forked from rancher/auth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler.go
50 lines (40 loc) · 1.64 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
package tokens
import (
"context"
"github.com/gorilla/mux"
"net/http"
"github.com/rancher/types/config"
)
//tokenAndIdentityAPIHandler is a wrapper over the mux router serving /token and /identities API
type tokenAPIHandler struct {
tokenRouter http.Handler
}
func (h *tokenAPIHandler) getRouter() http.Handler {
return h.tokenRouter
}
func (h *tokenAPIHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
h.getRouter().ServeHTTP(w, r)
}
func NewTokenAPIHandler(ctx context.Context, mgmtCtx *config.ManagementContext) (http.Handler, error) {
router, err := newTokenRouter(ctx, mgmtCtx)
if err != nil {
return nil, err
}
return &tokenAPIHandler{tokenRouter: router}, nil
}
//newTokenRouter creates and configures a mux router for /v3/tokens APIs
func newTokenRouter(ctx context.Context, mgmtCtx *config.ManagementContext) (*mux.Router, error) {
apiServer, err := newTokenAPIServer(ctx, mgmtCtx)
if err != nil {
return nil, err
}
router := mux.NewRouter().StrictSlash(true)
// Application routes
router.Methods("POST").Path("/v3/tokens").Queries("action", "login").Handler(http.HandlerFunc(apiServer.login))
router.Methods("POST").Path("/v3/tokens").Queries("action", "logout").Handler(http.HandlerFunc(apiServer.logout))
router.Methods("POST").Path("/v3/tokens").Handler(http.HandlerFunc(apiServer.deriveToken))
router.Methods("GET").Path("/v3/tokens").Handler(http.HandlerFunc(apiServer.listTokens))
//router.Methods("GET").Path("/v3/identities").Handler(http.HandlerFunc(apiServer.listIdentities))
//router.Methods("GET").Path("/v1/identities").Handler(api.ApiHandler(schemas, http.HandlerFunc(SearchIdentities)))
return router, nil
}