grafana/pkg/services/secrets/fakes/fake_service.go
Joan López de la Franca Beltran b2655750e8
Encryption: Add support for data keys re-encryption (#43548)
* Encryption: Add support for data keys re-encryption

* Add tests for data keys re-encryption

* Update code after refactorings

Co-authored-by: Leonard Gram <leo@xlson.com>
2022-02-03 09:15:38 +01:00

56 lines
1.5 KiB
Go

package fakes
import (
"context"
"github.com/grafana/grafana/pkg/services/secrets"
)
type FakeSecretsService struct{}
func NewFakeSecretsService() FakeSecretsService {
return FakeSecretsService{}
}
func (f FakeSecretsService) Encrypt(_ context.Context, payload []byte, _ secrets.EncryptionOptions) ([]byte, error) {
return payload, nil
}
func (f FakeSecretsService) Decrypt(_ context.Context, payload []byte) ([]byte, error) {
return payload, nil
}
func (f FakeSecretsService) EncryptJsonData(_ context.Context, kv map[string]string, _ secrets.EncryptionOptions) (map[string][]byte, error) {
result := make(map[string][]byte, len(kv))
for key, value := range kv {
result[key] = []byte(value)
}
return result, nil
}
func (f FakeSecretsService) DecryptJsonData(_ context.Context, sjd map[string][]byte) (map[string]string, error) {
result := make(map[string]string, len(sjd))
for key, value := range sjd {
result[key] = string(value)
}
return result, nil
}
func (f FakeSecretsService) GetDecryptedValue(_ context.Context, sjd map[string][]byte, key, fallback string) string {
if value, ok := sjd[key]; ok {
return string(value)
}
return fallback
}
func (f FakeSecretsService) ReEncryptDataKeys(_ context.Context) error {
return nil
}
func (f FakeSecretsService) CurrentProviderID() string {
return "fakeProvider"
}
func (f FakeSecretsService) GetProviders() map[string]secrets.Provider {
return make(map[string]secrets.Provider)
}
func (f FakeSecretsService) RegisterProvider(_ string, _ secrets.Provider) {}