forked from rancher/rancher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
apihandler.go
50 lines (39 loc) · 1.19 KB
/
apihandler.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
package tokens
import (
"context"
"net/http"
normanapi "github.com/rancher/norman/api"
"github.com/rancher/norman/types"
managementSchema "github.com/rancher/types/apis/management.cattle.io/v3/schema"
"github.com/rancher/types/client/management/v3"
"github.com/rancher/types/config"
)
var crdVersions = []*types.APIVersion{
&managementSchema.Version,
}
func NewAPIHandler(ctx context.Context, apiContext *config.ScaledContext) (http.Handler, error) {
err := NewTokenAPIServer(ctx, apiContext)
if err != nil {
return nil, err
}
schemas := types.NewSchemas().AddSchemas(managementSchema.TokenSchemas)
if err := tokenSchema(ctx, schemas); err != nil {
return nil, err
}
server := normanapi.NewAPIServer()
if err := server.AddSchemas(schemas); err != nil {
return nil, err
}
return server, nil
}
func tokenSchema(ctx context.Context, schemas *types.Schemas) error {
schema := schemas.Schema(&managementSchema.Version, client.TokenType)
schema.CollectionActions = map[string]types.Action{
"logout": {},
}
schema.ActionHandler = tokenActionHandler
schema.ListHandler = tokenListHandler
schema.CreateHandler = tokenCreateHandler
schema.DeleteHandler = tokenDeleteHandler
return nil
}