Skip to content

Commit

Permalink
chore: add validation
Browse files Browse the repository at this point in the history
  • Loading branch information
adikari committed Oct 4, 2022
1 parent 7a9fa21 commit 1513127
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 8 deletions.
5 changes: 5 additions & 0 deletions cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ func list(cmd *cobra.Command, args []string) error {
}

func printList(configs []store.Config) {
if len(configs) <= 0 {
fmt.Print("no configurations to list")
return
}

w := tabwriter.NewWriter(os.Stdout, 0, 8, 2, '\t', 0)

fmt.Fprint(w, "Name\tValue\tType\tVersion\tLastModified")
Expand Down
19 changes: 17 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io/ioutil"

"github.com/adikari/safebox/v2/store"
"github.com/pkg/errors"
"gopkg.in/yaml.v2"
)

Expand Down Expand Up @@ -48,8 +49,10 @@ func Load(param LoadConfigInput) (*Config, error) {
return nil, fmt.Errorf("could not parse safebox config file %s", param.Path)
}

if rc.Service == "" {
return nil, fmt.Errorf("'service' missing in config file%s", param.Path)
err = validateConfig(rc)

if err != nil {
return nil, errors.Wrap(err, "invalid configuration")
}

c := Config{}
Expand Down Expand Up @@ -128,6 +131,18 @@ func formatPath(stage string, service string, key string) string {
return fmt.Sprintf("/%s/%s/%s", stage, service, key)
}

func validateConfig(rc rawConfig) error {
if rc.Service == "" {
return fmt.Errorf("'service' is missing")
}

if rc.Provider == "" {
return fmt.Errorf("'provider' is missing")
}

return nil
}

func Interpolate(value string, variables map[string]string) (string, error) {
var result bytes.Buffer
tmpl, _ := template.New("interpolate").Option("missingkey=error").Parse(value)
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.7",
"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
4 changes: 4 additions & 0 deletions store/ssmstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ func (s *SSMStore) Delete(config ConfigInput) error {
}

func (s *SSMStore) GetMany(configs []ConfigInput) ([]Config, error) {
if len(configs) <= 0 {
return []Config{}, nil
}

getParametersInput := &ssm.GetParametersInput{
Names: getNames(configs),
WithDecryption: aws.Bool(true),
Expand Down

0 comments on commit 1513127

Please sign in to comment.