forked from taskcluster/taskcluster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsecrets.go
69 lines (60 loc) · 1.55 KB
/
secrets.go
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
62
63
64
65
66
67
68
69
package mocktc
import (
"fmt"
"github.com/taskcluster/httpbackoff/v3"
tcclient "github.com/taskcluster/taskcluster/v47/clients/client-go"
"github.com/taskcluster/taskcluster/v47/clients/client-go/tcsecrets"
)
type Secrets struct {
// map from secret name to secret value
Secrets map[string]*tcsecrets.Secret
}
func NewSecrets() *Secrets {
return &Secrets{
Secrets: map[string]*tcsecrets.Secret{},
}
}
func (s *Secrets) Ping() error {
// nothing to do
return nil
}
func (s *Secrets) List(continuationToken, limit string) (*tcsecrets.SecretsList, error) {
names := []string{}
for name := range s.Secrets {
names = append(names, name)
}
return &tcsecrets.SecretsList{
Secrets: names,
}, nil
}
func (s *Secrets) Get(name string) (*tcsecrets.Secret, error) {
if sec, exists := s.Secrets[name]; exists {
return sec, nil
}
return nil, &tcclient.APICallException{
CallSummary: &tcclient.CallSummary{
HTTPResponseBody: fmt.Sprintf("Secret %v not found - cannot return value", name),
},
RootCause: httpbackoff.BadHttpResponseCode{
HttpResponseCode: 404,
},
}
}
func (s *Secrets) Set(name string, payload *tcsecrets.Secret) error {
s.Secrets[name] = payload
return nil
}
func (s *Secrets) Remove(name string) error {
if _, exists := s.Secrets[name]; exists {
delete(s.Secrets, name)
return nil
}
return &tcclient.APICallException{
CallSummary: &tcclient.CallSummary{
HTTPResponseBody: fmt.Sprintf("Secret %v not found - cannot remove", name),
},
RootCause: httpbackoff.BadHttpResponseCode{
HttpResponseCode: 404,
},
}
}