Skip to content

Commit

Permalink
fix: fails when there are more than 10 parameters (#4)
Browse files Browse the repository at this point in the history
* chore: add validation

* chore: add empty line on console

* fix: using more than 10 parameters failes

* feat: display total numbers of parameters in list command
  • Loading branch information
adikari committed Oct 20, 2022
1 parent 07492d2 commit d951ff0
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 17 deletions.
2 changes: 1 addition & 1 deletion cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func deploy(cmd *cobra.Command, args []string) error {
return errors.Wrap(err, "failed to write params")
}

fmt.Printf("%d new configs deployed. service = %s, stage = %s", len(configsToDeploy), config.Service, stage)
fmt.Printf("%d new configs deployed. service = %s, stage = %s\n", len(configsToDeploy), config.Service, stage)

return nil
}
Expand Down
4 changes: 4 additions & 0 deletions cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ func printList(configs []store.Config) {
fmt.Fprintln(w, "")
}

fmt.Fprintln(w, "---")
fmt.Fprintf(w, "Total parameters = %d", len(configs))
fmt.Fprintln(w, "")

w.Flush()
}

Expand Down
7 changes: 6 additions & 1 deletion example/safebox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@ cloudformation-stacks:
config:
defaults:
DB_NAME: "database name updated"
API_ENDPOINT: "{{.authorizerLambaArns}}"
API_ENDPOINT: "{{.internalDomainName}}"
NEW: "endpoint-{{.stage}}"
NEW2: "endpoint updated"
NEW3: "endpoint updated"
NEW4: "endpoint updated"
NEW5: "endpoint updated"
NEW6: "endpoint updated"
NEW7: "endpoint updated"

prod:
DB_NAME: "production db name"
Expand Down
4 changes: 2 additions & 2 deletions npm/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions npm/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
{
"name": "@adikari/safebox",
"version": "1.1.6",
"version": "1.1.8",
"description": "A Fast and Flexible secret manager built with love by adikari in Go",
"main": "index.js",
"bin": {
"safebox": "./run.js"
},
"bin": "./run.js",
"scripts": {
"postinstall": "node install.js install",
"preuninstall": "node install.js uninstall",
Expand Down
34 changes: 25 additions & 9 deletions store/ssmstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package store
import (
"strings"

"github.com/adikari/safebox/v2/util"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/client"
"github.com/aws/aws-sdk-go/aws/session"
Expand Down Expand Up @@ -98,21 +99,36 @@ func (s *SSMStore) GetMany(configs []ConfigInput) ([]Config, error) {
return []Config{}, nil
}

getParametersInput := &ssm.GetParametersInput{
Names: getNames(configs),
WithDecryption: aws.Bool(true),
}
get := func(c []ConfigInput) ([]Config, error) {
var res []Config

resp, err := s.svc.GetParameters(getParametersInput)
getParametersInput := &ssm.GetParametersInput{
Names: getNames(c),
WithDecryption: aws.Bool(true),
}

if err != nil {
return []Config{}, err
resp, err := s.svc.GetParameters(getParametersInput)

if err != nil {
return []Config{}, err
}

for _, param := range resp.Parameters {
res = append(res, parameterToConfig(param))
}

return res, nil
}

var params []Config
for _, chunk := range util.ChunkSlice(configs, 10) {
p, err := get(chunk)

if err != nil {
return []Config{}, err
}

for _, param := range resp.Parameters {
params = append(params, parameterToConfig(param))
params = append(params, p...)
}

return params, nil
Expand Down
16 changes: 16 additions & 0 deletions util/util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package util

func ChunkSlice[T any](slice []T, chunkSize int) [][]T {
var chunks [][]T
for i := 0; i < len(slice); i += chunkSize {
end := i + chunkSize

if end > len(slice) {
end = len(slice)
}

chunks = append(chunks, slice[i:end])
}

return chunks
}

0 comments on commit d951ff0

Please sign in to comment.