37 Star 396 Fork 71

GVPrancher/rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
api.go 2.09 KB
一键复制 编辑 原始数据 按行查看 历史
orangedeng 提交于 2018-09-03 10:44 . Cache the API UI in local file
package tokens
import (
"context"
"net/http"
"github.com/rancher/norman/httperror"
"github.com/rancher/norman/types"
rancherapi "github.com/rancher/rancher/pkg/api"
managementSchema "github.com/rancher/types/apis/management.cattle.io/v3/schema"
"github.com/rancher/types/client/management/v3"
"github.com/rancher/types/config"
"github.com/sirupsen/logrus"
)
const (
CookieName = "R_SESS"
AuthHeaderName = "Authorization"
AuthValuePrefix = "Bearer"
BasicAuthPrefix = "Basic"
)
var crdVersions = []*types.APIVersion{
&managementSchema.Version,
}
func NewAPIHandler(ctx context.Context, apiContext *config.ScaledContext) (http.Handler, error) {
api := &tokenAPI{
mgr: NewManager(ctx, apiContext),
}
schemas := types.NewSchemas().AddSchemas(managementSchema.TokenSchemas)
schema := schemas.Schema(&managementSchema.Version, client.TokenType)
schema.CollectionActions = map[string]types.Action{
"logout": {},
}
schema.ActionHandler = api.tokenActionHandler
schema.ListHandler = api.tokenListHandler
schema.CreateHandler = api.tokenCreateHandler
schema.DeleteHandler = api.tokenDeleteHandler
return rancherapi.NewServer(schemas)
}
type tokenAPI struct {
mgr *Manager
}
func (t *tokenAPI) tokenActionHandler(actionName string, action *types.Action, request *types.APIContext) error {
logrus.Debugf("TokenActionHandler called for action %v", actionName)
if actionName == "logout" {
return t.mgr.logout(actionName, action, request)
}
return httperror.NewAPIError(httperror.ActionNotAvailable, "")
}
func (t *tokenAPI) tokenCreateHandler(request *types.APIContext, _ types.RequestHandler) error {
logrus.Debugf("TokenCreateHandler called")
return t.mgr.deriveToken(request)
}
func (t *tokenAPI) tokenListHandler(request *types.APIContext, _ types.RequestHandler) error {
logrus.Debugf("TokenListHandler called")
if request.ID != "" {
return t.mgr.getTokenFromRequest(request)
}
return t.mgr.listTokens(request)
}
func (t *tokenAPI) tokenDeleteHandler(request *types.APIContext, _ types.RequestHandler) error {
logrus.Debugf("TokenDeleteHandler called")
return t.mgr.removeToken(request)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.2.0

搜索帮助

344bd9b3 5694891 D2dac590 5694891