-
-
Notifications
You must be signed in to change notification settings - Fork 153
Expand file tree
/
Copy pathdescribe_component.go
More file actions
156 lines (132 loc) · 5.27 KB
/
describe_component.go
File metadata and controls
156 lines (132 loc) · 5.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package cmd
import (
"errors"
"os"
"github.com/spf13/cobra"
errUtils "github.com/cloudposse/atmos/errors"
e "github.com/cloudposse/atmos/internal/exec"
"github.com/cloudposse/atmos/pkg/auth"
cfg "github.com/cloudposse/atmos/pkg/config"
"github.com/cloudposse/atmos/pkg/schema"
)
// describeComponentCmd describes configuration for components
var describeComponentCmd = &cobra.Command{
Use: "component",
Short: "Show configuration details for an Atmos component in a stack",
Long: `Display the configuration details for a specific Atmos component within a designated Atmos stack, including its dependencies, settings, and overrides.`,
FParseErrWhitelist: struct{ UnknownFlags bool }{UnknownFlags: false},
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
// Check Atmos configuration
checkAtmosConfig()
if len(args) != 1 {
return errors.New("invalid arguments. The command requires one argument `component`")
}
flags := cmd.Flags()
stack, err := flags.GetString("stack")
if err != nil {
return err
}
format, err := flags.GetString("format")
if err != nil {
return err
}
file, err := flags.GetString("file")
if err != nil {
return err
}
processTemplates, err := flags.GetBool("process-templates")
if err != nil {
return err
}
processYamlFunctions, err := flags.GetBool("process-functions")
if err != nil {
return err
}
query, err := flags.GetString("query")
if err != nil {
return err
}
skip, err := flags.GetStringSlice("skip")
if err != nil {
return err
}
provenance, err := flags.GetBool("provenance")
if err != nil {
return err
}
component := args[0]
// Load atmos configuration to get auth config.
atmosConfig, err := cfg.InitCliConfig(schema.ConfigAndStacksInfo{
ComponentFromArg: component,
Stack: stack,
}, false)
if err != nil {
return errors.Join(errUtils.ErrFailedToInitConfig, err)
}
// Get identity flag value.
identityName := GetIdentityFromFlags(cmd, os.Args)
// Get component-specific auth config and merge with global auth config.
// This follows the same pattern as terraform.go to handle stack-level default identities.
// Start with global config.
mergedAuthConfig := auth.CopyGlobalAuthConfig(&atmosConfig.Auth)
// Get component config to extract auth section (without processing YAML functions to avoid circular dependency).
componentConfig, componentErr := e.ExecuteDescribeComponent(&e.ExecuteDescribeComponentParams{
Component: component,
Stack: stack,
ProcessTemplates: false,
ProcessYamlFunctions: false, // Avoid circular dependency with YAML functions that need auth.
Skip: nil,
AuthManager: nil, // No auth manager yet - we're determining which identity to use.
})
if componentErr != nil {
// If component doesn't exist, exit immediately before attempting authentication.
// This prevents prompting for identity when the component is invalid.
if errors.Is(componentErr, errUtils.ErrInvalidComponent) {
return componentErr
}
// For other errors (e.g., permission issues), continue with global auth config.
} else {
// Merge component-specific auth with global auth.
mergedAuthConfig, err = auth.MergeComponentAuthFromConfig(&atmosConfig.Auth, componentConfig, &atmosConfig, cfg.AuthSectionName)
if err != nil {
return err
}
}
// Create and authenticate AuthManager using merged auth config.
// This enables stack-level default identity to be recognized.
authManager, err := CreateAuthManagerFromIdentity(identityName, mergedAuthConfig)
if err != nil {
return err
}
err = e.NewDescribeComponentExec().ExecuteDescribeComponentCmd(e.DescribeComponentParams{
Component: component,
Stack: stack,
ProcessTemplates: processTemplates,
ProcessYamlFunctions: processYamlFunctions,
Skip: skip,
Query: query,
Format: format,
File: file,
Provenance: provenance,
AuthManager: authManager,
})
return err
},
ValidArgsFunction: ComponentsArgCompletion,
}
func init() {
describeComponentCmd.DisableFlagParsing = false
AddStackCompletion(describeComponentCmd)
describeComponentCmd.PersistentFlags().StringP("format", "f", "yaml", "The output format")
describeComponentCmd.PersistentFlags().String("file", "", "Write the result to the file")
describeComponentCmd.PersistentFlags().Bool("process-templates", true, "Enable/disable Go template processing in Atmos stack manifests when executing the command")
describeComponentCmd.PersistentFlags().Bool("process-functions", true, "Enable/disable YAML functions processing in Atmos stack manifests when executing the command")
describeComponentCmd.PersistentFlags().StringSlice("skip", nil, "Skip executing a YAML function in the Atmos stack manifests when executing the command")
describeComponentCmd.PersistentFlags().Bool("provenance", false, "Enable provenance tracking to show where configuration values originated")
err := describeComponentCmd.MarkPersistentFlagRequired("stack")
if err != nil {
errUtils.CheckErrorPrintAndExit(err, "", "")
}
describeCmd.AddCommand(describeComponentCmd)
}