-
Notifications
You must be signed in to change notification settings - Fork 53
/
auth_providers.go
42 lines (39 loc) · 1.16 KB
/
auth_providers.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
package machinery
import (
"context"
"fmt"
"github.com/rancher/opni/pkg/auth"
"github.com/rancher/opni/pkg/auth/noauth"
"github.com/rancher/opni/pkg/auth/openid"
"github.com/rancher/opni/pkg/auth/test"
"github.com/rancher/opni/pkg/config/meta"
"github.com/rancher/opni/pkg/config/v1beta1"
)
func LoadAuthProviders(ctx context.Context, objects meta.ObjectList) map[string]auth.Middleware {
authProviders := make(map[string]auth.Middleware)
objects.Visit(
func(ap *v1beta1.AuthProvider) {
switch ap.Spec.Type {
case v1beta1.AuthProviderOpenID:
mw, err := openid.New(ctx, ap.Spec)
if err != nil {
panic(fmt.Errorf("failed to create OpenID auth provider: %w", err))
}
authProviders[ap.Name] = mw
case v1beta1.AuthProviderNoAuth:
mw, err := noauth.New(ctx, ap.Spec)
if err != nil {
panic(fmt.Errorf("failed to create noauth auth provider: %w", err))
}
authProviders[ap.Name] = mw
case "test":
authProviders["test"] = &test.TestAuthMiddleware{
Strategy: test.AuthStrategyUserIDInAuthHeader,
}
default:
panic(fmt.Errorf("unsupported auth provider type: %s", ap.Spec.Type))
}
},
)
return authProviders
}