-
Notifications
You must be signed in to change notification settings - Fork 274
/
oidc.go
72 lines (63 loc) 路 1.7 KB
/
oidc.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package cluster
import (
"context"
apierrors "k8s.io/apimachinery/pkg/api/errors"
anywherev1 "github.com/aws/eks-anywhere/pkg/api/v1alpha1"
)
func oidcEntry() *ConfigManagerEntry {
return &ConfigManagerEntry{
APIObjectMapping: map[string]APIObjectGenerator{
anywherev1.OIDCConfigKind: func() APIObject {
return &anywherev1.OIDCConfig{}
},
},
Processors: []ParsedProcessor{processOIDC},
Validations: []Validation{
func(c *Config) error {
for _, o := range c.OIDCConfigs {
if errs := o.Validate(); len(errs) != 0 {
return apierrors.NewInvalid(anywherev1.GroupVersion.WithKind(anywherev1.OIDCConfigKind).GroupKind(), o.Name, errs)
}
}
return nil
},
func(c *Config) error {
for _, o := range c.OIDCConfigs {
if err := validateSameNamespace(c, o); err != nil {
return err
}
}
return nil
},
},
}
}
func processOIDC(c *Config, objects ObjectLookup) {
if c.OIDCConfigs == nil {
c.OIDCConfigs = map[string]*anywherev1.OIDCConfig{}
}
for _, idr := range c.Cluster.Spec.IdentityProviderRefs {
idp := objects.GetFromRef(c.Cluster.APIVersion, idr)
if idp == nil {
return
}
if idr.Kind == anywherev1.OIDCConfigKind {
c.OIDCConfigs[idp.GetName()] = idp.(*anywherev1.OIDCConfig)
}
}
}
func getOIDC(ctx context.Context, client Client, c *Config) error {
if c.OIDCConfigs == nil {
c.OIDCConfigs = map[string]*anywherev1.OIDCConfig{}
}
for _, idr := range c.Cluster.Spec.IdentityProviderRefs {
if idr.Kind == anywherev1.OIDCConfigKind {
oidc := &anywherev1.OIDCConfig{}
if err := client.Get(ctx, idr.Name, c.Cluster.Namespace, oidc); err != nil {
return err
}
c.OIDCConfigs[oidc.Name] = oidc
}
}
return nil
}