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 4df4ff7
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 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
3 changes: 2 additions & 1 deletion npm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
},
"scripts": {
"postinstall": "node install.js install",
"preuninstall": "node install.js uninstall"
"preuninstall": "node install.js uninstall",
"postversion": "git push && git push --tags"
},
"repository": {
"type": "git",
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 4df4ff7

Please sign in to comment.