Skip to content

Commit

Permalink
make accountid a string. start adding config validation. Fixes #1
Browse files Browse the repository at this point in the history
  • Loading branch information
acobaugh committed Sep 13, 2021
1 parent a6fcc4d commit fc5c81f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
5 changes: 5 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ func init() {
if err != nil {
log.Fatalf("Failed to load config: %s", err)
}

err = c.Validate()
if err != nil {
log.Fatalf("Failed to validate config: %s", err)
}
}

// Execute executes this command
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/apex/log v1.9.0
github.com/aws/aws-sdk-go-v2/config v1.6.0
github.com/go-ini/ini v1.62.0
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/heetch/confita v0.10.0
github.com/sirupsen/logrus v1.4.2 // indirect
github.com/spf13/cobra v1.2.1
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ github.com/grpc-ecosystem/grpc-gateway v1.8.6/go.mod h1:vNeuVxBJEsws4ogUvrchl83t
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q=
github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8=
github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
Expand All @@ -214,6 +215,8 @@ github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjh
github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM=
github.com/hashicorp/go-msgpack v0.5.5/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM=
github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk=
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
github.com/hashicorp/go-plugin v1.0.1/go.mod h1:++UyYGoz3o5w9ZzAdZxtQKrWWP+iqPBn3cQptSMzBuY=
github.com/hashicorp/go-retryablehttp v0.5.3/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs=
github.com/hashicorp/go-retryablehttp v0.5.4/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs=
Expand Down
12 changes: 9 additions & 3 deletions pkg/cfg/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import (
"fmt"
"log"
"os"
"strconv"

"github.com/PennState/sso2aws/pkg/envcfg"
"github.com/hashicorp/go-multierror"
"github.com/heetch/confita"
"github.com/heetch/confita/backend/file"
)
Expand All @@ -20,7 +22,7 @@ type Cfg struct {
type SSOConfig struct {
SSOStartURL string `config:"sso_start_url" ini:"sso_start_url"`
SSORegion string `config:"sso_region" ini:"sso_region"`
SSOAccountID int `config:"sso_account_id" ini:"sso_account_id"`
SSOAccountID string `config:"sso_account_id" ini:"sso_account_id"`
SSORoleName string `config:"sso_role_name" ini:"sso_role_name"`
Region string `config:"region" ini:"region"`
Output string `config:"output" ini:"output"`
Expand Down Expand Up @@ -78,7 +80,11 @@ func defaultConfigFile() string {
}

func (cfg *Cfg) Validate() error {
// check required keys
var errors error

return nil
if _, err := strconv.Atoi(cfg.SSOConfig.SSOAccountID); err != nil {
errors = multierror.Append(errors, fmt.Errorf("SSOAccountID is not a number (%s): %s", cfg.SSOConfig.SSOAccountID, err))
}

return errors
}

0 comments on commit fc5c81f

Please sign in to comment.