influxdb/mock/secret_service.go

75 lines
3.0 KiB
Go
Raw Normal View History

feat(vault): add vault implementation of secret service test(platform): run testcontainer integration tests for nightly release Integration tests for the vault secret service using testcontiners should not run along with unit tests, however, they should run on some regular schedule. This commit introduces `make test-integration` which runs integration tests for vault using testcontainers. The command introduced relies on docker being available on the host it is executed on. chore(platform): make go modules tidy chore: try to fix go mod chore(platform): remove explicit logrus dependency chore(platform): run go mod tidy chore(platform): replace github.com/Sirupsen/logrus with github.com/sirupsen/logrus chore(platform): update docker dependency feat(vault): add vault implementation of secret service test(platform): run testcontainer integration tests for nightly release Integration tests for the vault secret service using testcontiners should not run along with unit tests, however, they should run on some regular schedule. This commit introduces `make test-integration` which runs integration tests for vault using testcontainers. The command introduced relies on docker being available on the host it is executed on. chore(platform): make go modules tidy chore: try to fix go mod chore(platform): run go mod tidy feat(vault): add vault implementation of secret service chore(platform): make go modules tidy feat(platform): add Put/Patch/Delete methods on secret service feat(vault): add Put/Patch/Delete methods on vault secret service feat(http): add http handler methods for secret service feat(bolt): add Put/Delete/Patch methods to bolt secret service feat(testing): add tests for Put/Patch/Delete methods in secret service feat(mock): add mock secret service feat(http): add tests for secrets endpoints feat(http): update swagger for secrets endpoints chore: run go mod tidy
2018-11-16 16:45:00 +00:00
package mock
import (
"context"
"fmt"
platform "github.com/influxdata/influxdb"
feat(vault): add vault implementation of secret service test(platform): run testcontainer integration tests for nightly release Integration tests for the vault secret service using testcontiners should not run along with unit tests, however, they should run on some regular schedule. This commit introduces `make test-integration` which runs integration tests for vault using testcontainers. The command introduced relies on docker being available on the host it is executed on. chore(platform): make go modules tidy chore: try to fix go mod chore(platform): remove explicit logrus dependency chore(platform): run go mod tidy chore(platform): replace github.com/Sirupsen/logrus with github.com/sirupsen/logrus chore(platform): update docker dependency feat(vault): add vault implementation of secret service test(platform): run testcontainer integration tests for nightly release Integration tests for the vault secret service using testcontiners should not run along with unit tests, however, they should run on some regular schedule. This commit introduces `make test-integration` which runs integration tests for vault using testcontainers. The command introduced relies on docker being available on the host it is executed on. chore(platform): make go modules tidy chore: try to fix go mod chore(platform): run go mod tidy feat(vault): add vault implementation of secret service chore(platform): make go modules tidy feat(platform): add Put/Patch/Delete methods on secret service feat(vault): add Put/Patch/Delete methods on vault secret service feat(http): add http handler methods for secret service feat(bolt): add Put/Delete/Patch methods to bolt secret service feat(testing): add tests for Put/Patch/Delete methods in secret service feat(mock): add mock secret service feat(http): add tests for secrets endpoints feat(http): update swagger for secrets endpoints chore: run go mod tidy
2018-11-16 16:45:00 +00:00
)
// SecretService is a mock implementation of a retention.SecretService, which
// also makes it a suitable mock to use wherever an platform.SecretService is required.
type SecretService struct {
LoadSecretFn func(ctx context.Context, orgID platform.ID, k string) (string, error)
GetSecretKeysFn func(ctx context.Context, orgID platform.ID) ([]string, error)
PutSecretFn func(ctx context.Context, orgID platform.ID, k string, v string) error
PutSecretsFn func(ctx context.Context, orgID platform.ID, m map[string]string) error
PatchSecretsFn func(ctx context.Context, orgID platform.ID, m map[string]string) error
DeleteSecretFn func(ctx context.Context, orgID platform.ID, ks ...string) error
}
// NewSecretService returns a mock SecretService where its methods will return
// zero values.
func NewSecretService() *SecretService {
return &SecretService{
LoadSecretFn: func(ctx context.Context, orgID platform.ID, k string) (string, error) {
return "", fmt.Errorf("not implmemented")
},
GetSecretKeysFn: func(ctx context.Context, orgID platform.ID) ([]string, error) {
return nil, fmt.Errorf("not implmemented")
},
PutSecretFn: func(ctx context.Context, orgID platform.ID, k string, v string) error {
return fmt.Errorf("not implmemented")
},
PutSecretsFn: func(ctx context.Context, orgID platform.ID, m map[string]string) error {
return fmt.Errorf("not implmemented")
},
PatchSecretsFn: func(ctx context.Context, orgID platform.ID, m map[string]string) error {
return fmt.Errorf("not implmemented")
},
DeleteSecretFn: func(ctx context.Context, orgID platform.ID, ks ...string) error {
return fmt.Errorf("not implmemented")
},
}
}
// LoadSecret retrieves the secret value v found at key k for organization orgID.
func (s *SecretService) LoadSecret(ctx context.Context, orgID platform.ID, k string) (string, error) {
return s.LoadSecretFn(ctx, orgID, k)
}
// GetSecretKeys retrieves all secret keys that are stored for the organization orgID.
func (s *SecretService) GetSecretKeys(ctx context.Context, orgID platform.ID) ([]string, error) {
return s.GetSecretKeysFn(ctx, orgID)
}
// PutSecret stores the secret pair (k,v) for the organization orgID.
func (s *SecretService) PutSecret(ctx context.Context, orgID platform.ID, k string, v string) error {
return s.PutSecretFn(ctx, orgID, k, v)
}
// PutSecrets puts all provided secrets and overwrites any previous values.
func (s *SecretService) PutSecrets(ctx context.Context, orgID platform.ID, m map[string]string) error {
return s.PutSecretsFn(ctx, orgID, m)
}
// PatchSecrets patches all provided secrets and updates any previous values.
func (s *SecretService) PatchSecrets(ctx context.Context, orgID platform.ID, m map[string]string) error {
return s.PatchSecretsFn(ctx, orgID, m)
}
// DeleteSecret removes a single secret from the secret store.
func (s *SecretService) DeleteSecret(ctx context.Context, orgID platform.ID, ks ...string) error {
return s.DeleteSecretFn(ctx, orgID, ks...)
}