37 Star 411 Fork 76

GVPrancher/rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
store.go 1.67 KB
一键复制 编辑 原始数据 按行查看 历史
Darren Shepherd 提交于 2018-03-23 08:47 . Use new Transformer API
package secret
import (
"strings"
"github.com/rancher/norman/store/proxy"
"github.com/rancher/norman/store/transform"
"github.com/rancher/norman/types"
"github.com/rancher/norman/types/convert"
"github.com/rancher/types/config"
)
type Store struct {
types.Store
}
func (s *Store) Create(apiContext *types.APIContext, schema *types.Schema, data map[string]interface{}) (map[string]interface{}, error) {
t := convert.ToString(data["kind"])
t = strings.TrimPrefix(t, "namespaced")
t = convert.Uncapitalize(t)
data["kind"] = t
return s.Store.Create(apiContext, schema, data)
}
func NewNamespacedSecretStore(clientGetter proxy.ClientGetter) *Store {
return &Store{
Store: &transform.Store{
Store: proxy.NewProxyStore(clientGetter,
config.UserStorageContext,
[]string{"api"},
"",
"v1",
"Secret",
"secrets"),
Transformer: func(apiContext *types.APIContext, schema *types.Schema, data map[string]interface{}, opt *types.QueryOptions) (map[string]interface{}, error) {
if data == nil {
return data, nil
}
anns, _ := data["annotations"].(map[string]interface{})
if anns["secret.user.cattle.io/secret"] == "true" {
return nil, nil
}
if data["projectId"] != nil {
fieldProjectID, _ := data["projectId"].(string)
projectID := strings.Split(fieldProjectID, ":")
id := ""
if len(projectID) == 2 {
id = projectID[1]
}
if id == data["namespaceId"] {
return nil, nil
}
}
parts := strings.Split(convert.ToString(data["type"]), "/")
parts[len(parts)-1] = "namespaced" + convert.Capitalize(parts[len(parts)-1])
data["type"] = strings.Join(parts, "/")
return data, nil
},
},
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.0.0-alpha22

搜索帮助

0d507c66 1850385 C8b1a773 1850385