diff --git a/src/cli.go b/src/cli.go index 60a40e2..b00e932 100644 --- a/src/cli.go +++ b/src/cli.go @@ -55,6 +55,11 @@ func Init() (a *App) { Short('V'). BoolVar(&a.log.verbose) + a.cli.Flag("fuck", "lets say fuck off AWS"). + Default("false"). + Hidden(). + BoolVar(&a.log.awsDebug) + ConfigureEnvCommand(a) ConfigureDotEnvCommand(a) ConfigureBackendCommand(a) diff --git a/src/command_dotenv.go b/src/command_dotenv.go index 5f5ed46..30c9068 100644 --- a/src/command_dotenv.go +++ b/src/command_dotenv.go @@ -97,7 +97,14 @@ func ConfigureDotEnvCommand(a *App) { } func (c *DotEnvCommand) initSsmClient() { - awsSession, err := session.NewSession() + awsConfig := &aws.Config{ + LogLevel: aws.LogLevel(aws.LogOff), + } + + if c.log.awsDebug { + awsConfig.LogLevel = aws.LogLevel(aws.LogDebugWithHTTPBody) + } + awsSession, err := session.NewSession(awsConfig) c.log.must(err) c.ssm = ssm.New(awsSession) } @@ -193,6 +200,8 @@ func (c *DotEnvCommand) processDotEnv() error { } } + c.log.Debug("uniqNames = %v", len(uniqNames)) + if len(uniqNames) == 0 { // Nothing to do, no SSM parameters. return nil @@ -205,13 +214,18 @@ func (c *DotEnvCommand) processDotEnv() error { i++ } + c.log.Debug("names = %v", len(names)) + for i := 0; i < len(names); i += c.batchSize { j := i + c.batchSize if j > len(names) { j = len(names) } - values, err := c.getParameters(names[i:j], c.decrypt, ssmVars[i:j]) + c.log.Debug("Batch [%v-%v], names: %v, ssmVars: %v", i, j, len(names[i:j]), len(ssmVars[i:j])) + + values, err := c.getParameters(names[i:j], c.decrypt, ssmVars) + c.log.Debug("Batch [%v-%v], values: %v", i, j, len(values)) if err != nil { return err } @@ -238,7 +252,11 @@ func (c *DotEnvCommand) getParameters(names []string, decrypt bool, ssmVars []ss input.Names = append(input.Names, aws.String(n)) } + c.log.Debug("REQ: Batch [%v], input.Name: %v", len(ssmVars), len(input.Names)) + resp, err := c.ssm.GetParameters(input) + c.log.Debug("RESP: Batch [%v], resp.Parameters: %v", len(ssmVars), len(resp.Parameters)) + c.log.must(err) for _, v := range ssmVars { diff --git a/src/logs.go b/src/logs.go index 6dbae92..7dba430 100644 --- a/src/logs.go +++ b/src/logs.go @@ -15,6 +15,7 @@ type Log struct { verbose bool silent bool isQuite bool + awsDebug bool } func (a *App) Logger() *Log { @@ -24,6 +25,7 @@ func (a *App) Logger() *Log { verbose: false, silent: false, isQuite: false, + awsDebug: false, ioWriter: os.Stdout, } } @@ -34,6 +36,10 @@ func (l *Log) HandleSilent() { } } +func (l *Log) EnableAwsDebug() { + l.awsDebug = true +} + func (l *Log) Quite() { if !l.verbose { l.isQuite = true @@ -50,6 +56,12 @@ func (l *Log) Info(format string, s ...interface{}) { showLog("INFO", fmt.Sprintf(format, s...), false, l.isQuite, l.ioWriter) } +func (l *Log) Debug(format string, s ...interface{}) { + if l.verbose { + showLog("DEBUG", fmt.Sprintf(format, s...), false, l.isQuite, l.ioWriter) + } +} + func (l *Log) Warning(format string, s ...interface{}) { showLog("WARNING", fmt.Sprintf(format, s...), false, l.isQuite, l.ioWriter) } diff --git a/src/main.go b/src/main.go index 28d34f1..fcb4d09 100644 --- a/src/main.go +++ b/src/main.go @@ -1,6 +1,6 @@ package main -const Version = "v0.3.5" +const Version = "v0.4.0" const CiEnvVar = "CI" const TerraformLocalEnvVar = "TF_LOCAL"