-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsecrets.go
77 lines (58 loc) · 1.68 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
70
71
72
73
74
75
76
77
package symbiosis
import (
"fmt"
)
type SecretService interface {
Create(project string, secretKey string, input Secret) error
GetSecretsByProject(project string) (SecretCollection, error)
GetSecretsByProjectAndEnvironment(project string, environment ProjectEnvironment) (map[string]string, error)
}
type ProjectEnvironment string
const (
ENVIRONMENT_DEVELOPMENT ProjectEnvironment = "development"
ENVIRONMENT_PREVIEW ProjectEnvironment = "preview"
ENVIRONMENT_PRODUCTION ProjectEnvironment = "production"
)
type Secret struct {
DevelopmentValue string `json:"developmentValue"`
PreviewValue string `json:"previewValue"`
ProductionValue string `json:"productionValue"`
}
type SecretCollection map[string]*Secret
type SecretServiceClient struct {
client *Client
}
func (n *SecretServiceClient) Create(project string, secretKey string, input Secret) error {
err := n.client.Call(
fmt.Sprintf("/rest/v1/project/%s/secret/%s", project, secretKey),
"Put",
nil,
WithBody(input),
)
if err != nil {
return err
}
return nil
}
func (n *SecretServiceClient) GetSecretsByProject(project string) (SecretCollection, error) {
var secrets *SecretCollection
err := n.client.
Call(fmt.Sprintf("/rest/v1/project/%s/secret", project),
"Get",
&secrets)
if err != nil {
return nil, err
}
return *secrets, nil
}
func (n *SecretServiceClient) GetSecretsByProjectAndEnvironment(project string, environment ProjectEnvironment) (map[string]string, error) {
var secrets *map[string]string
err := n.client.
Call(fmt.Sprintf("/rest/v1/project/%s/secret?environment=%s", project, environment),
"Get",
&secrets)
if err != nil {
return nil, err
}
return *secrets, nil
}