@@ -32,42 +32,7 @@ process_file() {
3232 env_value=" ${! var_name} "
3333
3434 if [[ -n " $env_value " ]]; then
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- # Compact JSON and properly escape for YAML
44- clean_value=$( echo " $env_value " | jq -c .)
45- # Escape quotes and backslashes for YAML
46- clean_value=" ${clean_value// \\ / \\\\ } "
47- clean_value=" ${clean_value// \" / \\\" } "
48-
49- # For multiline YAML strings, use the literal scalar style
50- if [[ " $line " =~ ^[[:space:]]* [^:]+:[[:space:]]* INJECT_ENV\. ]]; then
51- # This is a YAML value, use proper quoting
52- line=" ${line// INJECT_ENV.${var_name} / \" ${clean_value} \" } "
53- else
54- line=" ${line// INJECT_ENV.${var_name} / ${clean_value} } "
55- fi
56- elif [[ " $env_value " =~ ^\s * [\{\[ ] ]] || [[ " $env_value " =~ [\}\] ]\s * $ ]]; then
57- # This looks like JSON, validate and compact it
58- if echo " $env_value " | jq empty 2> /dev/null; then
59- clean_value=$( echo " $env_value " | tr -d ' \000-\037' | jq -c .)
60- line=" ${line// INJECT_ENV.${var_name} / \" ${clean_value} \" } "
61- else
62- echo " Warning: $var_name appears to be JSON but is invalid. Using as-is."
63- clean_value=" ${env_value// \" / \\\" } "
64- line=" ${line// INJECT_ENV.${var_name} / \" ${clean_value} \" } "
65- fi
66- else
67- # For non-JSON content, escape quotes and use as-is
68- clean_value=" ${env_value// \" / \\\" } "
69- line=" ${line// INJECT_ENV.${var_name} / \" ${clean_value} \" } "
70- fi
35+ line=" ${line// INJECT_ENV.${var_name} / ${env_value} } "
7136 else
7237 echo " Warning: Environment variable $var_name is not set or empty. Leaving placeholder unchanged."
7338 fi
0 commit comments