-
Notifications
You must be signed in to change notification settings - Fork 3k
/
handler.go
57 lines (48 loc) · 1.71 KB
/
handler.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
package publicapi
import (
"context"
"net/http"
normanapi "github.com/rancher/norman/api"
"github.com/rancher/norman/store/subtype"
"github.com/rancher/norman/types"
publicSchema "github.com/rancher/types/apis/management.cattle.io/v3public/schema"
v3public "github.com/rancher/types/client/management/v3public"
"github.com/rancher/types/config"
)
func NewHandler(ctx context.Context, mgmtCtx *config.ScaledContext) (http.Handler, error) {
schemas := types.NewSchemas().AddSchemas(publicSchema.PublicSchemas)
if err := authProviderSchemas(ctx, mgmtCtx, schemas); err != nil {
return nil, err
}
server := normanapi.NewAPIServer()
if err := server.AddSchemas(schemas); err != nil {
return nil, err
}
return server, nil
}
var authProviderTypes = []string{
v3public.ActiveDirectoryProviderType,
v3public.AzureADProviderType,
v3public.GithubProviderType,
v3public.LocalProviderType,
v3public.OpenLdapProviderType,
v3public.FreeIpaProviderType,
v3public.PingProviderType,
v3public.ADFSProviderType,
v3public.KeyCloakProviderType,
}
func authProviderSchemas(ctx context.Context, management *config.ScaledContext, schemas *types.Schemas) error {
schema := schemas.Schema(&publicSchema.PublicVersion, v3public.AuthProviderType)
setAuthProvidersStore(schema, management)
lh := newLoginHandler(ctx, management)
for _, apSubtype := range authProviderTypes {
subSchema := schemas.Schema(&publicSchema.PublicVersion, apSubtype)
subSchema.Store = subtype.NewSubTypeStore(apSubtype, schema.Store)
subSchema.ActionHandler = lh.login
subSchema.Formatter = loginActionFormatter
}
return nil
}
func loginActionFormatter(apiContext *types.APIContext, resource *types.RawResource) {
resource.AddAction(apiContext, "login")
}