forked from rancher/rancher
-
Notifications
You must be signed in to change notification settings - Fork 1
/
authconfig_data.go
39 lines (33 loc) · 1.17 KB
/
authconfig_data.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package app
import (
"github.com/rancher/rancher/pkg/auth/providers/activedirectory"
"github.com/rancher/rancher/pkg/auth/providers/github"
localprovider "github.com/rancher/rancher/pkg/auth/providers/local"
"github.com/rancher/types/apis/management.cattle.io/v3"
"github.com/rancher/types/client/management/v3"
"github.com/rancher/types/config"
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
}
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
}