Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
685978d
updates
aknysh Nov 7, 2025
d3c654d
updates
aknysh Nov 7, 2025
11c6e42
updates
aknysh Nov 7, 2025
1c17ddb
updates
aknysh Nov 7, 2025
faab21d
updates
aknysh Nov 7, 2025
58463cb
updates
aknysh Nov 7, 2025
a6661cd
updates
aknysh Nov 7, 2025
1c4b3a0
updates
aknysh Nov 7, 2025
46ac268
Merge remote-tracking branch 'origin/main' into fix-terraform-state-w…
aknysh Nov 7, 2025
d38696e
[autofix.ci] apply automated fixes
autofix-ci[bot] Nov 7, 2025
cc872cc
fix: Thread authManager through detectComponentType and update NOTICE
aknysh Nov 8, 2025
aefd571
[autofix.ci] apply automated fixes
autofix-ci[bot] Nov 8, 2025
24084b8
updates
aknysh Nov 8, 2025
81b57cb
fix: Replace math.MaxInt32 with FatalLevel+1 for log disabling and di…
aknysh Nov 8, 2025
c90baba
refactor: Use ParseLogLevel and ConvertLogLevel utilities in setLogCo…
aknysh Nov 8, 2025
6abd1b6
Merge remote-tracking branch 'origin/main' into fix-terraform-state-w…
aknysh Nov 8, 2025
e9751d9
Merge remote-tracking branch 'origin/main' into fix-terraform-state-w…
aknysh Nov 9, 2025
eff50a7
updates
aknysh Nov 9, 2025
9c7bf18
[autofix.ci] apply automated fixes
autofix-ci[bot] Nov 9, 2025
8dee563
updates
aknysh Nov 10, 2025
a83310e
Merge remote-tracking branch 'origin/main' into fix-terraform-state-w…
aknysh Nov 10, 2025
4306226
updates
aknysh Nov 10, 2025
bf6c3ea
[autofix.ci] apply automated fixes
autofix-ci[bot] Nov 10, 2025
c82617e
feat: Auto-detect default identity for YAML function authentication
aknysh Nov 10, 2025
ffa099f
feat: Support --identity=off to disable authentication
aknysh Nov 10, 2025
6b39bb8
Format Go code blocks in terraform authentication PRD
aknysh Nov 10, 2025
d8d60f6
Fix CodeRabbitAI issues and format Go code in terraform output auth f…
aknysh Nov 10, 2025
c4aa489
Add authentication flow documentation for !terraform.state YAML function
aknysh Nov 10, 2025
a62c31f
updates
aknysh Nov 10, 2025
0b0a332
Merge remote-tracking branch 'origin/fix-terraform-state-with-auth' i…
aknysh Nov 10, 2025
02e57f6
Fix: Prompt users once for identity selection when no default configured
aknysh Nov 10, 2025
ff5dbec
Add debug logging to track identity selection prompts
aknysh Nov 10, 2025
e1a47cc
updates
aknysh Nov 10, 2025
749d39d
updates
aknysh Nov 10, 2025
ace6f54
updates
aknysh Nov 10, 2025
cf495a4
Merge branch 'main' into fix-terraform-state-with-auth
aknysh Nov 10, 2025
eadecc1
updates
aknysh Nov 10, 2025
dac96a5
Merge branch 'main' into fix-terraform-state-with-auth
aknysh Nov 10, 2025
c57aed3
updates
aknysh Nov 10, 2025
c08ae73
updates
aknysh Nov 10, 2025
de0201b
updates
aknysh Nov 11, 2025
f4cae61
updates
aknysh Nov 11, 2025
eb7fe90
updates
aknysh Nov 11, 2025
a503bd1
updates
aknysh Nov 11, 2025
1e53f50
updates
aknysh Nov 11, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ APACHE 2.0 LICENSED DEPENDENCIES

- github.com/aws/aws-sdk-go-v2/service/ssm
License: Apache-2.0
URL: https://github.com/aws/aws-sdk-go-v2/blob/service/ssm/v1.66.4/service/ssm/LICENSE.txt
URL: https://github.com/aws/aws-sdk-go-v2/blob/service/ssm/v1.67.0/service/ssm/LICENSE.txt

- github.com/aws/aws-sdk-go-v2/service/sso
License: Apache-2.0
Expand Down Expand Up @@ -732,7 +732,7 @@ BSD LICENSED DEPENDENCIES

- golang.org/x/oauth2
License: BSD-3-Clause
URL: https://cs.opensource.google/go/x/oauth2/+/v0.32.0:LICENSE
URL: https://cs.opensource.google/go/x/oauth2/+/v0.33.0:LICENSE

