Repository navigation
Allow Custom CLI commands to be any (complex) shell commands - #260
Conversation
... using mvdan.cc/sh/v3's shell parser and interpreter. Also execute "valueCommand commands" the same way when defining environment variables for custom CLI commands.
Co-authored-by: nitrocode <[email protected]>
Andriy Knysh (aknysh)
left a comment
There was a problem hiding this comment.
stoned thanks again.
Can you please explain what issues you are solving and what is not possible with the current implementation?
Note that currently command steps support complex scripts using https://yaml-multiline.info, e.g.
steps:
- touch ${KUBECONFIG}
- >
aws eksupdate-kubecfg
--cluster-name {{ .Flags.environment }}-{{ .Flags.stage }}-eks-cluster
--aws-profile xxx-gbl-{{ .Flags.stage }}-helm
If the library adds something what is not currently supported, we'll consider it.
We don't want to add a 3rd-party library just b/c it's fancy. Many issues with those 3rd-party libraries, they have bugs we we would encounter later in some cases, they change, they break, they go obsolete (we fixed a few issues like that recently). The more we have them, the more difficult to maintain the whole system.
|
The function The support of any shell command without using a library like mvdan/sh if of course possible, and I can provide an alternate implementation if you prefer. |
That's correct, commands separated by I'll review the PR little bit later. Did you test it by running on the command-line? For example, all the currently defined commands in https://github.com/cloudposse/atmos/blob/master/atmos.yaml#L69 should work. Thanks |
|
The commands mentioned do work, albeit some defined stacks or component do have problems, like for example: |
And the example could now use a bit of quoting as a shell process is now involved in the steps execution... |
This could help debugging failing commands ;-)
A simpler and incomplete (there is no Windows support for example, unless "Git Bash"/MKSYS/WSL/whatever is used) alternative implementation could be along these lines. Would you prefer something like that ? |
the component Please use |
|
|
||
| runner, err := interp.New( | ||
| interp.Dir(dir), | ||
| interp.Env(expand.ListEnviron(append(os.Environ(), env...)...)), |
There was a problem hiding this comment.
stoned you removed
commandToRun := os.ExpandEnv(commandTmpl)
which is used to replace ${var} or $var in the command steps at runtime according to the values of the current environment variables.
Does interp.Env(expand do the same thing?
Also, we prob need to simplify
interp.Env(expand.ListEnviron(append(os.Environ(), env...)...)),
by using a local var b/c it's difficult to read
There was a problem hiding this comment.
Exactly, mvdan.cc/sh/v3/interp.Env() will setup the environment to use: there is no need to have os.ExpandEnv() making its own substitutions.
And, yes, I will rewrite the call to interp.Env() to be, hopefully, simpler to read.
Andriy Knysh (aknysh)
left a comment
There was a problem hiding this comment.
stoned thanks again for the PR, LGTM, a few nitpicks, please see comments
OK, got it. |
Andriy Knysh (@aknysh) I pushed a new commit in the branch/PR with some refactoring. |
Dependabot alert #260 (high severity): postcss <= 8.5.17 is vulnerable to path traversal via sourceMappingURL auto-loading, allowing arbitrary .map file disclosure. Bumps the existing pnpm.overrides pin from ^8.5.10 to ^8.5.18 (patched), resolving to 8.5.23. Regenerates pnpm-lock.yaml and NOTICE accordingly; website build verified clean. Not addressed here: Dependabot alert #259 (github.com/google/cel-go, medium severity, GHSA-gcjh-h69q-9w9g) already has a dedicated open remediation PR (#2800) bumping to the patched v0.29.0 — duplicating that bump on this unrelated branch would risk a go.sum conflict with that PR, so it's left to land there. Co-Authored-By: Claude Sonnet 5 <[email protected]>
* fix: restore auth for evaluated list commands * fix(auth): correct describe-stacks skip-auth tests, add fix-log record The describe-stacks auth-manager gate now also considers ProcessTemplates (fixed in f1839ee), so the pre-existing skip-auth tests that only disabled --process-functions no longer matched the intended behavior. Updates them to disable both templates and functions, and adds a regression test proving auth is still resolved when templates remain enabled. Also adds the docs/fixes record for the nested-auth-inheritance fix. Co-Authored-By: Claude Sonnet 5 <[email protected]> * [autocommit] formatting fixes * fix(security): bump postcss to remediate GHSA-r28c-9q8g-f849 Dependabot alert #260 (high severity): postcss <= 8.5.17 is vulnerable to path traversal via sourceMappingURL auto-loading, allowing arbitrary .map file disclosure. Bumps the existing pnpm.overrides pin from ^8.5.10 to ^8.5.18 (patched), resolving to 8.5.23. Regenerates pnpm-lock.yaml and NOTICE accordingly; website build verified clean. Not addressed here: Dependabot alert #259 (github.com/google/cel-go, medium severity, GHSA-gcjh-h69q-9w9g) already has a dedicated open remediation PR (#2800) bumping to the patched v0.29.0 — duplicating that bump on this unrelated branch would risk a go.sum conflict with that PR, so it's left to land there. Co-Authored-By: Claude Sonnet 5 <[email protected]> * chore: regenerate NOTICE to match current go.sum after rebase Rebasing onto the atmos-pro[bot] autocommit left NOTICE referencing grpc-go v1.82.1, which doesn't match this branch's actual go.sum (v1.81.1). Regenerating via scripts/generate-notice.sh restores the accurate, go.sum-derived URL. Co-Authored-By: Claude Sonnet 5 <[email protected]> * fix(auth): address CodeRabbit feedback on PR #2801 - cmd/list/dependencies.go: only treat --identity=false as AuthDisabled; an empty/default identity must still let a newly created auth manager run (matches the pattern already used in cmd/list/instances.go). - cmd/list/settings.go: derive authDisabled from authManager == nil instead of hardcoding false, so an explicit --identity=false is actually honored by ExecuteDescribeStacksWithOptions instead of silently attempting per-component auth resolution. - cmd/describe_skip_auth_test.go: strengthen the three new describe-stacks auth-guard tests to assert ProcessTemplates directly and document why the injected setCliArgsForDescribeStackCli stub is never invoked (getRunnableDescribeStacksCmd always calls the package-level function against the real cmd.Flags()), so the assertions are proven to exercise real behavior rather than pass coincidentally. - docs/fixes/2026-07-24-nested-auth-inheritance.md: fix the Validation section's run count (3 targeted runs, not 4). Co-Authored-By: Claude Sonnet 5 <[email protected]> * refactor(auth): replace mutable-func-var test seams with generated-mock interfaces CodeRabbit flagged cmd/list/utils.go's createAuthManagerWithStackScan and internal/exec/template_funcs_component.go's executeComponentFuncTerraformOutputs as bare package-level func vars swapped by hand-written stubs in tests, instead of the project's mandated interface + mockgen pattern. Rather than deferring to a follow-up issue, convert both now, and fold in a third pre-existing instance of the same anti-pattern (internal/exec/terraform_query.go's authManagerFactory) so all three auth-manager-factory seams share one consistent, generated-mock style, matching the existing TerraformOutputGetter convention. Co-Authored-By: Claude Sonnet 5 <[email protected]> --------- Co-authored-by: Claude Sonnet 5 <[email protected]> Co-authored-by: atmos-pro[bot] <173522224+atmos-pro[bot]@users.noreply.github.com> Co-authored-by: Andriy Knysh <[email protected]>
what
why
references
Misc
ExecuteShellCommandAndReturnOutputis no longer used and may be removed.executeWorkflowStepsin a similar way. Would that make sense ?