Skip to content

Commit be85730

Browse files
committed
fix: sed double escape in certificate
1 parent 26c2e7a commit be85730

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

generate-yaml-rp-env.sh

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,22 @@ process_file() {
3232
env_value="${!var_name}"
3333

3434
if [[ -n "$env_value" ]]; then
35-
line="${line//INJECT_ENV.${var_name}/${env_value}}"
35+
# Special handling for CIS_CREDENTIAL or similar JSON structures
36+
if [[ "$var_name" == "CIS_CREDENTIAL" ]] || [[ "$var_name" == "CIS_CENTRAL_BINDING" ]]; then
37+
# Validate and format CIS credential JSON
38+
if ! echo "$env_value" | jq empty 2>/dev/null; then
39+
echo "Error: $var_name contains invalid JSON"
40+
exit 1
41+
fi
42+
43+
# Clean JSON and properly escape for parsing
44+
# NOTE: Because the certificate contains \n characters, which are escaped by jq, we need to remove \\n manually from the string
45+
clean_value=$(echo "$env_value" | jq . | sed 's/\\\\n//g')
46+
line="${line//INJECT_ENV.${var_name}/${clean_value}}"
47+
else
48+
# For non-JSON variables, use direct substitution
49+
line="${line//INJECT_ENV.${var_name}/${env_value}}"
50+
fi
3651
else
3752
echo "Warning: Environment variable $var_name is not set or empty. Leaving placeholder unchanged."
3853
fi

0 commit comments

Comments
 (0)