forked from rancher/rancher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
store.go
36 lines (32 loc) · 899 Bytes
/
store.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
package setting
import (
"os"
"github.com/rancher/norman/store/transform"
"github.com/rancher/norman/types"
"github.com/rancher/norman/types/convert"
"github.com/rancher/rancher/pkg/settings"
)
func New(store types.Store) types.Store {
return &transform.Store{
Store: store,
Transformer: func(apiContext *types.APIContext, schema *types.Schema, data map[string]interface{}, opt *types.QueryOptions) (map[string]interface{}, error) {
v, ok := data["value"]
id := convert.ToString(data["id"])
value, ok2 := os.LookupEnv(settings.GetEnvKey(id))
switch {
case ok2:
data["value"] = value
data["customized"] = false
data["source"] = "env"
case !ok || v == "":
data["value"] = data["default"]
data["customized"] = false
data["source"] = "default"
default:
data["customized"] = true
data["source"] = "db"
}
return data, nil
},
}
}