37 Star 407 Fork 75

GVPrancher/rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
actions.go 1.21 KB
一键复制 编辑 原始数据 按行查看 历史
Craig Jellick 提交于 2019-04-10 17:56 . Set content-type for auth responses
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" {
request.Response.Header().Add("Content-type", "application/json")
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")
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.2.4-rc3

搜索帮助