Skip to content

Commit

Permalink
Merge pull request #42 from buildkite/keithduncan/fix-zero-data
Browse files Browse the repository at this point in the history
Check env data length before indexing
  • Loading branch information
keithduncan authored Jul 16, 2021
2 parents 5f59864 + 0b33277 commit 7c42323
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions s3secrets-helper/secrets/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,15 @@ func handleEnvs(conf Config, results <-chan getResult) error {
continue
}
data := r.data
if data[len(data)-1] != '\n' {
data = append(data, '\n')
}
log.Printf("Loading %s/%s (%d bytes) of env", r.bucket, r.key, len(r.data))
if _, err := bytes.NewReader(data).WriteTo(conf.EnvSink); err != nil {
return fmt.Errorf("copying env: %w", err)

if len(data) > 0 {
if data[len(data)-1] != '\n' {
data = append(data, '\n')
}
log.Printf("Loading %s/%s (%d bytes) of env", r.bucket, r.key, len(r.data))
if _, err := bytes.NewReader(data).WriteTo(conf.EnvSink); err != nil {
return fmt.Errorf("copying env: %w", err)
}
}
}
return nil
Expand Down

0 comments on commit 7c42323

Please sign in to comment.