37 Star 411 Fork 76

GVPrancher/rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
authconfig_data.go 2.56 KB
一键复制 编辑 原始数据 按行查看 历史
package app
import (
"github.com/rancher/rancher/pkg/auth/providers/activedirectory"
"github.com/rancher/rancher/pkg/auth/providers/azure"
"github.com/rancher/rancher/pkg/auth/providers/github"
"github.com/rancher/rancher/pkg/auth/providers/ldap"
localprovider "github.com/rancher/rancher/pkg/auth/providers/local"
"github.com/rancher/rancher/pkg/auth/providers/saml"
"github.com/rancher/rancher/pkg/namespace"
"github.com/rancher/types/apis/management.cattle.io/v3"
"github.com/rancher/types/client/management/v3"
"github.com/rancher/types/config"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/apis/meta/v1"
)
func addAuthConfigs(management *config.ManagementContext) error {
if err := addAuthConfig(github.Name, client.GithubConfigType, false, management); err != nil {
return err
}
if err := addAuthConfig(activedirectory.Name, client.ActiveDirectoryConfigType, false, management); err != nil {
return err
}
if err := addAuthConfig(azure.Name, client.AzureADConfigType, false, management); err != nil {
return err
}
if err := addAuthConfig(ldap.OpenLdapName, client.OpenLdapConfigType, false, management); err != nil {
return err
}
if err := addAuthConfig(ldap.FreeIpaName, client.FreeIpaConfigType, false, management); err != nil {
return err
}
if err := addAuthConfig(saml.PingName, client.PingConfigType, false, management); err != nil {
return err
}
if err := addAuthConfig(saml.ADFSName, client.ADFSConfigType, false, management); err != nil {
return err
}
if err := addAuthConfig(saml.KeyCloakName, client.KeyCloakConfigType, false, management); err != nil {
return err
}
if err := addAuthConfig(saml.OKTAName, client.OKTAConfigType, false, management); err != nil {
return err
}
if err := createMgmtNamespace(management); err != nil {
return err
}
return addAuthConfig(localprovider.Name, client.LocalConfigType, true, management)
}
func addAuthConfig(name, aType string, enabled bool, management *config.ManagementContext) error {
_, err := management.Management.AuthConfigs("").ObjectClient().Create(&v3.AuthConfig{
ObjectMeta: v1.ObjectMeta{
Name: name,
},
Type: aType,
Enabled: enabled,
})
if err != nil && !apierrors.IsAlreadyExists(err) {
return err
}
return nil
}
func createMgmtNamespace(management *config.ManagementContext) error {
_, err := management.Core.Namespaces("").Create(&corev1.Namespace{
ObjectMeta: v1.ObjectMeta{
Name: namespace.GlobalNamespace,
},
})
if err != nil && !apierrors.IsAlreadyExists(err) {
return err
}
return nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.2.0-alpha4

搜索帮助