37 Star 411 Fork 76

GVPrancher/rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
actions.go 1.14 KB
一键复制 编辑 原始数据 按行查看 历史
Craig Jellick 提交于 2018-06-20 15:10 . Improve auth logging
package common
import (
"github.com/rancher/norman/types"
"github.com/rancher/types/apis/management.cattle.io/v3"
"github.com/rancher/types/client/management/v3"
"github.com/sirupsen/logrus"
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
)
func HandleCommonAction(actionName string, action *types.Action, request *types.APIContext, authConfigName string, authConfigs v3.AuthConfigInterface) (bool, error) {
if actionName == "disable" {
o, err := authConfigs.ObjectClient().UnstructuredClient().Get(authConfigName, v1.GetOptions{})
if err != nil {
return false, err
}
u, _ := o.(runtime.Unstructured)
config := u.UnstructuredContent()
if e, ok := config[client.AuthConfigFieldEnabled].(bool); ok && e {
config[client.AuthConfigFieldEnabled] = false
logrus.Infof("Disabling auth provider %v", authConfigName)
_, err := authConfigs.ObjectClient().Update(authConfigName, o)
return true, err
}
}
return false, nil
}
func AddCommonActions(apiContext *types.APIContext, resource *types.RawResource) {
if e, ok := resource.Values["enabled"].(bool); ok && e {
resource.AddAction(apiContext, "disable")
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.1.2-rc14

搜索帮助

0d507c66 1850385 C8b1a773 1850385