-
Notifications
You must be signed in to change notification settings - Fork 2
/
api_keys.go
57 lines (49 loc) · 1.62 KB
/
api_keys.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
package flagsmithapi
import (
"fmt"
)
func (c *Client) GetServerSideEnvKeys(environmentKey string) ([]ServerSideEnvKey, error) {
url := fmt.Sprintf("%s/environments/%s/api-keys/", c.baseURL, environmentKey)
keys := []ServerSideEnvKey{}
resp, err := c.client.R().SetResult(&keys).Get(url)
if err != nil {
return nil, err
}
if !resp.IsSuccess() {
return nil, fmt.Errorf("flagsmithapi: Error fetching server side keys: %v", resp)
}
return keys, nil
}
func (c *Client) CreateServerSideEnvKey(environmentKey string, key *ServerSideEnvKey) error {
url := fmt.Sprintf("%s/environments/%s/api-keys/", c.baseURL, environmentKey)
resp, err := c.client.R().SetBody(key).SetResult(&key).Post(url)
if err != nil {
return err
}
if !resp.IsSuccess() {
return fmt.Errorf("flagsmithapi: Error creating server side environment key: %s", resp)
}
return nil
}
func (c *Client) UpdateServerSideEnvKey(environmentKey string, key *ServerSideEnvKey) error {
url := fmt.Sprintf("%s/environments/%s/api-keys/%d/", c.baseURL, environmentKey, key.ID)
resp, err := c.client.R().SetBody(key).SetResult(&key).Put(url)
if err != nil {
return nil
}
if !resp.IsSuccess() {
return fmt.Errorf("flagsmithapi: Error updating server side environment key: %s", resp)
}
return nil
}
func (c *Client) DeleteServerSideEnvKey(environmentKey string, keyID int64) error {
url := fmt.Sprintf("%s/environments/%s/api-keys/%d/", c.baseURL, environmentKey, keyID)
resp, err := c.client.R().Delete(url)
if err != nil {
return err
}
if !resp.IsSuccess() {
return fmt.Errorf("flagsmithapi: Error deleting server side environment key: %s", resp)
}
return nil
}