Skip to content

Commit

Permalink
Merge pull request #192 from deviceinsight/feature/placeholder_escape
Browse files Browse the repository at this point in the history
add support escaping placeholders with backslash
  • Loading branch information
pvorb authored Apr 20, 2023
2 parents 75ac03f + 544b838 commit fe66816
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

* Support escaping placeholders with backslash e.g. `\${MY_ENV_VAR}` will no longer be expanded

## Version 2.12.0

* Converted README and CHANGELOG to Markdown
Expand Down
16 changes: 11 additions & 5 deletions src/main/kotlin/com/deviceinsight/helm/PackageMojo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import java.io.IOException
class PackageMojo : ResolveHelmMojo(), ServerAuthentication {

companion object {
private val PLACEHOLDER_REGEX = Regex("""\$\{(.*?)}""")
private val PLACEHOLDER_REGEX = Regex("""(\\?)\$\{(.*?)}""")
private val SUBSTITUTED_EXTENSIONS = setOf("json", "tpl", "yml", "yaml")
}

Expand Down Expand Up @@ -173,11 +173,17 @@ class PackageMojo : ResolveHelmMojo(), ServerAuthentication {
file.useLines { lines ->
lines.map { line ->
PLACEHOLDER_REGEX.replace(line) { matchResult ->
val property = matchResult.groupValues[1]

when (val propertyValue = findPropertyValue(property, targetFile.absolutePath)) {
null -> matchResult.groupValues[0]
else -> propertyValue
val isEscaped = matchResult.groupValues[1] == "\\"
val property = matchResult.groupValues[2]

if (isEscaped) {
matchResult.groupValues[0].substring(1)
} else {
when (val propertyValue = findPropertyValue(property, targetFile.absolutePath)) {
null -> matchResult.groupValues[0]
else -> propertyValue
}
}
}
}.forEach {
Expand Down

0 comments on commit fe66816

Please sign in to comment.