@@ -3,6 +3,7 @@ package main
3
3
import (
4
4
"encoding/json"
5
5
"fmt"
6
+ "log/slog"
6
7
"os"
7
8
"time"
8
9
@@ -17,23 +18,36 @@ var (
17
18
)
18
19
19
20
func main () {
21
+ rootCmd , err := newRootCmd ()
22
+ if err != nil {
23
+ slog .Error ("Failed to initialize CLI" , "error" , err )
24
+ os .Exit (1 )
25
+ }
26
+
27
+ if err := rootCmd .Execute (); err != nil {
28
+ slog .Error ("Encountered a fatal error during execution" , "error" , err )
29
+ os .Exit (1 )
30
+ }
31
+ }
32
+
33
+ func newRootCmd () (* cobra.Command , error ) {
20
34
rootCmd := & cobra.Command {
21
35
Use : "aws-spiffe-workload-helper" ,
22
36
Short : "TODO" , // TODO(strideynet): Helpful, short description.
23
37
Long : `TODO` , // TODO(strideynet): Helpful, long description.
24
38
Version : version ,
25
39
}
26
40
27
- x509CredentialProcessCmd := newX509CredentialProcessCmd ()
41
+ x509CredentialProcessCmd , err := newX509CredentialProcessCmd ()
42
+ if err != nil {
43
+ return nil , fmt .Errorf ("initializing x509-credential-process command: %w" , err )
44
+ }
28
45
rootCmd .AddCommand (x509CredentialProcessCmd )
29
46
30
- if err := rootCmd .Execute (); err != nil {
31
- fmt .Println (err .Error ())
32
- os .Exit (1 )
33
- }
47
+ return rootCmd , nil
34
48
}
35
49
36
- func newX509CredentialProcessCmd () * cobra.Command {
50
+ func newX509CredentialProcessCmd () ( * cobra.Command , error ) {
37
51
var (
38
52
roleARN string
39
53
region string
@@ -91,13 +105,19 @@ func newX509CredentialProcessCmd() *cobra.Command {
91
105
},
92
106
}
93
107
cmd .Flags ().StringVar (& roleARN , "role-arn" , "" , "The ARN of the role to assume. Required." )
94
- cmd .MarkFlagRequired ("role-arn" )
108
+ if err := cmd .MarkFlagRequired ("role-arn" ); err != nil {
109
+ return nil , fmt .Errorf ("marking role-arn flag as required: %w" , err )
110
+ }
95
111
cmd .Flags ().StringVar (& region , "region" , "" , "The AWS region to use. Optional." )
96
112
cmd .Flags ().StringVar (& profileARN , "profile-arn" , "" , "The ARN of the Roles Anywhere profile to use. Required." )
97
- cmd .MarkFlagRequired ("profile-arn" )
113
+ if err := cmd .MarkFlagRequired ("profile-arn" ); err != nil {
114
+ return nil , fmt .Errorf ("marking profile-arn flag as required: %w" , err )
115
+ }
98
116
cmd .Flags ().DurationVar (& sessionDuration , "session-duration" , 0 , "The duration of the resulting session. Optional. Can range from 15m to 12h." )
99
117
cmd .Flags ().StringVar (& trustAnchorARN , "trust-anchor-arn" , "" , "The ARN of the Roles Anywhere trust anchor to use. Required." )
100
- cmd .MarkFlagRequired ("trust-anchor-arn" )
118
+ if err := cmd .MarkFlagRequired ("trust-anchor-arn" ); err != nil {
119
+ return nil , fmt .Errorf ("marking trust-anchor-arn flag as required: %w" , err )
120
+ }
101
121
cmd .Flags ().StringVar (& roleSessionName , "role-session-name" , "" , "The identifier for the role session. Optional." )
102
- return cmd
122
+ return cmd , nil
103
123
}
0 commit comments