Skip to content

Commit

Permalink
Disallow empty keys when accessing secrets
Browse files Browse the repository at this point in the history
  • Loading branch information
konradreiche committed Oct 7, 2020
1 parent e2eeb5a commit d433484
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions secrets/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import (
// encoding in the secrets.json file.
var ErrInvalidEncoding = errors.New("secrets: invalid encoding, expected identity, base64 or empty")

// ErrEmptySecretKey is returned when the path for a secret is empty.
var ErrEmptySecretKey = errors.New("secrets: secret path cannot be empty")

// TooManyFieldsError is a type of errors could be returned by
// Document.Validate.
//
Expand Down
9 changes: 9 additions & 0 deletions secrets/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ type Secrets struct {

// GetSimpleSecret fetches a simple secret or error if the key is not present.
func (s *Secrets) GetSimpleSecret(path string) (SimpleSecret, error) {
if path == "" {
return SimpleSecret{}, ErrEmptySecretKey
}
secret, ok := s.simpleSecrets[path]
if !ok {
return secret, SecretNotFoundError(path)
Expand All @@ -48,6 +51,9 @@ func (s *Secrets) GetSimpleSecret(path string) (SimpleSecret, error) {

// GetVersionedSecret fetches a versioned secret or error if the key is not present.
func (s *Secrets) GetVersionedSecret(path string) (VersionedSecret, error) {
if path == "" {
return VersionedSecret{}, ErrEmptySecretKey
}
secret, ok := s.versionedSecrets[path]
if !ok {
return secret, SecretNotFoundError(path)
Expand All @@ -59,6 +65,9 @@ func (s *Secrets) GetVersionedSecret(path string) (VersionedSecret, error) {
// GetCredentialSecret fetches a credential secret or error if the key is not
// present.
func (s *Secrets) GetCredentialSecret(path string) (CredentialSecret, error) {
if path == "" {
return CredentialSecret{}, ErrEmptySecretKey
}
secret, ok := s.credentialSecrets[path]
if !ok {
return secret, SecretNotFoundError(path)
Expand Down

0 comments on commit d433484

Please sign in to comment.