Skip to content

Commit 20f428f

Browse files
aknyshautofix-ci[bot]claudeosterman
authored
fix: Profile and identity flags loading and propagation (#1805)
* fix profiles * fix profiles * fix profiles * [autofix.ci] apply automated fixes * test: Add tests for profile and identity flag handling Added comprehensive unit tests to increase code coverage for the profile and identity flag fixes: - pkg/config/load_flags_test.go: Tests getProfilesFromFlagsOrEnv() function covering environment variables, CLI flags (both syntaxes), and edge cases - internal/exec/terraform_nested_auth_helper_test.go: Added TestIdentityInheritanceLogic to verify identity extraction from AuthManager chain for nested component operations These tests cover the new code paths added for fixing: 1. Profile loading from --profile CLI flag 2. Identity propagation to nested components via parent AuthManager chain 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * test: Add comprehensive tests for auth helper edge cases Added tests to increase coverage for profile and identity flag handling: - TestGetProfilesFromFlagsOrEnv: Added test for environment variable precedence - TestResolveAuthManagerForNestedComponent_WithoutAuthSection: Tests early return paths - TestHasDefaultIdentity_EdgeCases: Tests additional edge cases including: - Multiple defaults - Missing default field - Mixed valid/invalid configs These tests target the uncovered code paths in: - pkg/config/load.go: getProfilesFromFlagsOrEnv() and edge cases - internal/exec/terraform_nested_auth_helper.go: hasDefaultIdentity() and early returns 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * fix: Correct precedence - CLI flags override environment variables Fixed the precedence order in getProfilesFromFlagsOrEnv() to ensure CLI flags take precedence over environment variables, which is the expected behavior for CLI applications. Before: Environment variables took precedence over CLI flags After: CLI flags override environment variables (correct behavior) Precedence order (highest to lowest): 1. CLI flags (--profile) 2. Environment variables (ATMOS_PROFILE) 3. Config file 4. Defaults Updated test case to verify correct precedence behavior. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * docs: Update documentation to reflect correct CLI flag precedence Updated documentation to clarify that CLI flags take precedence over environment variables (standard CLI behavior): - Fixed "Fix Overview" section to show CLI flags checked first - Updated code example to show correct precedence order - Added explicit precedence order list - Clarified logic flow and why this works Precedence (highest to lowest): 1. CLI flags (--profile) 2. Environment variables (ATMOS_PROFILE) 3. Config file 4. Defaults 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * fix: Use os.Getenv for ATMOS_PROFILE to avoid Viper caching in tests Fixed CI test failures by reading ATMOS_PROFILE directly from environment instead of using Viper, which caches environment variables and causes test isolation issues. Root cause: - Viper caches environment variable values on first read - In CI, if ATMOS_PROFILE was set by environment or previous tests, Viper retained the cached value even after tests cleaned up - This caused "profile not found" errors when trying to load non-existent cached profile names Solution: - Read ATMOS_PROFILE using os.Getenv() for fresh reads on every call - Added nolint:forbidigo with explanation for linter exception - Updated test to use switch statement (staticcheck QF1003) - Tests use t.Setenv() instead of viper.Set() to match implementation Benefits: - Proper test isolation (t.Setenv cleanup works correctly) - No cached stale values - CLI flags still take precedence (checked first) - Comma-separated values handled consistently 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * fix: Handle comma-separated profiles in --profile value syntax Fixed regression where --profile dev,staging (space syntax with commas) was treated as a single profile instead of being split into multiple profiles. Both syntaxes now handle comma-separated values consistently: - --profile dev,staging → ["dev", "staging"] - --profile=dev,staging → ["dev", "staging"] Added test case to verify comma-separated values work with space syntax. Fixes CodeRabbit feedback about comma-separated spaced syntax regression. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * test: Reset Viper state per subtest to prevent pollution Added viper.Reset() before and after each subtest to ensure test isolation. Viper is a global singleton, so mutations in one test could affect subsequent tests without proper cleanup. Changes: - Call viper.Reset() at start of each subtest - Use t.Cleanup(viper.Reset) to ensure cleanup after test - Prevents test pollution where one test's Viper state affects another Fixes CodeRabbit feedback about Viper state isolation. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * refactor: Use AuthProfileFlag constant instead of hardcoded strings Replace hardcoded "--profile" strings with AuthProfileFlag constant from pkg/config/const.go for consistency and maintainability. Changes: - pkg/config/load.go: Use AuthProfileFlag in parseProfilesFromArgs() - pkg/config/load_flags_test.go: Use AuthProfileFlag in test cases - pkg/config/load_profile_test.go: Use AuthProfileFlag in test cases 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * refactor: Rename AuthProfileFlag to AtmosProfileFlag Rename the constant from AuthProfileFlag to AtmosProfileFlag because profiles are not only for authentication. They configure multiple aspects of Atmos behavior including base paths, component locations, and various settings. Changes: - pkg/config/const.go: Rename constant and update comment - pkg/config/load.go: Update all references - pkg/config/load_flags_test.go: Update all references - pkg/config/load_profile_test.go: Update all references - internal/exec/cli_utils.go: Update global flags list 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * refactor: Rename AuthProfileFlag to AtmosProfileFlag Rename the constant from AuthProfileFlag to AtmosProfileFlag because profiles are not only for authentication. They configure multiple aspects of Atmos behavior including base paths, component locations, and various settings. Changes: - pkg/config/const.go: Rename constant and update comment - pkg/config/load.go: Update all references - pkg/config/load_flags_test.go: Update all references - pkg/config/load_profile_test.go: Update all references - internal/exec/cli_utils.go: Update global flags list 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * test: Add comprehensive edge case tests for profile parsing Add extensive test coverage for profile parsing edge cases including: - Empty entries in comma-separated lists - Whitespace handling (leading, trailing, and standalone) - Leading and trailing commas - Multiple consecutive commas - Mixed whitespace and empty values - Empty profile values Test improvements: - pkg/config/load_flags_test.go: Added 4 new test cases for env var edge cases - pkg/config/load_profile_test.go: Added 7 new test cases for flag parsing edge cases - internal/exec/cli_utils_test.go: Added 2 new test functions with 8 test cases for ProcessCommandLineArgs Coverage improvements: - parseProfilesFromArgs: 100.0% (maintained) - getProfilesFromFlagsOrEnv: 100.0% (maintained) - ProcessCommandLineArgs: 86.1% → 91.1% (+5.0%) - internal/exec overall: 65.7% → 65.8% All tests verify the robustness improvements from filtering empty entries when parsing comma-separated profile values. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * fix: Profile and identity flag handling (sync flags to Viper) (#1806) * refactor: Sync global flags to Viper in root.go instead of passing cmd parameter Remove the cmd parameter from InitCliConfig and LoadConfig signatures by syncing global flags (profile, identity) from Cobra's FlagSet to Viper in root.go PersistentPreRun before config loading. This is cleaner than passing cmd through 100+ function calls where 99% were nil. Also simplify getProfilesFromFlagsOrEnv() to just read from Viper, which now has synced flag values. Keep parseProfilesFromOsArgs() as fallback for DisableFlagParsing commands (terraform/helmfile/packer) that bypass Cobra's flag parsing. Update docs/fixes/profile-and-identity-flags-loading.md to document Phase 3 (root cause fix) completion and future migration path. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * docs: Update implementation section to reflect Phase 3 solution Update the 'Solution Implemented' section to accurately describe the Phase 3 implementation (syncing Viper in root.go) instead of the outdated Phase 2 approach (passing cmd parameter). Clarify the two-part solution: syncing in root.go for normal commands and pflag fallback for DisableFlagParsing commands. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * docs: Rewrite fix documentation to focus on the solution - Remove commit-by-commit evolutionary phases - Focus on the final implementation and how it works - Clearer explanation of root cause (Viper timing issue) - Simplified structure: Problem → Root Cause → Solution → Verification - Removed confusing 'rejected' alternative that we actually implemented * test: Fix TestResolveIdentityName by clearing Viper state The test was failing because resolveIdentityName() now reads from Viper when the flag is not changed (due to syncGlobalFlagsToViper changes). Tests need to ensure Viper has clean state for the identity flag. * docs: Document source detection limitation in profile loading tests Source detection (env vs flag) is best-effort for logging purposes only. When both ATMOS_PROFILE env var and --profile flag are set, source may be incorrectly reported as 'env' even though flag value was actually used. This doesn't affect functionality - Viper and syncGlobalFlagsToViper() ensure flag precedence is correct. The source string is only used for debug logging. * fix: Handle Viper's quirky comma-separated env var parsing for profiles Viper does NOT automatically parse comma-separated environment variables for StringSlice types. This commit adds proper handling for all Viper quirks: - "dev,staging,prod" → []string{"dev,staging,prod"} (single element) - "dev staging prod" → []string{"dev", "staging", "prod"} (splits on whitespace) - " dev , staging " → []string{"dev", ",", "staging"} (splits on whitespace, keeps commas!) Changes: - pkg/config/load.go: Add parseViperProfilesFromEnv() helper to handle Viper environment variable quirks. Refactor getProfilesFromFlagsOrEnv() to reduce complexity (passes gocognit and nestif linters). - pkg/config/load_flags_test.go: Add TestGetProfilesFromFlagsOrEnvWithRealViper() that uses actual Viper BindEnv() to test real-world behavior - pkg/config/load_flags_test.go: Restore environment variable edge case tests (empty values, leading/trailing commas, whitespace, precedence) - cmd/*_test.go: Add Viper.Reset() and clear identity env vars to prevent test pollution This fixes the critical bug where comma-separated profiles in ATMOS_PROFILE environment variable were not parsed correctly. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]> * docs: Replace hard tabs with spaces in code blocks Fix markdown formatting by replacing all hard tabs with 4 spaces in code blocks throughout the documentation file. This ensures consistent rendering across different markdown parsers and editors. Changes: - Replaced 50+ instances of hard tabs with 4 spaces - Maintains proper code block indentation - Improves markdown consistency 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * fix profiles * [autofix.ci] apply automated fixes * fix: Add fallback to parseProfilesFromOsArgs for DisableFlagParsing commands PR #1806 broke profile loading for terraform/helmfile/packer commands because these commands have DisableFlagParsing=true, which means Cobra never parses flags, so syncGlobalFlagsToViper() never syncs profile values to Viper. This commit restores profile loading by: 1. Adding fallback to parseProfilesFromOsArgs(os.Args) when Viper doesn't have profiles 2. Adding fallback to os.Getenv("ATMOS_PROFILE") as final resort 3. Extracting helper functions to reduce cyclomatic complexity: - parseProfilesFromEnvString() for comma-separated parsing - getProfilesFromFallbacks() for fallback logic 4. Using profileDelimiter constant for "," literal This ensures --profile flag works for all commands (normal and DisableFlagParsing). Fixes: #1806 merge regression Complexity: Reduced from 11 to 5 (nestif from 6 to 2) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * fix: Merge global auth config from profiles into component sections PR #1806 regression: Profile auth config was loaded into atmosConfig.Auth but not propagated to ComponentAuthSection, causing terraform pre-hook to skip authentication with "No auth configuration found". Root cause: postProcessTemplatesAndYamlFunctions() overwrote ComponentAuthSection with component-level auth from ComponentSection["auth"], which didn't include the global auth config from profiles. Solution: 1. Pass atmosConfig to ProcessComponentConfig() 2. When component has no auth section, call mergeGlobalAuthConfig() 3. Helper function merges atmosConfig.Auth into both componentAuthSection AND componentSection["auth"] (prevents overwrite by postProcess) 4. Extracted to helper function to reduce cyclomatic complexity Flow: - ProcessComponentConfig calls mergeGlobalAuthConfig - Writes merged config to ComponentSection["auth"] AND ComponentAuthSection - postProcessTemplatesAndYamlFunctions copies ComponentSection["auth"] → ComponentAuthSection - TerraformPreHook receives merged auth config ✅ Impact: - Profiles with auth config work without explicit auth.yaml import - --profile flag properly propagates auth config to terraform commands - Backward compatible: explicit auth.yaml imports still work Fixes: terraform commands failing with --profile when auth.yaml not imported 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * add tests * add tests * [autofix.ci] apply automated fixes * [autofix.ci] apply automated fixes (attempt 2/3) * [autofix.ci] apply automated fixes (attempt 3/3) * add tests * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Claude <[email protected]> Co-authored-by: Erik Osterman (CEO @ Cloud Posse) <[email protected]>
1 parent 10886fe commit 20f428f

22 files changed

+1634
-126
lines changed

NOTICE

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ APACHE 2.0 LICENSED DEPENDENCIES
6767

6868
- github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp
6969
License: Apache-2.0
70-
URL: https://github.com/GoogleCloudPlatform/opentelemetry-operations-go/blob/detectors/gcp/v1.29.0/detectors/gcp/LICENSE
70+
URL: https://github.com/GoogleCloudPlatform/opentelemetry-operations-go/blob/detectors/gcp/v1.30.0/detectors/gcp/LICENSE
7171

7272
- github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric
7373
License: Apache-2.0
@@ -99,83 +99,87 @@ APACHE 2.0 LICENSED DEPENDENCIES
9999

100100
- github.com/aws/aws-sdk-go-v2
101101
License: Apache-2.0
102-
URL: https://github.com/aws/aws-sdk-go-v2/blob/v1.39.6/LICENSE.txt
102+
URL: https://github.com/aws/aws-sdk-go-v2/blob/v1.40.0/LICENSE.txt
103103

104104
- github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream
105105
License: Apache-2.0
106106
URL: https://github.com/aws/aws-sdk-go-v2/blob/aws/protocol/eventstream/v1.7.3/aws/protocol/eventstream/LICENSE.txt
107107

108108
- github.com/aws/aws-sdk-go-v2/config
109109
License: Apache-2.0
110-
URL: https://github.com/aws/aws-sdk-go-v2/blob/config/v1.31.20/config/LICENSE.txt
110+
URL: https://github.com/aws/aws-sdk-go-v2/blob/config/v1.32.0/config/LICENSE.txt
111111

112112
- github.com/aws/aws-sdk-go-v2/credentials
113113
License: Apache-2.0
114-
URL: https://github.com/aws/aws-sdk-go-v2/blob/credentials/v1.18.24/credentials/LICENSE.txt
114+
URL: https://github.com/aws/aws-sdk-go-v2/blob/credentials/v1.19.0/credentials/LICENSE.txt
115115

116116
- github.com/aws/aws-sdk-go-v2/feature/ec2/imds
117117
License: Apache-2.0
118-
URL: https://github.com/aws/aws-sdk-go-v2/blob/feature/ec2/imds/v1.18.13/feature/ec2/imds/LICENSE.txt
118+
URL: https://github.com/aws/aws-sdk-go-v2/blob/feature/ec2/imds/v1.18.14/feature/ec2/imds/LICENSE.txt
119119

120120
- github.com/aws/aws-sdk-go-v2/feature/s3/manager
121121
License: Apache-2.0
122-
URL: https://github.com/aws/aws-sdk-go-v2/blob/feature/s3/manager/v1.20.7/feature/s3/manager/LICENSE.txt
122+
URL: https://github.com/aws/aws-sdk-go-v2/blob/feature/s3/manager/v1.20.9/feature/s3/manager/LICENSE.txt
123123

124124
- github.com/aws/aws-sdk-go-v2/internal/configsources
125125
License: Apache-2.0
126-
URL: https://github.com/aws/aws-sdk-go-v2/blob/internal/configsources/v1.4.13/internal/configsources/LICENSE.txt
126+
URL: https://github.com/aws/aws-sdk-go-v2/blob/internal/configsources/v1.4.14/internal/configsources/LICENSE.txt
127127

128128
- github.com/aws/aws-sdk-go-v2/internal/endpoints/v2
129129
License: Apache-2.0
130-
URL: https://github.com/aws/aws-sdk-go-v2/blob/internal/endpoints/v2.7.13/internal/endpoints/v2/LICENSE.txt
130+
URL: https://github.com/aws/aws-sdk-go-v2/blob/internal/endpoints/v2.7.14/internal/endpoints/v2/LICENSE.txt
131131

132132
- github.com/aws/aws-sdk-go-v2/internal/ini
133133
License: Apache-2.0
134134
URL: https://github.com/aws/aws-sdk-go-v2/blob/internal/ini/v1.8.4/internal/ini/LICENSE.txt
135135

136136
- github.com/aws/aws-sdk-go-v2/internal/v4a
137137
License: Apache-2.0
138-
URL: https://github.com/aws/aws-sdk-go-v2/blob/internal/v4a/v1.4.13/internal/v4a/LICENSE.txt
138+
URL: https://github.com/aws/aws-sdk-go-v2/blob/internal/v4a/v1.4.14/internal/v4a/LICENSE.txt
139139

140140
- github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding
141141
License: Apache-2.0
142142
URL: https://github.com/aws/aws-sdk-go-v2/blob/service/internal/accept-encoding/v1.13.3/service/internal/accept-encoding/LICENSE.txt
143143

144144
- github.com/aws/aws-sdk-go-v2/service/internal/checksum
145145
License: Apache-2.0
146-
URL: https://github.com/aws/aws-sdk-go-v2/blob/service/internal/checksum/v1.9.4/service/internal/checksum/LICENSE.txt
146+
URL: https://github.com/aws/aws-sdk-go-v2/blob/service/internal/checksum/v1.9.5/service/internal/checksum/LICENSE.txt
147147

148148
- github.com/aws/aws-sdk-go-v2/service/internal/presigned-url
149149
License: Apache-2.0
150-
URL: https://github.com/aws/aws-sdk-go-v2/blob/service/internal/presigned-url/v1.13.13/service/internal/presigned-url/LICENSE.txt
150+
URL: https://github.com/aws/aws-sdk-go-v2/blob/service/internal/presigned-url/v1.13.14/service/internal/presigned-url/LICENSE.txt
151151

152152
- github.com/aws/aws-sdk-go-v2/service/internal/s3shared
153153
License: Apache-2.0
154-
URL: https://github.com/aws/aws-sdk-go-v2/blob/service/internal/s3shared/v1.19.13/service/internal/s3shared/LICENSE.txt
154+
URL: https://github.com/aws/aws-sdk-go-v2/blob/service/internal/s3shared/v1.19.14/service/internal/s3shared/LICENSE.txt
155155

156156
- github.com/aws/aws-sdk-go-v2/service/s3
157157
License: Apache-2.0
158-
URL: https://github.com/aws/aws-sdk-go-v2/blob/service/s3/v1.90.2/service/s3/LICENSE.txt
158+
URL: https://github.com/aws/aws-sdk-go-v2/blob/service/s3/v1.91.1/service/s3/LICENSE.txt
159159

160160
- github.com/aws/aws-sdk-go-v2/service/secretsmanager
161161
License: Apache-2.0
162162
URL: https://github.com/aws/aws-sdk-go-v2/blob/service/secretsmanager/v1.35.4/service/secretsmanager/LICENSE.txt
163163

164+
- github.com/aws/aws-sdk-go-v2/service/signin
165+
License: Apache-2.0
166+
URL: https://github.com/aws/aws-sdk-go-v2/blob/service/signin/v1.0.1/service/signin/LICENSE.txt
167+
164168
- github.com/aws/aws-sdk-go-v2/service/ssm
165169
License: Apache-2.0
166-
URL: https://github.com/aws/aws-sdk-go-v2/blob/service/ssm/v1.67.2/service/ssm/LICENSE.txt
170+
URL: https://github.com/aws/aws-sdk-go-v2/blob/service/ssm/v1.67.3/service/ssm/LICENSE.txt
167171

168172
- github.com/aws/aws-sdk-go-v2/service/sso
169173
License: Apache-2.0
170-
URL: https://github.com/aws/aws-sdk-go-v2/blob/service/sso/v1.30.3/service/sso/LICENSE.txt
174+
URL: https://github.com/aws/aws-sdk-go-v2/blob/service/sso/v1.30.4/service/sso/LICENSE.txt
171175

172176
- github.com/aws/aws-sdk-go-v2/service/ssooidc
173177
License: Apache-2.0
174-
URL: https://github.com/aws/aws-sdk-go-v2/blob/service/ssooidc/v1.35.7/service/ssooidc/LICENSE.txt
178+
URL: https://github.com/aws/aws-sdk-go-v2/blob/service/ssooidc/v1.35.8/service/ssooidc/LICENSE.txt
175179

176180
- github.com/aws/aws-sdk-go-v2/service/sts
177181
License: Apache-2.0
178-
URL: https://github.com/aws/aws-sdk-go-v2/blob/service/sts/v1.40.2/service/sts/LICENSE.txt
182+
URL: https://github.com/aws/aws-sdk-go-v2/blob/service/sts/v1.41.1/service/sts/LICENSE.txt
179183

180184
- github.com/aws/smithy-go
181185
License: Apache-2.0
@@ -187,7 +191,7 @@ APACHE 2.0 LICENSED DEPENDENCIES
187191

188192
- github.com/cncf/xds/go
189193
License: Apache-2.0
190-
URL: https://github.com/cncf/xds/blob/2ac532fd4443/go/LICENSE
194+
URL: https://github.com/cncf/xds/blob/0feb69152e9f/go/LICENSE
191195

192196
- github.com/cockroachdb/apd/v3
193197
License: Apache-2.0
@@ -247,7 +251,7 @@ APACHE 2.0 LICENSED DEPENDENCIES
247251

248252
- github.com/envoyproxy/go-control-plane/envoy
249253
License: Apache-2.0
250-
URL: https://github.com/envoyproxy/go-control-plane/blob/envoy/v1.32.4/envoy/LICENSE
254+
URL: https://github.com/envoyproxy/go-control-plane/blob/envoy/v1.35.0/envoy/LICENSE
251255

252256
- github.com/envoyproxy/protoc-gen-validate/validate
253257
License: Apache-2.0
@@ -267,7 +271,7 @@ APACHE 2.0 LICENSED DEPENDENCIES
267271

268272
- github.com/go-jose/go-jose/v4
269273
License: Apache-2.0
270-
URL: https://github.com/go-jose/go-jose/blob/v4.1.2/LICENSE
274+
URL: https://github.com/go-jose/go-jose/blob/v4.1.3/LICENSE
271275

272276
- github.com/go-logr/logr
273277
License: Apache-2.0
@@ -411,7 +415,7 @@ APACHE 2.0 LICENSED DEPENDENCIES
411415

412416
- github.com/spiffe/go-spiffe/v2
413417
License: Apache-2.0
414-
URL: https://github.com/spiffe/go-spiffe/blob/v2.5.0/v2/LICENSE
418+
URL: https://github.com/spiffe/go-spiffe/blob/v2.6.0/LICENSE
415419

416420
- github.com/xanzy/ssh-agent
417421
License: Apache-2.0
@@ -439,11 +443,11 @@ APACHE 2.0 LICENSED DEPENDENCIES
439443

440444
- go.opentelemetry.io/auto/sdk
441445
License: Apache-2.0
442-
URL: https://github.com/open-telemetry/opentelemetry-go-instrumentation/blob/sdk/v1.1.0/sdk/LICENSE
446+
URL: https://github.com/open-telemetry/opentelemetry-go-instrumentation/blob/sdk/v1.2.1/sdk/LICENSE
443447

444448
- go.opentelemetry.io/contrib/detectors/gcp
445449
License: Apache-2.0
446-
URL: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/detectors/gcp/v1.36.0/detectors/gcp/LICENSE
450+
URL: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/detectors/gcp/v1.38.0/detectors/gcp/LICENSE
447451

448452
- go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc
449453
License: Apache-2.0
@@ -495,15 +499,15 @@ APACHE 2.0 LICENSED DEPENDENCIES
495499

496500
- google.golang.org/genproto/googleapis/api
497501
License: Apache-2.0
498-
URL: https://github.com/googleapis/go-genproto/blob/c5933d9347a5/googleapis/api/LICENSE
502+
URL: https://github.com/googleapis/go-genproto/blob/3a174f9686a8/googleapis/api/LICENSE
499503

500504
- google.golang.org/genproto/googleapis/rpc
501505
License: Apache-2.0
502506
URL: https://github.com/googleapis/go-genproto/blob/f26f9409b101/googleapis/rpc/LICENSE
503507

504508
- google.golang.org/grpc
505509
License: Apache-2.0
506-
URL: https://github.com/grpc/grpc-go/blob/v1.76.0/LICENSE
510+
URL: https://github.com/grpc/grpc-go/blob/v1.77.0/LICENSE
507511

508512
- gopkg.in/ini.v1
509513
License: Apache-2.0
@@ -556,7 +560,7 @@ BSD LICENSED DEPENDENCIES
556560

557561
- github.com/aws/aws-sdk-go-v2/internal/sync/singleflight
558562
License: BSD-3-Clause
559-
URL: https://github.com/aws/aws-sdk-go-v2/blob/v1.39.6/internal/sync/singleflight/LICENSE
563+
URL: https://github.com/aws/aws-sdk-go-v2/blob/v1.40.0/internal/sync/singleflight/LICENSE
560564

561565
- github.com/aws/aws-sdk-go/internal/sync/singleflight
562566
License: BSD-3-Clause
@@ -608,7 +612,7 @@ BSD LICENSED DEPENDENCIES
608612

609613
- github.com/go-jose/go-jose/v4/json
610614
License: BSD-3-Clause
611-
URL: https://github.com/go-jose/go-jose/blob/v4.1.2/json/LICENSE
615+
URL: https://github.com/go-jose/go-jose/blob/v4.1.3/json/LICENSE
612616

613617
- github.com/godbus/dbus
614618
License: BSD-2-Clause
@@ -1612,10 +1616,6 @@ MIT LICENSED DEPENDENCIES
16121616
License: MIT
16131617
URL: https://github.com/zealic/xignore/blob/v0.3.3/LICENSE.txt
16141618

1615-
- github.com/zeebo/errs
1616-
License: MIT
1617-
URL: https://github.com/zeebo/errs/blob/v1.4.0/LICENSE
1618-
16191619
- go.etcd.io/bbolt
16201620
License: MIT
16211621
URL: https://github.com/etcd-io/bbolt/blob/v1.4.0/LICENSE

cmd/auth_console_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"time"
99

1010
"github.com/spf13/cobra"
11+
"github.com/spf13/viper"
1112
"github.com/stretchr/testify/assert"
1213
"github.com/stretchr/testify/require"
1314
"go.uber.org/mock/gomock"
@@ -548,6 +549,10 @@ func TestResolveIdentityName(t *testing.T) {
548549
t.Run(tt.name, func(t *testing.T) {
549550
_ = NewTestKit(t)
550551

552+
// Ensure Viper doesn't have stale identity value from previous tests.
553+
// resolveIdentityName() reads from Viper when flag is not changed.
554+
viper.GetViper().Set("identity", "")
555+
551556
// Create a mock command.
552557
cmd := &cobra.Command{}
553558
cmd.Flags().String("identity", "", "identity name")

cmd/describe_affected_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"testing"
66

77
"github.com/spf13/pflag"
8+
"github.com/spf13/viper"
89
"github.com/stretchr/testify/assert"
910
"go.uber.org/mock/gomock"
1011

@@ -15,6 +16,15 @@ import (
1516
func TestDescribeAffected(t *testing.T) {
1617
_ = NewTestKit(t)
1718

19+
// Reset Viper to clear any environment variable bindings from previous tests.
20+
// This prevents ATMOS_IDENTITY or IDENTITY env vars from interfering with the test.
21+
viper.Reset()
22+
23+
// Clear identity environment variables to prevent Viper from reading them.
24+
// In CI, these might be set and cause auth validation to fail when no auth is configured.
25+
t.Setenv("ATMOS_IDENTITY", "")
26+
t.Setenv("IDENTITY", "")
27+
1828
t.Chdir("../tests/fixtures/scenarios/basic")
1929
ctrl := gomock.NewController(t)
2030
defer ctrl.Finish()

cmd/describe_dependents_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
"github.com/spf13/cobra"
77
"github.com/spf13/pflag"
8+
"github.com/spf13/viper"
89
"github.com/stretchr/testify/assert"
910
"go.uber.org/mock/gomock"
1011

@@ -15,6 +16,15 @@ import (
1516
func TestDescribeDependents(t *testing.T) {
1617
_ = NewTestKit(t)
1718

19+
// Reset Viper to clear any environment variable bindings from previous tests.
20+
// This prevents ATMOS_IDENTITY or IDENTITY env vars from interfering with the test.
21+
viper.Reset()
22+
23+
// Clear identity environment variables to prevent Viper from reading them.
24+
// In CI, these might be set and cause auth validation to fail when no auth is configured.
25+
t.Setenv("ATMOS_IDENTITY", "")
26+
t.Setenv("IDENTITY", "")
27+
1828
ctrl := gomock.NewController(t)
1929
defer ctrl.Finish()
2030

cmd/describe_stacks_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/spf13/cobra"
88
"github.com/spf13/pflag"
9+
"github.com/spf13/viper"
910
"github.com/stretchr/testify/assert"
1011
"go.uber.org/mock/gomock"
1112

@@ -16,6 +17,15 @@ import (
1617
func TestDescribeStacksRunnable(t *testing.T) {
1718
_ = NewTestKit(t)
1819

20+
// Reset Viper to clear any environment variable bindings from previous tests.
21+
// This prevents ATMOS_IDENTITY or IDENTITY env vars from interfering with the test.
22+
viper.Reset()
23+
24+
// Clear identity environment variables to prevent Viper from reading them.
25+
// In CI, these might be set and cause auth validation to fail when no auth is configured.
26+
t.Setenv("ATMOS_IDENTITY", "")
27+
t.Setenv("IDENTITY", "")
28+
1929
ctrl := gomock.NewController(t)
2030
defer ctrl.Finish()
2131

cmd/root.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,35 @@ func parseChdirFromArgs() string {
102102
return ""
103103
}
104104

105+
// syncGlobalFlagsToViper synchronizes global flags from Cobra's FlagSet to Viper.
106+
// This is necessary because Viper's BindPFlag doesn't immediately sync values when flags are parsed.
107+
// Call this after Cobra parses flags but before accessing flag values via Viper.
108+
//
109+
// Background: When using viper.BindPFlag(), the binding happens at initialization time,
110+
// but the actual flag value isn't synced to Viper until you call viper.Get*().
111+
// For some code paths (especially in InitCliConfig), we need the flag values
112+
// available in Viper before config loading completes.
113+
//
114+
// This function explicitly syncs changed flags to Viper, making their values
115+
// immediately available via viper.Get*() calls.
116+
func syncGlobalFlagsToViper(cmd *cobra.Command) {
117+
v := viper.GetViper()
118+
119+
// Sync profile flag if explicitly set.
120+
if cmd.Flags().Changed("profile") {
121+
if profiles, err := cmd.Flags().GetStringSlice("profile"); err == nil {
122+
v.Set("profile", profiles)
123+
}
124+
}
125+
126+
// Sync identity flag if explicitly set.
127+
if cmd.Flags().Changed("identity") {
128+
if identity, err := cmd.Flags().GetString("identity"); err == nil {
129+
v.Set("identity", identity)
130+
}
131+
}
132+
}
133+
105134
// processChdirFlag processes the --chdir flag and ATMOS_CHDIR environment variable,
106135
// changing the working directory before any other operations.
107136
// Precedence: --chdir flag > ATMOS_CHDIR environment variable.
@@ -203,6 +232,10 @@ var RootCmd = &cobra.Command{
203232
errUtils.CheckErrorPrintAndExit(err, "", "")
204233
}
205234

235+
// Sync global flags from Cobra to Viper before InitCliConfig.
236+
// This ensures flag values are immediately available in Viper for config loading.
237+
syncGlobalFlagsToViper(cmd)
238+
206239
configAndStacksInfo := schema.ConfigAndStacksInfo{}
207240
// Honor CLI overrides for resolving atmos.yaml and its imports.
208241
if bp, _ := cmd.Flags().GetString("base-path"); bp != "" {

0 commit comments

Comments
 (0)