-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconfig.go
More file actions
85 lines (70 loc) · 2.19 KB
/
config.go
File metadata and controls
85 lines (70 loc) · 2.19 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Package config provides methods for managing configuration of apps.
package config
import (
"encoding/json"
"fmt"
drycc "github.com/drycc/controller-sdk-go"
"github.com/drycc/controller-sdk-go/api"
)
// List lists an app's config.
func List(c *drycc.Client, app string, version int) (api.Config, error) {
u := fmt.Sprintf("/v2/apps/%s/config/", app)
if version > 0 {
u = fmt.Sprintf("%s?version=v%d", u, version)
}
res, reqErr := c.Request("GET", u, nil)
if reqErr != nil {
return api.Config{}, reqErr
}
defer res.Body.Close()
config := api.Config{}
if err := json.NewDecoder(res.Body).Decode(&config); err != nil {
return api.Config{}, err
}
return config, reqErr
}
// Set sets an app's config variables and creates a new release.
// This is a patching operation, which means when you call Set() with an api.Config:
//
// - If the variable does not exist, it will be set.
// - If the variable exists, it will be overwritten.
// - If the variable is set to nil, it will be unset.
// - If the variable was ignored in the api.Config, it will remain unchanged.
//
// Calling Set() with an empty api.Config will return a drycc.ErrConflict.
// Trying to unset a key that does not exist returns a drycc.ErrUnprocessable.
// Trying to set a tag that is not a label in the kubernetes cluster will return a drycc.ErrTagNotFound.
func Set(c *drycc.Client, app string, config api.Config, merge bool) (api.Config, error) {
body, err := json.Marshal(config)
if err != nil {
return api.Config{}, err
}
u := fmt.Sprintf("/v2/apps/%s/config/", app)
if merge {
u += "?merge=true"
}
res, reqErr := c.Request("POST", u, body)
if reqErr != nil {
return api.Config{}, reqErr
}
defer res.Body.Close()
newConfig := api.Config{}
if err = json.NewDecoder(res.Body).Decode(&newConfig); err != nil {
return api.Config{}, err
}
return newConfig, reqErr
}
// Detach config groups from app ptype.
func Detach(c *drycc.Client, app string, config api.Config) error {
body, err := json.Marshal(config)
if err != nil {
return err
}
u := fmt.Sprintf("/v2/apps/%s/config/", app)
res, reqErr := c.Request("DELETE", u, body)
if reqErr != nil {
return reqErr
}
defer res.Body.Close()
return reqErr
}