Skip to content

Commit

Permalink
aws-go-sdk v1.15.49 (was 1.13.37), ssm buffering issue fixed within m…
Browse files Browse the repository at this point in the history
…ore than 10 smm batch vars, debugging logs, special flag
  • Loading branch information
wobondar committed Oct 8, 2018
1 parent 93d9c25 commit bf6bb03
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 20 additions & 2 deletions src/command_dotenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand All @@ -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 {
Expand Down
12 changes: 12 additions & 0 deletions src/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type Log struct {
verbose bool
silent bool
isQuite bool
awsDebug bool
}

func (a *App) Logger() *Log {
Expand All @@ -24,6 +25,7 @@ func (a *App) Logger() *Log {
verbose: false,
silent: false,
isQuite: false,
awsDebug: false,
ioWriter: os.Stdout,
}
}
Expand All @@ -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
Expand All @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion src/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package main

const Version = "v0.3.5"
const Version = "v0.4.0"

const CiEnvVar = "CI"
const TerraformLocalEnvVar = "TF_LOCAL"
Expand Down

0 comments on commit bf6bb03

Please # to comment.