Repository navigation
refactor: Migrate atmos auth to Command Registry with StandardParser - #1919
Merged
Merged
Conversation
Erik Osterman (Cloud Posse) (osterman)
requested a review
from a team
as a code owner
December 28, 2025 21:37
Contributor
|
Warning This PR exceeds the recommended limit of 1,000 lines.Large PRs are difficult to review and may be rejected due to their size. Please verify that this PR does not address multiple issues. |
Dependency ReviewThe following issues were found:
License Issuesgo.mod
Scanned Files
|
What
Refactors the
atmos authcommand family from the legacy flat-file structure to the Command Registry pattern with unified flag handling viapkg/flags/StandardParser. As a side-effect of the refactor, this PR also resolves two long-standing flag-precedence bugs (#1973 and #2392) and adds regression tests so they cannot silently regress again.cmd/auth_*.goto an organisedcmd/auth/package with aCommandProviderinterface.viper.BindPFlag()/viper.BindEnv()calls withflags.NewStandardParser(...)+parser.BindToViper(...)(Forbidigo-compliant).DisableFlagParsingwith theSeparatedArgspattern for pass-through commands (auth shell,auth exec).auth userto a real subcommand package (cmd/auth/user/).Why
viper.BindPFlag()/viper.BindEnv()calls.BuildConfigAndStacksInfo(cmd, v)so global flags (--base-path,--config,--config-path,--profile) are honoured uniformly.CommandProvider.cmd/authrose from 33% → 47% in this PR.Closes
Closes #1973 —
--profilenot applied forauth execandauth shellRoot cause: the legacy
executeAuthExecCommandCore/executeAuthShellCommandCoreloaded the atmos config fromcfg.InitCliConfig(newAuthConfigAndStacksInfo(cmd), false)— a helper that only read--base-path/--config/--config-pathand dropped--profileon the floor.auth list/auth env/auth whoamihappened to call a different helper that did read profile, hence the asymmetric bug.Fix: both
cmd/auth/exec.goandcmd/auth/shell.gonow callBuildConfigAndStacksInfo(cmd, v)(a wrapper overflags.BuildConfigAndStacksInfo) which extracts all global flags including--profileintoConfigAndStacksInfo.ProfilesFromArgbeforecfg.InitCliConfig.Regression tests:
cmd/auth/exec_test.go::TestAuthExec_ProfileFlagAppliedToConfigcmd/auth/shell_test.go::TestAuthShell_ProfileFlagAppliedToConfigBoth cover single-profile, multi-profile, and no-profile cases.
Closes #2392 —
--identitysilently dropped onatmos terraform planRoot cause: the bug as reported at v1.216.0 stemmed from
--identitybeing parsed inconsistently between command families. Terraform commands relied solely on the legacy arg-walkerparseIdentityFlagwhile auth/describe used a Cobra-flag-based path.Fix: terraform commands now register
--identityvia the StandardParser (cmd/terraform/flags.go::registerIdentityFlags) and the legacy arg-walker still populatesinfo.Identityfor backwards compat — so both paths converge on the same value.setupTerraformAuth(ininternal/exec/terraform_execute_helpers.go) passesinfo.Identityverbatim to the auth manager creator;pkg/auth.resolveIdentityNamereturns it as-is when non-empty, so the explicit flag value can never be overridden by a profile-default identity.Regression tests:
internal/exec/cli_utils_test.go::TestProcessCommandLineArgs_TerraformIdentityFlag_Issue2392— replays the exact arg shape from the bug report (terraform plan account-map -s core-gbl-root --identity core-root/admin) and assertsinfo.Identity == "core-root/admin".internal/exec/terraform_execute_helpers_auth_test.go::TestSetupTerraformAuth_IdentityFlagPropagatesToAuthCreator— builds a merged auth config with both adefault: trueidentity and a non-default identity and assertssetupTerraformAuthpasses the explicit--identityvalue verbatim.internal/exec/terraform_execute_helpers_auth_test.go::TestSetupTerraformAuth_EmptyIdentity_AllowsAutoDetection— inverse guard: emptyinfo.Identitymust still allow auto-detect.Testing
go build ./...,go vet ./...,make lint— all clean.go test -short ./cmd/... ./internal/... ./pkg/...— all pass.cmd/auth33.0% → 47.6%,cmd/auth/user35.6% → 51.0%.--profileglobal flag not applied forauth execandauth shellcommands #1973 and--identityflag silently ignored byatmos terraform plan(works onatmos authandatmos describesubcommands) #2392.Summary by CodeRabbit
New Features
Improvements
Documentation