Skip to content

Commit

Permalink
Validate the configurations even when syncing
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien Duchesne committed Jun 24, 2019
1 parent f5f1f6f commit 0df0ce8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
7 changes: 7 additions & 0 deletions cli/sync.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
package cli

import (
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

var syncCmd = &cobra.Command{
Use: "sync",
Short: "Fetches credentials and syncs them to targets",
Run: func(cmd *cobra.Command, args []string) {
if !configuration.Sources.ValidateConfiguration() {
log.Fatal("The sources section of the config file is invalid")
}
if !configuration.Targets.ValidateConfiguration() {
log.Fatal("The targets section of the config file is invalid")
}
configuration.Sync()
},
}
11 changes: 10 additions & 1 deletion credentials/source_s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
log "github.com/sirupsen/logrus"
)

type AWSS3Source struct {
Expand Down Expand Up @@ -39,5 +40,13 @@ func (source *AWSS3Source) Type() string {
}

func (source *AWSS3Source) ValidateConfiguration() bool {
return len(source.Bucket) > 0 && len(source.Key) > 0
if source.Bucket == "" {
log.Errorf("S3 sources must define a bucket")
return false
}
if source.Key == "" {
log.Errorf("S3 sources must define a key")
return false
}
return true
}
9 changes: 6 additions & 3 deletions credentials/source_secretsmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/aws/aws-sdk-go/aws/credentials/stscreds"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/secretsmanager"
log "github.com/sirupsen/logrus"
)

type AWSSecretsManagerSource struct {
Expand Down Expand Up @@ -41,8 +42,6 @@ func (source *AWSSecretsManagerSource) Credentials() ([]Credentials, error) {
}
} else if source.SecretID != "" {
secretIDs = append(secretIDs, source.SecretID)
} else {
return nil, fmt.Errorf("Either `secret_id` or `secret_prefix` must be defined")
}

credentials := []Credentials{}
Expand All @@ -68,5 +67,9 @@ func (source *AWSSecretsManagerSource) Type() string {
}

func (source *AWSSecretsManagerSource) ValidateConfiguration() bool {
return len(source.SecretID) > 0
if source.SecretID == "" && source.SecretPrefix == "" {
log.Error("Either `secret_id` or `secret_prefix` must be defined on a secretsmanager source")
return false
}
return true
}

0 comments on commit 0df0ce8

Please sign in to comment.