36 Star 396 Fork 71

GVPrancher / rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
store.go 1.73 KB
一键复制 编辑 原始数据 按行查看 历史
Darren Shepherd 提交于 2018-04-26 15:02 . Move watch sharing to norman
package secret
import (
"strings"
"context"
"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(ctx context.Context, clientGetter proxy.ClientGetter) *Store {
secretsStore := proxy.NewProxyStore(ctx, clientGetter,
config.UserStorageContext,
[]string{"api"},
"",
"v1",
"Secret",
"secrets")
return &Store{
Store: &transform.Store{
Store: secretsStore,
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
},
},
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.3.0-alpha1

搜索帮助

344bd9b3 5694891 D2dac590 5694891