Skip to content

feat(cli): summary improvements over sensitive data#203

Open
pipeline1987 wants to merge 1 commit intomainfrom
feat/summary-improvements-over-sensitive-data
Open

feat(cli): summary improvements over sensitive data#203
pipeline1987 wants to merge 1 commit intomainfrom
feat/summary-improvements-over-sensitive-data

Conversation

@pipeline1987
Copy link
Contributor

@pipeline1987 pipeline1987 commented Mar 18, 2026

Summary

When DEBUG is set (any non-empty value), emit one JSON line to stderr at the end of each run (event, invocation_id, command, status, duration_ms, optional error). Reuses existing DEBUG instead of new env vars. Sanitizes command and error: API keys, app IDs, and profile values are masked (last 4 chars only, e.g. --api-key=***c123) so logs stay safe.

Changes

  • Logic: pkg/cmd/root/run_summary.go + tests in run_summary_test.go; root.go only wires emitRunSummary after Execute.
  • Run summary: no longer uses ALGOLIA_CLI_OBSERVABILITY / ALGOLIA_CLI_NON_INTERACTIVE; use DEBUG=1 instead.

Testing

go test ./pkg/cmd/root/.... Manual: DEBUG=1 ./algolia indices list 2>/tmp/e.txt && tail -1 /tmp/e.txt → one JSON line, no full secrets.

Comment on lines +30 to +32
// sensitiveFlagPattern matches flags that take a secret value; submatch 1 = flag name (e.g. --api-key= or -p ), submatch 2 = value.
var sensitiveFlagPattern = regexp.MustCompile(
`(--(?:api-key|application-id|admin-api-key)=)(\S+)|(--(?:api-key|application-id|admin-api-key)\s+)(\S+)|(-p\s+)(\S+)`)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to hide -p ? It's profile for most/all commands, might be useful to keep visible

Copy link
Contributor

Choose a reason for hiding this comment

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

Although I couldn't find a command to see this specific behavior

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