Skip to content

Commit

Permalink
Merge pull request #41 from Clever/SECNG-177-create-secret-store-for-…
Browse files Browse the repository at this point in the history
…parameterstore

Create secret store based on parameterstore
  • Loading branch information
ulziibay authored Dec 8, 2020
2 parents f8a1ba0 + b2babec commit 1e15dd0
Show file tree
Hide file tree
Showing 9 changed files with 528 additions and 32 deletions.
56 changes: 48 additions & 8 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

[[constraint]]
name = "github.com/aws/aws-sdk-go"
version = "1.13.0"
version = "1.34.0"

[[constraint]]
name = "github.com/stretchr/testify"
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ func main() {
func getEnvironment(environment string) store.Environment {
if environment == "development" {
return store.DevelopmentEnvironment
} else if environment == "ci-test" {
return store.CITestEnvironment
} else if environment != "production" {
log.Fatal("Environment flag must be 'development' or 'production'")
}
Expand Down
6 changes: 5 additions & 1 deletion store/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ type SecretStore interface {
// Creates a Secret in the secret store. Version is guaranteed to be zero if no error is returned.
Create(id SecretIdentifier, value string) error

// Read a Secret from the store. Returns the lastest version of the secret.
// Read a Secret from the store. Returns the latest version of the secret.
Read(id SecretIdentifier) (Secret, error)

// ReadVersion reads a specific version of a secret from the store.
Expand All @@ -129,9 +129,13 @@ type SecretStore interface {
// IdentifierNotFoundError occurs when a secret identifier cannot be found (during Read, History, Update)
type IdentifierNotFoundError struct {
Identifier SecretIdentifier
Region string
}

func (e *IdentifierNotFoundError) Error() string {
if e.Region != "" {
return fmt.Sprintf("Identifier not found in region(%s): %s", e.Region, e.Identifier)
}
return fmt.Sprintf("Identifier not found: %s", e.Identifier)
}

Expand Down
10 changes: 5 additions & 5 deletions store/memory_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (s *MemoryStore) Read(id SecretIdentifier) (Secret, error) {
if history, ok := s.history[id]; ok {
return history.Secrets[len(history.Secrets)-1], nil
}
return Secret{}, &IdentifierNotFoundError{Identifier: id}
return Secret{}, &IdentifierNotFoundError{Identifier: id, Region: ""}
}

// ReadVersion reads a version of a secret
Expand All @@ -53,7 +53,7 @@ func (s *MemoryStore) ReadVersion(id SecretIdentifier, version int) (Secret, err
}
return Secret{}, &VersionNotFoundError{Version: version, Identifier: id}
}
return Secret{}, &IdentifierNotFoundError{Identifier: id}
return Secret{}, &IdentifierNotFoundError{Identifier: id, Region: ""}
}

// Update updates a secret in the secret store
Expand All @@ -65,7 +65,7 @@ func (s *MemoryStore) Update(id SecretIdentifier, value string) (Secret, error)

// Return error if secret does not exist
if history, ok = s.history[id]; !ok {
return Secret{}, &IdentifierNotFoundError{Identifier: id}
return Secret{}, &IdentifierNotFoundError{Identifier: id, Region: ""}
}

// Append newest version
Expand Down Expand Up @@ -117,7 +117,7 @@ func (s *MemoryStore) History(id SecretIdentifier) ([]SecretMeta, error) {
}
return secrets, nil
}
return []SecretMeta{}, &IdentifierNotFoundError{Identifier: id}
return []SecretMeta{}, &IdentifierNotFoundError{Identifier: id, Region: ""}
}

// Delete deletes all versions of a secret
Expand All @@ -126,7 +126,7 @@ func (s *MemoryStore) Delete(id SecretIdentifier) error {
delete(s.history, id)
return nil
}
return &IdentifierNotFoundError{Identifier: id}
return &IdentifierNotFoundError{Identifier: id, Region: ""}
}

// NewMemoryStore creates an in-memory secret store
Expand Down
Loading

0 comments on commit 1e15dd0

Please # to comment.