Skip to content

Commit 58c09bd

Browse files
committed
feat(config): add typed_values
1 parent 10d3dbb commit 58c09bd

4 files changed

Lines changed: 41 additions & 13 deletions

File tree

api/config.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,19 @@ import (
66
"text/template"
77
)
88

9+
// ConfigValues is the key, value for env
10+
type ConfigValues map[string]interface{}
11+
912
// ConfigSet is the definition of POST /v2/apps/<app id>/config/.
1013
type ConfigSet struct {
11-
Values map[string]string `json:"values"`
14+
Values ConfigValues `json:"values"`
15+
TypedValues map[string]ConfigValues `json:"typed_values"`
1216
}
1317

1418
// ConfigUnset is the definition of POST /v2/apps/<app id>/config/.
1519
type ConfigUnset struct {
16-
Values map[string]interface{} `json:"values"`
20+
Values ConfigValues `json:"values"`
21+
TypedValues map[string]ConfigValues `json:"typed_values"`
1722
}
1823

1924
// Config is the structure of an app's config.
@@ -23,7 +28,9 @@ type Config struct {
2328
// App is the app name. It cannot be updated at all right now.
2429
App string `json:"app,omitempty"`
2530
// Values are exposed as environment variables to the app.
26-
Values map[string]interface{} `json:"values,omitempty"`
31+
Values ConfigValues `json:"values,omitempty"`
32+
// Typed values are exposed as environment variables to the app.
33+
TypedValues map[string]ConfigValues `json:"typed_values,omitempty"`
2734
// Limits is used to set process resources limits. The key is the process name
2835
// and the value is a limit plan. Ex: std1.xlarge.c1m1
2936
Limits map[string]interface{} `json:"limits,omitempty"`

config/config_test.go

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ const configFixture string = `
2020
"TEST": "testing",
2121
"FOO": "bar"
2222
},
23+
"typed_values": {
24+
"web": {
25+
"PORT": "9000"
26+
}
27+
},
2328
"limits": {
2429
"web": "std1.xlarge.c1m1"
2530
},
@@ -40,6 +45,7 @@ const configUnsetFixture string = `
4045
"owner": "test",
4146
"app": "unset-test",
4247
"values": {},
48+
"typed_values": {"web":{"PORT":null}},
4349
"limits": {},
4450
"tags": {},
4551
"registry": {},
@@ -49,8 +55,8 @@ const configUnsetFixture string = `
4955
}
5056
`
5157

52-
const configSetExpected string = `{"values":{"FOO":"bar","TEST":"testing"},"limits":{"web":"std1.xlarge.c1m1"},"tags":{"test":"tests"},"registry":{"username":"bob"}}`
53-
const configUnsetExpected string = `{"values":{"FOO":null,"TEST":null},"limits":{"web":null},"tags":{"test":null},"registry":{"username":null}}`
58+
const configSetExpected string = `{"values":{"FOO":"bar","TEST":"testing"},"typed_values":{"web":{"PORT":"9000"}},"limits":{"web":"std1.xlarge.c1m1"},"tags":{"test":"tests"},"registry":{"username":"bob"}}`
59+
const configUnsetExpected string = `{"values":{"FOO":null,"TEST":null},"typed_values":{"web":{"PORT":null}},"limits":{"web":null},"tags":{"test":null},"registry":{"username":null}}`
5460

5561
type fakeHTTPServer struct{}
5662

@@ -124,10 +130,13 @@ func TestConfigSet(t *testing.T) {
124130
expected := api.Config{
125131
Owner: "test",
126132
App: "example-go",
127-
Values: map[string]interface{}{
133+
Values: api.ConfigValues{
128134
"TEST": "testing",
129135
"FOO": "bar",
130136
},
137+
TypedValues: map[string]api.ConfigValues{
138+
"web": {"PORT": "9000"},
139+
},
131140
Limits: map[string]interface{}{
132141
"web": "std1.xlarge.c1m1",
133142
},
@@ -143,10 +152,13 @@ func TestConfigSet(t *testing.T) {
143152
}
144153

145154
configVars := api.Config{
146-
Values: map[string]interface{}{
155+
Values: api.ConfigValues{
147156
"TEST": "testing",
148157
"FOO": "bar",
149158
},
159+
TypedValues: map[string]api.ConfigValues{
160+
"web": {"PORT": "9000"},
161+
},
150162
Limits: map[string]interface{}{
151163
"web": "std1.xlarge.c1m1",
152164
},
@@ -182,9 +194,12 @@ func TestConfigUnset(t *testing.T) {
182194
}
183195

184196
expected := api.Config{
185-
Owner: "test",
186-
App: "unset-test",
187-
Values: map[string]interface{}{},
197+
Owner: "test",
198+
App: "unset-test",
199+
Values: map[string]interface{}{},
200+
TypedValues: map[string]api.ConfigValues{
201+
"web": {"PORT": nil},
202+
},
188203
Limits: map[string]interface{}{},
189204
Tags: map[string]interface{}{},
190205
Registry: map[string]interface{}{},
@@ -198,6 +213,9 @@ func TestConfigUnset(t *testing.T) {
198213
"TEST": nil,
199214
"FOO": nil,
200215
},
216+
TypedValues: map[string]api.ConfigValues{
217+
"web": {"PORT": nil},
218+
},
201219
Limits: map[string]interface{}{
202220
"web": nil,
203221
},
@@ -239,6 +257,9 @@ func TestConfigList(t *testing.T) {
239257
"TEST": "testing",
240258
"FOO": "bar",
241259
},
260+
TypedValues: map[string]api.ConfigValues{
261+
"web": {"PORT": "9000"},
262+
},
242263
Limits: map[string]interface{}{
243264
"web": "std1.xlarge.c1m1",
244265
},

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.22
44

55
require (
66
github.com/stretchr/testify v1.9.0
7-
golang.org/x/net v0.21.0
7+
golang.org/x/net v0.23.0
88
)
99

1010
require (

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
44
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
55
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
66
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
7-
golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
8-
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
7+
golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
8+
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
99
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
1010
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
1111
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

0 commit comments

Comments
 (0)