36 Star 396 Fork 71

GVPrancher / rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
store.go 1.43 KB
一键复制 编辑 原始数据 按行查看 历史
package setting
import (
"fmt"
"os"
"github.com/rancher/norman/httperror"
"github.com/rancher/norman/store/transform"
"github.com/rancher/norman/types"
"github.com/rancher/norman/types/convert"
"github.com/rancher/norman/types/slice"
"github.com/rancher/rancher/pkg/api/customization/setting"
"github.com/rancher/rancher/pkg/settings"
)
type Store struct {
types.Store
}
func New(store types.Store) types.Store {
return &Store{
&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
},
},
}
}
func (s *Store) Delete(apiContext *types.APIContext, schema *types.Schema, id string) (map[string]interface{}, error) {
if slice.ContainsString(setting.ReadOnlySettings, id) {
return nil, httperror.NewAPIError(httperror.MethodNotAllowed, fmt.Sprintf("Cannot delete readOnly setting %s.", id))
}
return s.Store.Delete(apiContext, schema, id)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.2.6-rc2

搜索帮助

344bd9b3 5694891 D2dac590 5694891