37 Star 403 Fork 75

GVPrancher/rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
store.go 2.28 KB
一键复制 编辑 原始数据 按行查看 历史
phli 提交于 2018-06-26 16:36 . pipeline new ux
package providers
import (
"github.com/rancher/norman/httperror"
"github.com/rancher/norman/objectclient"
"github.com/rancher/norman/store/empty"
"github.com/rancher/norman/types"
"github.com/rancher/norman/types/convert"
"github.com/rancher/rancher/pkg/ref"
"github.com/rancher/types/client/project/v3"
"github.com/rancher/types/config"
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
)
func setSourceCodeProviderStore(schema *types.Schema, apiContext *config.ScaledContext) {
schema.Store = &sourceCodeProviderStore{
scpConfigsRaw: apiContext.Project.SourceCodeProviderConfigs("").ObjectClient().UnstructuredClient(),
}
}
type sourceCodeProviderStore struct {
empty.Store
scpConfigsRaw objectclient.GenericClient
}
func (s *sourceCodeProviderStore) ByID(apiContext *types.APIContext, schema *types.Schema, id string) (map[string]interface{}, error) {
ns, name := ref.Parse(id)
o, err := s.scpConfigsRaw.GetNamespaced(ns, name, v1.GetOptions{})
if err != nil {
return nil, err
}
u, _ := o.(runtime.Unstructured)
config := u.UnstructuredContent()
if t := convert.ToString(config[client.SourceCodeProviderFieldType]); t != "" && providersByType[t] != nil {
return providersByType[t].TransformToSourceCodeProvider(config), nil
}
return nil, httperror.NewAPIError(httperror.NotFound, "")
}
func (s *sourceCodeProviderStore) List(apiContext *types.APIContext, schema *types.Schema, opt *types.QueryOptions) ([]map[string]interface{}, error) {
rrr, _ := s.scpConfigsRaw.List(v1.ListOptions{})
var result []map[string]interface{}
list, _ := rrr.(*unstructured.UnstructuredList)
for _, i := range list.Items {
if t := convert.ToString(i.Object[client.SourceCodeProviderFieldType]); t != "" && providersByType[t] != nil {
if enabled, ok := i.Object[client.SourceCodeProviderConfigFieldEnabled].(bool); ok && enabled {
result = append(result, providersByType[t].TransformToSourceCodeProvider(i.Object))
}
}
}
return result, nil
}
func (s *sourceCodeProviderStore) Update(apiContext *types.APIContext, schema *types.Schema, data map[string]interface{}, id string) (map[string]interface{}, error) {
result, err := s.Update(apiContext, schema, data, id)
if err != nil {
return nil, err
}
return result, nil
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.1.10-rc4

搜索帮助