forked from cloudfoundry/go-cfclient
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenvironmentvariablegroups.go
59 lines (47 loc) · 1.49 KB
/
environmentvariablegroups.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
package cfclient
import (
"bytes"
"encoding/json"
"fmt"
)
type EnvironmentVariableGroup map[string]interface{}
func (c *Client) GetRunningEnvironmentVariableGroup() (EnvironmentVariableGroup, error) {
return c.getEnvironmentVariableGroup(true)
}
func (c *Client) GetStagingEnvironmentVariableGroup() (EnvironmentVariableGroup, error) {
return c.getEnvironmentVariableGroup(false)
}
func (c *Client) getEnvironmentVariableGroup(running bool) (EnvironmentVariableGroup, error) {
evgType := "staging"
if running {
evgType = "running"
}
req := c.NewRequest("GET", fmt.Sprintf("/v2/config/environment_variable_groups/%s", evgType))
resp, err := c.DoRequest(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
evg := EnvironmentVariableGroup{}
err = json.NewDecoder(resp.Body).Decode(&evg)
return evg, err
}
func (c *Client) SetRunningEnvironmentVariableGroup(evg EnvironmentVariableGroup) error {
return c.setEnvironmentVariableGroup(evg, true)
}
func (c *Client) SetStagingEnvironmentVariableGroup(evg EnvironmentVariableGroup) error {
return c.setEnvironmentVariableGroup(evg, false)
}
func (c *Client) setEnvironmentVariableGroup(evg EnvironmentVariableGroup, running bool) error {
evgType := "staging"
if running {
evgType = "running"
}
marshalled, err := json.Marshal(evg)
if err != nil {
return err
}
req := c.NewRequestWithBody("PUT", fmt.Sprintf("/v2/config/environment_variable_groups/%s", evgType), bytes.NewBuffer(marshalled))
_, err = c.DoRequest(req)
return err
}