diff --git a/bundlebee-core/src/main/java/io/yupiik/bundlebee/core/lang/SubstitutorProducer.java b/bundlebee-core/src/main/java/io/yupiik/bundlebee/core/lang/SubstitutorProducer.java index c19ef6da..fa5c4bdd 100644 --- a/bundlebee-core/src/main/java/io/yupiik/bundlebee/core/lang/SubstitutorProducer.java +++ b/bundlebee-core/src/main/java/io/yupiik/bundlebee/core/lang/SubstitutorProducer.java @@ -249,9 +249,16 @@ protected String doSubstitute(final AtomicReference self, final Con final var src = readResource(placeholder, "bundlebee-base64-file:"); return src == null ? null : Base64.getEncoder().encodeToString(src); } + if (placeholder.startsWith("bundlebee-base64-decode-file:")) { + final var src = readResource(placeholder, "bundlebee-base64-decode-file:"); + return src == null ? null : new String(Base64.getDecoder().decode(src), StandardCharsets.UTF_8); + } if (placeholder.startsWith("bundlebee-base64:")) { return Base64.getEncoder().encodeToString(placeholder.substring("bundlebee-base64:".length()).getBytes(StandardCharsets.UTF_8)); } + if (placeholder.startsWith("bundlebee-base64-decode:")) { + return new String(Base64.getDecoder().decode(placeholder.substring("bundlebee-base64-decode:".length()).getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8); + } if (placeholder.startsWith("bundlebee-quote-escaped-inline-file:")) { final var resource = readResource(placeholder, "bundlebee-quote-escaped-inline-file:"); return resource == null ? null : new String(resource, StandardCharsets.UTF_8) diff --git a/bundlebee-core/src/test/java/io/yupiik/bundlebee/core/lang/SubstitutorProducerTest.java b/bundlebee-core/src/test/java/io/yupiik/bundlebee/core/lang/SubstitutorProducerTest.java index 03e81333..e6dc599a 100644 --- a/bundlebee-core/src/test/java/io/yupiik/bundlebee/core/lang/SubstitutorProducerTest.java +++ b/bundlebee-core/src/test/java/io/yupiik/bundlebee/core/lang/SubstitutorProducerTest.java @@ -219,6 +219,13 @@ void base64() { substitutor.getOrDefault("bundlebee-base64:content", "failed")); } + @Test + void debase64() { + assertEquals( + "content", + substitutor.getOrDefault("bundlebee-base64-decode:" + Base64.getEncoder().encodeToString("content".getBytes(StandardCharsets.UTF_8)), "failed")); + } + @Test void base64File(@TempDir final Path root) throws IOException { final var file = root.resolve("test.txt"); diff --git a/bundlebee-documentation/src/main/minisite/content/how-it-works.adoc b/bundlebee-documentation/src/main/minisite/content/how-it-works.adoc index b2d4d43b..7f8baab7 100644 --- a/bundlebee-documentation/src/main/minisite/content/how-it-works.adoc +++ b/bundlebee-documentation/src/main/minisite/content/how-it-works.adoc @@ -194,7 +194,9 @@ Placeholders can use some keywords to get some particular values: - `bundlebee-indent::`: indents a value with the provided space size, it is generally combined with another interpolation (file ones in particular) as value, ex `{{bundlebee-indent:8:{{bundlebee-inline-file:myfile.txt}}}}`, - `bundlebee-inline-file:`: load the file content as value, - `bundlebee-base64-file:`: converts the file in base64 (useful to write `data:xxxx,` values for ex keeping the raw file in the filesystem, very helpful for images), +- `bundlebee-base64-decode-file:`: decode the file from a base64 content, - `bundlebee-base64:`: encodes in base64 the text, +- `bundlebee-base64-decode:`: decode from base64 to text the value `text`, - `bundlebee-digest:BASE64|HEX,,`: computes the digest of the text encoded in base64 or hexa format (useful to read files like `ConfigMap` or `Secret` and inject their digest value in a `Deployment` annotations to force its reload for example), - `bundlebee-quote-escaped-inline-file:`: load the file content as a quoted value, - `bundlebee-json-inline-file:`: load the file content as a JSON string value - without quotes,