Skip to content

Commit c11118e

Browse files
committed
fix: fmted with -s
1 parent 33df08e commit c11118e

File tree

6 files changed

+359
-358
lines changed

6 files changed

+359
-358
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# aws-cli-auth
22

3+
[![Go Report Card](https://goreportcard.com/badge/github.com/dnitsch/aws-cli-auth)](https://goreportcard.com/report/github.com/dnitsch/aws-cli-auth)
4+
35
CLI tool for retrieving AWS temporary credentials using SAML providers.
46

57
Firstly, this package currently deals with SAML only, however if you have an OIDC IdP provider set up to AWS you can use this [package](https://github.com/openstandia/aws-cli-oidc) and likewise this [package](https://github.com/Versent/saml2aws) for standard SAML only AWS integrations - standard meaning.

aws-cli-auth.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
package main
2-
3-
import "github.com/dnitsch/aws-cli-auth/cmd"
4-
5-
func main() {
6-
cmd.Execute()
7-
}
1+
package main
2+
3+
import "github.com/dnitsch/aws-cli-auth/cmd"
4+
5+
func main() {
6+
cmd.Execute()
7+
}

cmd/root.go

Lines changed: 48 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,48 @@
1-
package cmd
2-
3-
import (
4-
"fmt"
5-
"os"
6-
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-
cfgSectionName string
14-
cfgFile string
15-
storeInProfile bool
16-
killHangingProcess bool
17-
verbose bool
18-
rootCmd = &cobra.Command{
19-
Use: "aws-cli-auth",
20-
Short: "CLI tool for retrieving AWS temporary credentials",
21-
Long: `CLI tool for retrieving AWS temporary credentials using SAML providers, or specified method of retrieval - i.e. force AWS_WEB_IDENTITY.
22-
Useful in situations like CI jobs or containers where multiple env vars might be present.
23-
Stores them under the $HOME/.aws/credentials file under a specified path or returns the crednetial_process payload for use in config`,
24-
}
25-
)
26-
27-
func Execute() {
28-
if err := rootCmd.Execute(); err != nil {
29-
util.Exit(err)
30-
}
31-
}
32-
33-
func init() {
34-
cobra.OnInitialize(initConfig)
35-
rootCmd.PersistentFlags().StringVarP(&role, "role", "r", "", "Set the role you want to assume when SAML or OIDC process completes")
36-
rootCmd.PersistentFlags().StringVarP(&cfgSectionName, "cfg-section", "", "", "config section name in the yaml config file")
37-
rootCmd.PersistentFlags().BoolVarP(&storeInProfile, "store-profile", "s", false, "By default the credentials are returned to stdout to be used by the credential_process. Set this flag to instead store the credentials under a named profile section")
38-
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Verbose output")
39-
}
40-
41-
func initConfig() {
42-
util.IsTraceEnabled = verbose
43-
if _, err := os.Stat(util.ConfigIniFile("")); err != nil {
44-
// creating a file
45-
rolesInit := []byte(fmt.Sprintf("[%s]\n", config.INI_CONF_SECTION))
46-
err := os.WriteFile(util.ConfigIniFile(""), rolesInit, 0644)
47-
cobra.CheckErr(err)
48-
}
49-
}
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
"os"
6+
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+
cfgSectionName string
14+
storeInProfile bool
15+
killHangingProcess bool
16+
verbose bool
17+
rootCmd = &cobra.Command{
18+
Use: "aws-cli-auth",
19+
Short: "CLI tool for retrieving AWS temporary credentials",
20+
Long: `CLI tool for retrieving AWS temporary credentials using SAML providers, or specified method of retrieval - i.e. force AWS_WEB_IDENTITY.
21+
Useful in situations like CI jobs or containers where multiple env vars might be present.
22+
Stores them under the $HOME/.aws/credentials file under a specified path or returns the crednetial_process payload for use in config`,
23+
}
24+
)
25+
26+
func Execute() {
27+
if err := rootCmd.Execute(); err != nil {
28+
util.Exit(err)
29+
}
30+
}
31+
32+
func init() {
33+
cobra.OnInitialize(initConfig)
34+
rootCmd.PersistentFlags().StringVarP(&role, "role", "r", "", "Set the role you want to assume when SAML or OIDC process completes")
35+
rootCmd.PersistentFlags().StringVarP(&cfgSectionName, "cfg-section", "", "", "config section name in the yaml config file")
36+
rootCmd.PersistentFlags().BoolVarP(&storeInProfile, "store-profile", "s", false, "By default the credentials are returned to stdout to be used by the credential_process. Set this flag to instead store the credentials under a named profile section")
37+
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Verbose output")
38+
}
39+
40+
func initConfig() {
41+
util.IsTraceEnabled = verbose
42+
if _, err := os.Stat(util.ConfigIniFile("")); err != nil {
43+
// creating a file
44+
rolesInit := []byte(fmt.Sprintf("[%s]\n", config.INI_CONF_SECTION))
45+
err := os.WriteFile(util.ConfigIniFile(""), rolesInit, 0644)
46+
cobra.CheckErr(err)
47+
}
48+
}

cmd/saml.go

Lines changed: 62 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,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-
}
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

Comments
 (0)