- golang.org/x/sync
License: BSD-3-Clause
Expand Down
13 changes: 6 additions & 7 deletions cmd/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@ func init() {
// when processing YAML template functions (!terraform.state, !terraform.output).
// By default, all describe commands execute YAML functions and Go templates unless
// disabled with --process-functions=false or --process-templates=false flags.
describeCmd.PersistentFlags().StringP("identity", "i", "", "Specify the identity to authenticate to before describing. Use without value to interactively select.")

// Set NoOptDefVal to enable optional flag value for interactive identity selection.
// When --identity is used without a value, it will receive IdentityFlagSelectValue.
if identityFlag := describeCmd.PersistentFlags().Lookup("identity"); identityFlag != nil {
identityFlag.NoOptDefVal = IdentityFlagSelectValue
}
//
// NOTE: NoOptDefVal is NOT used here to avoid Cobra parsing issues with commands
// that have positional arguments. When NoOptDefVal is set and a space-separated value
// is used (--identity value), Cobra misinterprets the value as a subcommand/positional arg.
// Users should use --identity=select or similar for interactive selection.
describeCmd.PersistentFlags().StringP("identity", "i", "", "Specify the identity to authenticate with before describing")

// Register shell completion for identity flag.
AddIdentityCompletion(describeCmd)
Expand Down
47 changes: 4 additions & 43 deletions cmd/identity_flag.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
package cmd

import (
"context"
"errors"
"fmt"
"strings"

"github.com/spf13/cobra"
"github.com/spf13/viper"

errUtils "github.com/cloudposse/atmos/errors"
"github.com/cloudposse/atmos/pkg/auth"
"github.com/cloudposse/atmos/pkg/auth/credentials"
"github.com/cloudposse/atmos/pkg/auth/validation"
cfg "github.com/cloudposse/atmos/pkg/config"
"github.com/cloudposse/atmos/pkg/schema"
)
Expand Down Expand Up @@ -133,45 +127,12 @@ func extractIdentityFromArgs(args []string) string {
// Returns nil if identityName is empty (no authentication requested).
// Returns error if identityName is provided but auth is not configured in atmos.yaml.
// This helper reduces nested complexity in describe commands.
//
// This function delegates to auth.CreateAndAuthenticateManager to ensure consistent
// authentication behavior across CLI commands and internal execution logic.
func CreateAuthManagerFromIdentity(
identityName string,
authConfig *schema.AuthConfig,
) (auth.AuthManager, error) {
if identityName == "" {
return nil, nil
}

// Check if auth is configured when --identity flag is provided.
if authConfig == nil || len(authConfig.Identities) == 0 {
return nil, fmt.Errorf("%w: the --identity flag requires authentication to be configured in atmos.yaml with at least one identity", errUtils.ErrAuthNotConfigured)
}

// Create a ConfigAndStacksInfo for the auth manager to populate with AuthContext.
authStackInfo := &schema.ConfigAndStacksInfo{
AuthContext: &schema.AuthContext{},
}

credStore := credentials.NewCredentialStore()
validator := validation.NewValidator()
authManager, err := auth.NewAuthManager(authConfig, credStore, validator, authStackInfo)
if err != nil {
return nil, errors.Join(errUtils.ErrFailedToInitializeAuthManager, err)
}

// Handle interactive selection.
forceSelect := identityName == IdentityFlagSelectValue
if forceSelect {
identityName, err = authManager.GetDefaultIdentity(forceSelect)
if err != nil {
return nil, err
}
}

// Authenticate.
_, err = authManager.Authenticate(context.Background(), identityName)
if err != nil {
return nil, err
}

return authManager, nil
return auth.CreateAndAuthenticateManager(identityName, authConfig, IdentityFlagSelectValue)
}
8 changes: 5 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,10 @@ var RootCmd = &cobra.Command{
},
}

// setupLogger configures the global logger based on the provided Atmos configuration.
func setupLogger(atmosConfig *schema.AtmosConfiguration) {
// SetupLogger configures the global logger based on the provided Atmos configuration.
//
//nolint:revive,cyclop // Function complexity is acceptable for logger configuration.
func SetupLogger(atmosConfig *schema.AtmosConfiguration) {
switch atmosConfig.Logs.Level {
case "Trace":
log.SetLevel(log.TraceLevel)
Expand Down Expand Up @@ -577,7 +579,7 @@ func Execute() error {
}

// Set the log level for the charmbracelet/log package based on the atmosConfig.
setupLogger(&atmosConfig)
SetupLogger(&atmosConfig)

var err error
// If CLI configuration was found, process its custom commands and command aliases.
Expand Down
12 changes: 6 additions & 6 deletions cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func TestSetupLogger_TraceLevel(t *testing.T) {
},
}

setupLogger(cfg)
SetupLogger(cfg)
assert.Equal(t, tt.expectedLevel, log.GetLevel(),
"Expected level %v for config %q", tt.expectedLevel, tt.configLevel)
})
Expand Down Expand Up @@ -228,7 +228,7 @@ func TestSetupLogger_TraceVisibility(t *testing.T) {
Terminal: schema.Terminal{},
},
}
setupLogger(cfg)
SetupLogger(cfg)

// Test trace visibility.
buf.Reset()
Expand Down Expand Up @@ -281,7 +281,7 @@ func TestSetupLogger_TraceLevelFromEnvironment(t *testing.T) {
Terminal: schema.Terminal{},
},
}
setupLogger(cfg)
SetupLogger(cfg)

assert.Equal(t, log.TraceLevel, log.GetLevel(),
"Should set trace level from environment variable")
Expand Down Expand Up @@ -309,10 +309,10 @@ func TestSetupLogger_NoColorWithTraceLevel(t *testing.T) {
}

// Mock the IsColorEnabled to return false.
// Since we can't easily mock it, we'll just test that setupLogger doesn't panic.
// Since we can't easily mock it, we'll just test that SetupLogger doesn't panic.
assert.NotPanics(t, func() {
setupLogger(cfg)
}, "setupLogger should not panic with trace level and no color")
SetupLogger(cfg)
}, "SetupLogger should not panic with trace level and no color")

assert.Equal(t, log.TraceLevel, log.GetLevel(),
"Trace level should be set even with no color")
Expand Down
Loading
Loading