This repository was archived by the owner on Jul 5, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathbackend.go
More file actions
61 lines (48 loc) · 1.46 KB
/
backend.go
File metadata and controls
61 lines (48 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Package dummy implements an example backend that can be used for testing
// purposes. It acceps a "suffix" as a parameter that will be appended to the
// key passed to the Get function.
package dummy
import (
"fmt"
"github.com/containersolutions/externalsecret-operator/pkg/backend"
ctrl "sigs.k8s.io/controller-runtime"
)
var log = ctrl.Log.WithName("dummy")
// Backend is a fake secrets backend for testing purposes
type Backend struct {
suffix string
}
func init() {
backend.Register("dummy", NewBackend)
}
// NewBackend gives you an NewBackend Dummy Backend
func NewBackend() backend.Backend {
return &Backend{}
}
// Init implements SecretsBackend interface, sets the suffix
func (d *Backend) Init(parameters map[string]interface{}, credentials []byte) error {
if len(parameters) == 0 {
log.Error(fmt.Errorf("error"), "empty or invalid parameters: ")
return fmt.Errorf("empty or invalid parameters")
}
suffix, ok := parameters["Suffix"].(string)
if !ok {
log.Error(fmt.Errorf("error"), "missing parameters: ")
return fmt.Errorf("missing parameters")
}
d.suffix = suffix
return nil
}
// Get a key and returns a fake secrets key + suffix
func (d *Backend) Get(key string, version string) (string, error) {
if d.suffix == "" {
return "", fmt.Errorf("backend is not initialized")
}
if key == "" {
return "", fmt.Errorf("empty key provided")
}
if key == "ErroredKey" {
return "", fmt.Errorf("Mocked error")
}
return key + version + d.suffix, nil
}