37 Star 411 Fork 76

GVPrancher/rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
store.go 2.19 KB
一键复制 编辑 原始数据 按行查看 历史
Dan Ramich 提交于 2019-06-12 13:38 . goimport linting changes
package publicapi
import (
"strings"
"github.com/rancher/norman/httperror"
"github.com/rancher/norman/objectclient"
"github.com/rancher/norman/store/empty"
"github.com/rancher/norman/types"
"github.com/rancher/rancher/pkg/auth/providers"
"github.com/rancher/rancher/pkg/settings"
"github.com/rancher/types/config"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
)
func setAuthProvidersStore(schema *types.Schema, apiContext *config.ScaledContext) {
schema.Store = &authProvidersStore{
authConfigsRaw: apiContext.Management.AuthConfigs("").ObjectClient().UnstructuredClient(),
}
}
type authProvidersStore struct {
empty.Store
authConfigsRaw objectclient.GenericClient
}
func (s *authProvidersStore) ByID(apiContext *types.APIContext, schema *types.Schema, id string) (map[string]interface{}, error) {
o, err := s.authConfigsRaw.Get(id, v1.GetOptions{})
if err != nil {
return nil, err
}
u, _ := o.(runtime.Unstructured)
config := u.UnstructuredContent()
if t, ok := config["type"].(string); ok && t != "" {
return providers.GetProviderByType(t).TransformToAuthProvider(config), nil
}
return nil, httperror.NewAPIError(httperror.NotFound, "")
}
func (s *authProvidersStore) List(apiContext *types.APIContext, schema *types.Schema, opt *types.QueryOptions) ([]map[string]interface{}, error) {
rrr, _ := s.authConfigsRaw.List(v1.ListOptions{})
var result []map[string]interface{}
list, _ := rrr.(*unstructured.UnstructuredList)
for _, i := range list.Items {
if t, ok := i.Object["type"].(string); ok && t != "" {
if enabled, ok := i.Object["enabled"].(bool); ok && enabled {
result = append(result, providers.GetProviderByType(t).TransformToAuthProvider(i.Object))
}
}
}
return result, nil
}
func (s *authProvidersStore) 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
}
if strings.EqualFold(settings.FirstLogin.Get(), "true") {
if err := settings.FirstLogin.Set("false"); err != nil {
return nil, err
}
}
return result, nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.2.5-rc14

搜索帮助

0d507c66 1850385 C8b1a773 1850385