|
1 | | -package cmd |
2 | | - |
3 | | -import ( |
4 | | - "fmt" |
5 | | - |
6 | | - "github.com/dnitsch/aws-cli-auth/internal/auth" |
7 | | - "github.com/dnitsch/aws-cli-auth/internal/config" |
8 | | - "github.com/dnitsch/aws-cli-auth/internal/util" |
9 | | - "github.com/spf13/cobra" |
10 | | -) |
11 | | - |
12 | | -var ( |
13 | | - providerUrl string |
14 | | - principalArn string |
15 | | - acsUrl string |
16 | | - role string |
17 | | - duration int |
18 | | - reloadBeforeTime int |
19 | | - samlCmd = &cobra.Command{ |
20 | | - Use: "saml <SAML ProviderUrl>", |
21 | | - Short: "Get AWS credentials and out to stdout", |
22 | | - Long: `Get AWS credentials and out to stdout through your SAML provider authentication.`, |
23 | | - Run: getSaml, |
24 | | - PreRunE: func(cmd *cobra.Command, args []string) error { |
25 | | - if reloadBeforeTime != 0 && reloadBeforeTime > duration { |
26 | | - return fmt.Errorf("reload-before: %v, must be less than duration (-d): %v", reloadBeforeTime, duration) |
27 | | - } |
28 | | - return nil |
29 | | - }, |
30 | | - } |
31 | | -) |
32 | | - |
33 | | -func init() { |
34 | | - samlCmd.PersistentFlags().StringVarP(&providerUrl, "provider", "p", "", "Saml Entity StartSSO Url") |
35 | | - samlCmd.MarkPersistentFlagRequired("provider") |
36 | | - samlCmd.PersistentFlags().StringVarP(&principalArn, "principal", "", "", "Principal Arn of the SAML IdP in AWS") |
37 | | - samlCmd.MarkPersistentFlagRequired("principal") |
38 | | - samlCmd.PersistentFlags().StringVarP(&acsUrl, "acsurl", "a", "https://signin.aws.amazon.com/saml", "Override the default ACS Url, used for checkin the post of the SAMLResponse") |
39 | | - samlCmd.PersistentFlags().IntVarP(&duration, "max-duration", "d", 900, "Override default max session duration, in seconds, of the role session [900-43200]") |
40 | | - samlCmd.MarkPersistentFlagRequired("max-duration") |
41 | | - samlCmd.PersistentFlags().IntVarP(&reloadBeforeTime, "reload-before", "", 0, "Triggers a credentials refresh before the specified max-duration. Value provided in seconds. Should be less than the max-duration of the session") |
42 | | - rootCmd.AddCommand(samlCmd) |
43 | | -} |
44 | | - |
45 | | -func getSaml(cmd *cobra.Command, args []string) { |
46 | | - conf := config.SamlConfig{ |
47 | | - ProviderUrl: providerUrl, |
48 | | - PrincipalArn: principalArn, |
49 | | - Duration: duration, |
50 | | - AcsUrl: acsUrl, |
51 | | - BaseConfig: config.BaseConfig{ |
52 | | - StoreInProfile: storeInProfile, |
53 | | - Role: role, |
54 | | - CfgSectionName: cfgSectionName, |
55 | | - DoKillHangingProcess: killHangingProcess, |
56 | | - ReloadBeforeTime: reloadBeforeTime, |
57 | | - }, |
58 | | - } |
59 | | - |
60 | | - auth.GetSamlCreds(conf) |
61 | | - util.CleanExit() |
62 | | -} |
| 1 | +package cmd |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + |
| 6 | + "github.com/dnitsch/aws-cli-auth/internal/auth" |
| 7 | + "github.com/dnitsch/aws-cli-auth/internal/config" |
| 8 | + "github.com/dnitsch/aws-cli-auth/internal/util" |
| 9 | + "github.com/spf13/cobra" |
| 10 | +) |
| 11 | + |
| 12 | +var ( |
| 13 | + providerUrl string |
| 14 | + principalArn string |
| 15 | + acsUrl string |
| 16 | + role string |
| 17 | + duration int |
| 18 | + reloadBeforeTime int |
| 19 | + samlCmd = &cobra.Command{ |
| 20 | + Use: "saml <SAML ProviderUrl>", |
| 21 | + Short: "Get AWS credentials and out to stdout", |
| 22 | + Long: `Get AWS credentials and out to stdout through your SAML provider authentication.`, |
| 23 | + Run: getSaml, |
| 24 | + PreRunE: func(cmd *cobra.Command, args []string) error { |
| 25 | + if reloadBeforeTime != 0 && reloadBeforeTime > duration { |
| 26 | + return fmt.Errorf("reload-before: %v, must be less than duration (-d): %v", reloadBeforeTime, duration) |
| 27 | + } |
| 28 | + return nil |
| 29 | + }, |
| 30 | + } |
| 31 | +) |
| 32 | + |
| 33 | +func init() { |
| 34 | + samlCmd.PersistentFlags().StringVarP(&providerUrl, "provider", "p", "", "Saml Entity StartSSO Url") |
| 35 | + samlCmd.MarkPersistentFlagRequired("provider") |
| 36 | + samlCmd.PersistentFlags().StringVarP(&principalArn, "principal", "", "", "Principal Arn of the SAML IdP in AWS") |
| 37 | + samlCmd.MarkPersistentFlagRequired("principal") |
| 38 | + samlCmd.PersistentFlags().StringVarP(&acsUrl, "acsurl", "a", "https://signin.aws.amazon.com/saml", "Override the default ACS Url, used for checkin the post of the SAMLResponse") |
| 39 | + samlCmd.PersistentFlags().IntVarP(&duration, "max-duration", "d", 900, "Override default max session duration, in seconds, of the role session [900-43200]") |
| 40 | + samlCmd.MarkPersistentFlagRequired("max-duration") |
| 41 | + samlCmd.PersistentFlags().IntVarP(&reloadBeforeTime, "reload-before", "", 0, "Triggers a credentials refresh before the specified max-duration. Value provided in seconds. Should be less than the max-duration of the session") |
| 42 | + rootCmd.AddCommand(samlCmd) |
| 43 | +} |
| 44 | + |
| 45 | +func getSaml(cmd *cobra.Command, args []string) { |
| 46 | + conf := config.SamlConfig{ |
| 47 | + ProviderUrl: providerUrl, |
| 48 | + PrincipalArn: principalArn, |
| 49 | + Duration: duration, |
| 50 | + AcsUrl: acsUrl, |
| 51 | + BaseConfig: config.BaseConfig{ |
| 52 | + StoreInProfile: storeInProfile, |
| 53 | + Role: role, |
| 54 | + CfgSectionName: cfgSectionName, |
| 55 | + DoKillHangingProcess: killHangingProcess, |
| 56 | + ReloadBeforeTime: reloadBeforeTime, |
| 57 | + }, |
| 58 | + } |
| 59 | + |
| 60 | + auth.GetSamlCreds(conf) |
| 61 | + util.CleanExit() |
| 62 | +} |
0 commit comments