代码拉取完成,页面将自动刷新
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"
client "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"
CSRFCookie = "CSRF"
)
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)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。