Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the service path support variable depths #70

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,13 @@ func list(cmd *cobra.Command, args []string) error {
}

func key(s string) string {
_, noPaths := os.LookupEnv("CHAMBER_NO_PATHS")
if !noPaths {
tokens := strings.Split(s, "/")
secretKey := tokens[2]
return secretKey
_, noPaths := os.LookupEnv("CHAMBER_NO_PATHS")
sep := "/"
if noPaths {
sep = "."
}

tokens := strings.Split(s, ".")
secretKey := tokens[1]
tokens := strings.Split(s, sep)
secretKey := tokens[len(tokens)-1]
return secretKey
}
4 changes: 2 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
// Regex's used to validate service and key names
var (
validKeyFormat = regexp.MustCompile(`^[A-Za-z0-9-_]+$`)
validServiceFormat = regexp.MustCompile(`^[A-Za-z0-9-_]+$`)
validServiceFormat = regexp.MustCompile(`^[A-Za-z0-9-_\/.]+$`)

numRetries int
chamberVersion string
Expand Down Expand Up @@ -51,7 +51,7 @@ func Execute(vers string) {

func validateService(service string) error {
if !validServiceFormat.MatchString(service) {
return fmt.Errorf("Failed to validate service name '%s'. Only alphanumeric, dashes, and underscores are allowed for service names", service)
return fmt.Errorf("Failed to validate service name '%s'. Only alphanumeric, dashes, forwardslases, fullstops and underscores are allowed for service names", service)
}
return nil
}
Expand Down
7 changes: 4 additions & 3 deletions store/ssmstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ const (

// validPathKeyFormat is the format that is expected for key names inside parameter store
// when using paths
var validPathKeyFormat = regexp.MustCompile(`^\/[A-Za-z0-9-_]+\/[A-Za-z0-9-_]+$`)
var validPathKeyFormat = regexp.MustCompile(`^\/[A-Za-z0-9-_/]+$`)

// validKeyFormat is the format that is expected for key names inside parameter store when
// not using paths
var validKeyFormat = regexp.MustCompile(`^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+$`)
var validKeyFormat = regexp.MustCompile(`^[A-Za-z0-9-_.]+$`)

// ensure SSMStore confirms to Store interface
var _ Store = &SSMStore{}
Expand Down Expand Up @@ -501,7 +501,8 @@ func basePath(key string) string {
if len(pathParts) == 1 {
return pathParts[0]
}
return "/" + pathParts[1]
end := len(pathParts) - 1
return strings.Join(pathParts[0:end], "/")
}

func parameterMetaToSecretMeta(p *ssm.ParameterMetadata) SecretMetadata {
Expand Down