Skip to content

Fix shell escape errors when querying for Rancher API#37

Merged
ikogan merged 1 commit into
mainfrom
cs/adp-connect-exec-support
Jun 23, 2026
Merged

Fix shell escape errors when querying for Rancher API#37
ikogan merged 1 commit into
mainfrom
cs/adp-connect-exec-support

Conversation

@ikogan

@ikogan ikogan commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

After using kopf, annotations containing significant escape characters (\) became present in Rancher Project API responses. Using echo caused them to be parsed by the shell and slightly unescaped, making them unparseable JSON.

This moves to using printf for all API calls instead of echo.

Copilot AI review requested due to automatic review settings June 23, 2026 19:26
@ikogan
ikogan merged commit 19f43f7 into main Jun 23, 2026
4 of 5 checks passed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates adp-connect.sh to avoid shell escape/unescape issues (notably backslashes in JSON) by replacing echo pipelines with printf when passing API responses and other strings through parsing tools.

Changes:

  • Replaced multiple echo "$var" pipelines with printf '%s' "$var" to avoid escape interpretation and preserve JSON fidelity.
  • Adjusted rancher_login to return failure codes in more cases (and updated several call sites to handle failures).
  • Added additional diagnostic output when Rancher projects cannot be discovered.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread adp-connect.sh
Comment on lines 864 to +866
if ! gum spin --show-error --title="Checking ${SERVER}..." rancher project list; then
yq -i '.Servers["'"${SERVER}"'"].project = ""' "$HOME/.rancher/cli2.json"
rancher_login "${SERVER}"
rancher_login "${SERVER}" || warn "Unable to login to ${SERVER}. Skipping."
Comment thread adp-connect.sh
fi

echo "$RESPONSE"
printf '%s' "$RESPONSE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants