36 Star 396 Fork 71

GVPrancher / rancher

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
Clone or Download
handler.go 1.63 KB
Copy Edit Raw Blame History
orangedeng authored 2018-09-03 10:44 . Cache the API UI in local file
package publicapi
import (
"context"
"net/http"
"github.com/rancher/norman/store/subtype"
"github.com/rancher/norman/types"
rancherapi "github.com/rancher/rancher/pkg/api"
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
}
return rancherapi.NewServer(schemas)
}
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")
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.1.2-rc10

Search

344bd9b3 5694891 D2dac590 5694891