Skip to content

Commit 4ff5006

Browse files
committed
style: add/remove logging
1 parent eb788b2 commit 4ff5006

File tree

4 files changed

+13
-14
lines changed

4 files changed

+13
-14
lines changed

cmd/root.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"os"
66

77
"github.com/dnitsch/aws-cli-auth/internal/config"
8+
"github.com/dnitsch/aws-cli-auth/internal/util"
89
"github.com/spf13/cobra"
910
"github.com/spf13/viper"
1011
)
@@ -14,6 +15,7 @@ var (
1415
cfgFile string
1516
storeInProfile bool
1617
killHangingProcess bool
18+
verbose bool
1719
rootCmd = &cobra.Command{
1820
Use: "aws-cli-auth",
1921
Short: "CLI tool for retrieving AWS temporary credentials",
@@ -25,7 +27,7 @@ Stores them under the $HOME/.aws/credentials file under a specified path or retu
2527

2628
func Execute() {
2729
if err := rootCmd.Execute(); err != nil {
28-
fmt.Errorf(err.Error())
30+
util.Exit(err)
2931
}
3032
}
3133

@@ -34,7 +36,7 @@ func init() {
3436
rootCmd.PersistentFlags().StringVarP(&role, "role", "r", "", "Set the role you want to assume when SAML or OIDC process completes")
3537
rootCmd.PersistentFlags().StringVarP(&cfgSectionName, "cfg-section", "", "", "config section name in the yaml config file")
3638
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(&killHangingProcess, "kill-rod", "k", false, "If aws-cli-auth exited improprely in a previous run there is a chance that there could be hanging processes left over - this will clean them up forcefully")
39+
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Verbose output")
3840
}
3941

4042
func initConfig() {
@@ -54,7 +56,10 @@ func initConfig() {
5456

5557
viper.AutomaticEnv()
5658
viper.WriteConfig()
59+
60+
util.IsTraceEnabled = verbose
61+
5762
if err := viper.ReadInConfig(); err == nil {
58-
fmt.Println("Using config file:", viper.ConfigFileUsed())
63+
util.Traceln("Using config file:", viper.ConfigFileUsed())
5964
}
6065
}

internal/auth/saml.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package auth
22

33
import (
4-
"fmt"
54
"os/user"
6-
"runtime"
75

86
"github.com/dnitsch/aws-cli-auth/internal/config"
97
"github.com/dnitsch/aws-cli-auth/internal/util"
@@ -20,9 +18,6 @@ func GetSamlCreds(conf config.SamlConfig) {
2018
var awsCreds *util.AWSCredentials
2119
var err error
2220

23-
os := runtime.GOOS
24-
util.Writeln("Is OS: %s\nAnd conf.BaseConfig.StoreInProfile: %v", os, conf.BaseConfig.StoreInProfile)
25-
2621
// Try to reuse stored credential in secret
2722
if !conf.BaseConfig.StoreInProfile {
2823
awsCreds, err = util.AWSCredential(conf.BaseConfig.Role)
@@ -43,7 +38,7 @@ func GetSamlCreds(conf config.SamlConfig) {
4338

4439
awsCreds, err = LoginStsSaml(t, roleObj)
4540
if err != nil {
46-
fmt.Printf("%v", err)
41+
util.Writeln("%v", err)
4742
util.Exit(err)
4843
}
4944

internal/util/helper.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func SetCredentials(creds *AWSCredentials, config config.SamlConfig) {
3131

3232
if config.BaseConfig.StoreInProfile {
3333
if err := storeCredentialsInProfile(*creds, config.BaseConfig.CfgSectionName); err != nil {
34-
fmt.Printf("Error: %s", err.Error())
34+
Traceln("Error: %s", err.Error())
3535
}
3636
return
3737
}
@@ -54,8 +54,8 @@ func storeCredentialsInProfile(creds AWSCredentials, configSection string) error
5454

5555
cfg, err := ini.Load(awsConfPath)
5656
if err != nil {
57-
fmt.Printf("Fail to read file: %v", err)
58-
os.Exit(1)
57+
Writeln("Fail to read file: %v", err)
58+
Exit(err)
5959
}
6060
cfg.Section(configSection).Key("aws_access_key_id").SetValue(creds.AWSAccessKey)
6161
cfg.Section(configSection).Key("aws_secret_access_key").SetValue(creds.AWSSecretKey)
@@ -88,4 +88,3 @@ func GetWebIdTokenFileContents() (string, error) {
8888
}
8989
return string(content), nil
9090
}
91-

internal/web/web.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func checkRodProcess() error {
105105
}
106106
}
107107
for _, pid := range pids {
108-
fmt.Printf("Process to be killed as part of clean up: %d", pid)
108+
util.Traceln("Process to be killed as part of clean up: %d", pid)
109109
if proc, _ := os.FindProcess(pid); proc != nil {
110110
proc.Kill()
111111
}

0 commit comments

Comments
 (0)