Skip to content

Commit f1d6fea

Browse files
authored
feat(controller-sdk-go): config add ValuesRefs field (#41)
1 parent 441681c commit f1d6fea

8 files changed

Lines changed: 338 additions & 92 deletions

File tree

api/config.go

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,39 @@ import (
99
// ConfigTags is the key, value for tag
1010
type ConfigTags map[string]interface{}
1111

12-
// ConfigValues is the key, value for env
13-
type ConfigValues map[string]interface{}
12+
// ConfigValues value for env
13+
type KV struct {
14+
Name string `json:"name,omitempty"`
15+
Value interface{} `json:"value,omitempty"`
16+
}
17+
18+
type ConfigValue struct {
19+
Ptype string `json:"ptype,omitempty"`
20+
Group string `json:"group,omitempty"`
21+
KV
22+
}
23+
24+
type PtypeValue struct {
25+
Env []KV `json:"env,omitempty"`
26+
Ref []string `json:"ref,omitempty"`
27+
}
28+
29+
type ConfigInfo struct {
30+
Ptype map[string]PtypeValue `json:"ptype,omitempty"`
31+
Group map[string][]KV `json:"group,omitempty"`
32+
}
33+
34+
// ValuesRefs is the key, value for refs
35+
type ValuesRefs map[string][]string
1436

1537
// ConfigSet is the definition of POST /v2/apps/<app id>/config/.
1638
type ConfigSet struct {
17-
Values ConfigValues `json:"values"`
18-
TypedValues map[string]ConfigValues `json:"typed_values"`
39+
Values []ConfigValue `json:"values"`
1940
}
2041

2142
// ConfigUnset is the definition of POST /v2/apps/<app id>/config/.
2243
type ConfigUnset struct {
23-
Values ConfigValues `json:"values"`
24-
TypedValues map[string]ConfigValues `json:"typed_values"`
44+
Values []ConfigValue `json:"values"`
2545
}
2646

2747
// Config is the structure of an app's config.
@@ -31,9 +51,9 @@ type Config struct {
3151
// App is the app name. It cannot be updated at all right now.
3252
App string `json:"app,omitempty"`
3353
// Values are exposed as environment variables to the app.
34-
Values ConfigValues `json:"values,omitempty"`
54+
Values []ConfigValue `json:"values,omitempty"`
3555
// Typed values are exposed as environment variables to the app.
36-
TypedValues map[string]ConfigValues `json:"typed_values,omitempty"`
56+
ValuesRefs ValuesRefs `json:"values_refs,omitempty"`
3757
// Limits is used to set process resources limits. The key is the process name
3858
// and the value is a limit plan. Ex: std1.xlarge.c1m1
3959
Limits map[string]interface{} `json:"limits,omitempty"`
@@ -46,7 +66,7 @@ type Config struct {
4666
Tags map[string]ConfigTags `json:"tags,omitempty"`
4767
// Registry is a key-value pair to provide authentication for container registries.
4868
// The key is the username and the value is the password.
49-
Registry map[string]interface{} `json:"registry,omitempty"`
69+
Registry map[string]map[string]interface{} `json:"registry,omitempty"`
5070
// Created is the time that the application was created and cannot be updated.
5171
Created string `json:"created,omitempty"`
5272
// Updated is the last time the configuration was changed and cannot be updated.

api/pts.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ type Ptype struct {
88
UpToDate int `json:"up_to_date"`
99
AvailableReplicas int `json:"available_replicas"`
1010
Started string `json:"started"`
11+
Garbage bool `json:"garbage"`
1112
}
1213

1314
// Ptypes defines a collection of app Ptypes.

api/pts_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import (
77

88
func TestPtypesSorted(t *testing.T) {
99
ptypes := Ptypes{
10-
{"web", "v1", "1/1", 1, 1, ""},
11-
{"cronjob", "v1", "1/1", 1, 1, ""},
12-
{"sleep", "v1", "1/1", 1, 1, ""},
10+
{"web", "v1", "1/1", 1, 1, "", false},
11+
{"cronjob", "v1", "1/1", 1, 1, "", false},
12+
{"sleep", "v1", "1/1", 1, 1, "", false},
1313
}
1414

1515
sort.Sort(ptypes)

config/config.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,22 @@ func Set(c *drycc.Client, app string, config api.Config) (api.Config, error) {
6363

6464
return newConfig, reqErr
6565
}
66+
67+
// Detach config groups from app ptype.
68+
func Detach(c *drycc.Client, app string, config api.Config) error {
69+
body, err := json.Marshal(config)
70+
71+
if err != nil {
72+
return err
73+
}
74+
75+
u := fmt.Sprintf("/v2/apps/%s/config/", app)
76+
77+
res, reqErr := c.Request("DELETE", u, body)
78+
if reqErr != nil {
79+
return reqErr
80+
}
81+
defer res.Body.Close()
82+
83+
return reqErr
84+
}

0 commit comments

Comments
 (0)