代码拉取完成,页面将自动刷新
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/rancher/pkg/api/store/sharewatch"
"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(clientGetter,
config.UserStorageContext,
[]string{"api"},
"",
"v1",
"Secret",
"secrets")
secretsStore = sharewatch.NewWatchShare(ctx, clientGetter, secretsStore)
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
},
},
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。