Skip to content

Commit

Permalink
Merge pull request #46 from Clever/fix-list
Browse files Browse the repository at this point in the history
Skip current-deploy parameters
  • Loading branch information
ulziibay committed Jan 6, 2021
2 parents 36e4eb9 + b24b1c5 commit 79e4ebc
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.1
0.1.2
11 changes: 10 additions & 1 deletion store/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func stringToSecretIdentifier(s string) (SecretIdentifier, error) {
}
env, err := environmentStringToInt(parts[0])
if err != nil {
return SecretIdentifier{}, fmt.Errorf("unable to create SecretIdentifier from string -- invalid environment: %s", s)
return SecretIdentifier{}, &InvalidEnvironmentError{Identifier: s}
}
return SecretIdentifier{env, parts[1], parts[2]}, nil
}
Expand Down Expand Up @@ -148,6 +148,15 @@ func (e *InvalidIdentifierError) Error() string {
return fmt.Sprintf("The given identifier is invalid: %s", e.Identifier)
}

// InvalidEnvironmentError occurs when a parameter name is using non-compatible environment name
type InvalidEnvironmentError struct {
Identifier string
}

func (e *InvalidEnvironmentError) Error() string {
return fmt.Sprintf("environment is not compatible. supplied %s, expects `production`, `development`, or `ci-test`.", e.Identifier)
}

// IdentifierAlreadyExistsError occurs when Create is called and an identifier already exists
type IdentifierAlreadyExistsError struct {
Identifier SecretIdentifier
Expand Down
21 changes: 19 additions & 2 deletions store/parameter_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ func init() {
Region = region
}

// CurrentDeployError occurs when a parameter name has suffix current-deploy.
// Such parameters are private to catapult service and should not be surfaced via interface
type CurrentDeployError struct {
Identifier string
}

func (e *CurrentDeployError) Error() string {
return fmt.Sprintf("current-deploy parameter should not be surfaced for parameter %s", e.Identifier)
}

// getOrderedRegions provides guarantees that actions on ParamStore will happen
// within a specific order every time. This is helpful for any errors with inconsistent
// state
Expand Down Expand Up @@ -55,7 +65,10 @@ func getSecretIDFromParamName(name string) (SecretIdentifier, error) {
parts := strings.Split(name, "/")
env, err := environmentStringToInt(parts[1])
if err != nil {
return SecretIdentifier{}, err
return SecretIdentifier{}, &InvalidEnvironmentError{Identifier: name}
}
if strings.HasSuffix(name, "current-deploy") {
return SecretIdentifier{}, &CurrentDeployError{Identifier: name}
}
return SecretIdentifier{Environment: env, Service: parts[2], Key: parts[3]}, nil
}
Expand Down Expand Up @@ -292,7 +305,11 @@ func (s *ParameterStore) List(env Environment, service string) ([]SecretIdentifi
return []SecretIdentifier{}, err
}
for _, result := range resp.Parameters {
ident, _ := getSecretIDFromParamName(*result.Name)
ident, err := getSecretIDFromParamName(*result.Name)
if _, ok := err.(*CurrentDeployError); ok {
// secrets that fail with CurrentDeployError are intended to be read by machines, and not returned for human consumption.
continue
}
resultsPerTry = append(resultsPerTry, ident)
}
if resp.NextToken != nil && *resp.NextToken != "" {
Expand Down

0 comments on commit 79e4ebc

Please sign in to comment.