Skip to content

Commit 2469c48

Browse files
committed
fix: secret parsing
1 parent be85730 commit 2469c48

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

generate-yaml-rp-env.sh

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,17 @@ process_file() {
3434
if [[ -n "$env_value" ]]; then
3535
# Special handling for CIS_CREDENTIAL or similar JSON structures
3636
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
37+
# First escape any literal newlines and other control characters for proper JSON parsing
38+
escaped_json=$(printf '%s' "$env_value" | sed ':a;N;$!ba;s/\n/\\n/g' | sed 's/\r/\\r/g' | sed 's/\t/\\t/g')
39+
40+
# Validate the escaped JSON
41+
if ! echo "$escaped_json" | jq empty 2>/dev/null; then
3942
echo "Error: $var_name contains invalid JSON"
40-
exit 1
43+
exit 1
4144
fi
4245

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+
# Process with jq and then clean up the escaped newlines
47+
clean_value=$(echo "$escaped_json" | jq -c . | sed 's/\\n//g')
4648
line="${line//INJECT_ENV.${var_name}/${clean_value}}"
4749
else
4850
# For non-JSON variables, use direct substitution

providers/provider-btp/v1.0.3/setup/config.yaml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,6 @@ stringData:
1212
"password": "INJECT_ENV.TECHNICAL_USER_PASSWORD"
1313
}
1414
---
15-
apiVersion: v1
16-
kind: Secret
17-
metadata:
18-
namespace: default
19-
name: cis-provider-secret
20-
type: Opaque
21-
stringData:
22-
data: |
23-
INJECT_ENV.CIS_CENTRAL_BINDING
24-
---
2515
apiVersion: btp.sap.crossplane.io/v1alpha1
2616
kind: ProviderConfig
2717
metadata:
@@ -41,3 +31,13 @@ spec:
4131
name: sa-provider-secret
4232
namespace: default
4333
source: Secret
34+
---
35+
apiVersion: v1
36+
kind: Secret
37+
metadata:
38+
namespace: default
39+
name: cis-provider-secret
40+
type: Opaque
41+
stringData:
42+
data: |
43+
INJECT_ENV.CIS_CENTRAL_BINDING

0 commit comments

Comments
 (0)