diff --git a/apis/management.cattle.io/v3/authn_types.go b/apis/management.cattle.io/v3/authn_types.go index 279cc8ac..8540766c 100644 --- a/apis/management.cattle.io/v3/authn_types.go +++ b/apis/management.cattle.io/v3/authn_types.go @@ -62,26 +62,6 @@ type Principal struct { ExtraInfo map[string]string `json:"extraInfo,omitempty"` } -//LoginInput structure defines all properties that can be sent by client to create a token -type LoginInput struct { - TTLMillis int `json:"ttl,omitempty"` - Description string `json:"description,omitempty"` - ResponseType string `json:"responseType,omitempty"` //json or cookie - LocalCredential LocalCredential `json:"localCredential, omitempty"` - GithubCredential GithubCredential `json:"githubCredential, omitempty"` -} - -//LocalCredential stores the local auth creds -type LocalCredential struct { - Username string `json:"username"` - Password string `json:"password"` -} - -//GithubCredential stores the github auth creds -type GithubCredential struct { - Code string `json:"code"` -} - type ChangePasswordInput struct { CurrentPassword string `json:"currentPassword" norman:"type=string,required"` NewPassword string `json:"newPassword" norman:"type=string,required"` @@ -126,7 +106,7 @@ type GithubConfigTestInput struct { //GithubConfigApplyInput structure defines all properties that can be sent by client to configure github type GithubConfigApplyInput struct { - GithubConfig GithubConfig `json:"githubConfig, omitempty"` - GithubCredential GithubCredential `json:"githubCredential, omitempty"` - Enabled bool `json:"enabled,omitempty"` + GithubConfig GithubConfig `json:"githubConfig, omitempty"` + Code string `json:"code,omitempty"` + Enabled bool `json:"enabled,omitempty"` } diff --git a/apis/management.cattle.io/v3/schema/schema.go b/apis/management.cattle.io/v3/schema/schema.go index e04fa316..3b9dc878 100644 --- a/apis/management.cattle.io/v3/schema/schema.go +++ b/apis/management.cattle.io/v3/schema/schema.go @@ -36,7 +36,7 @@ var ( Init(globalTypes). Init(rkeTypes) - TokenSchema = factory.Schemas(&Version). + TokenSchemas = factory.Schemas(&Version). Init(tokens) ) @@ -149,15 +149,8 @@ func machineTypes(schemas *types.Schemas) *types.Schemas { func tokens(schemas *types.Schemas) *types.Schemas { return schemas. - MustImport(&Version, v3.LoginInput{}). - MustImport(&Version, v3.LocalCredential{}). - MustImport(&Version, v3.GithubCredential{}). MustImportAndCustomize(&Version, v3.Token{}, func(schema *types.Schema) { schema.CollectionActions = map[string]types.Action{ - "login": { - Input: "loginInput", - Output: "token", - }, "logout": {}, } }) diff --git a/apis/management.cattle.io/v3public/authn_types.go b/apis/management.cattle.io/v3public/authn_types.go new file mode 100644 index 00000000..603d7455 --- /dev/null +++ b/apis/management.cattle.io/v3public/authn_types.go @@ -0,0 +1,41 @@ +package v3public + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +type AuthProvider struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + Type string `json:"type"` +} + +type GithubProvider struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + AuthProvider `json:",inline"` +} + +type LocalProvider struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + AuthProvider `json:",inline"` +} + +type GenericLogin struct { + TTLMillis int `json:"ttl,omitempty"` + Description string `json:"description,omitempty" norman:"type=string,required"` + ResponseType string `json:"responseType,omitempty" norman:"type=string,required"` //json or cookie +} + +type GithubLogin struct { + GenericLogin `json:",inline"` + Code string `json:"code" norman:"type=string,required"` +} + +type LocalLogin struct { + GenericLogin `json:",inline"` + Username string `json:"username" norman:"type=string,required"` + Password string `json:"password" norman:"type=string,required"` +} diff --git a/apis/management.cattle.io/v3public/schema/public_schema.go b/apis/management.cattle.io/v3public/schema/public_schema.go new file mode 100644 index 00000000..3ca9e9d3 --- /dev/null +++ b/apis/management.cattle.io/v3public/schema/public_schema.go @@ -0,0 +1,57 @@ +package schema + +import ( + "net/http" + + "github.com/rancher/norman/types" + "github.com/rancher/types/apis/management.cattle.io/v3" + "github.com/rancher/types/apis/management.cattle.io/v3public" + "github.com/rancher/types/factory" +) + +var ( + PublicVersion = types.APIVersion{ + Version: "v3public", + Group: "management.cattle.io", + Path: "/v3-public", + } + + PublicSchemas = factory.Schemas(&PublicVersion). + Init(authProvidersTypes) +) + +func authProvidersTypes(schemas *types.Schemas) *types.Schemas { + return schemas. + MustImportAndCustomize(&PublicVersion, v3public.AuthProvider{}, func(schema *types.Schema) { + schema.CollectionMethods = []string{http.MethodGet} + }). + MustImportAndCustomize(&PublicVersion, v3public.GithubProvider{}, func(schema *types.Schema) { + schema.BaseType = "authProvider" + schema.ResourceActions = map[string]types.Action{ + "login": { + Input: "githubLogin", + Output: "token", + }, + } + schema.CollectionMethods = []string{} + schema.ResourceMethods = []string{http.MethodGet} + }). + MustImportAndCustomize(&PublicVersion, v3public.LocalProvider{}, func(schema *types.Schema) { + schema.BaseType = "authProvider" + schema.ResourceActions = map[string]types.Action{ + "login": { + Input: "localLogin", + Output: "token", + }, + } + schema.CollectionMethods = []string{} + schema.ResourceMethods = []string{http.MethodGet} + }). + MustImport(&PublicVersion, v3public.GithubLogin{}). + MustImport(&PublicVersion, v3public.LocalLogin{}). + MustImportAndCustomize(&PublicVersion, v3.Token{}, func(schema *types.Schema) { + // No collection methods causes the store to not create a CRD for it + schema.CollectionMethods = []string{} + schema.ResourceMethods = []string{} + }) +} diff --git a/main.go b/main.go index 352c2389..accee626 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,7 @@ package main import ( clusterSchema "github.com/rancher/types/apis/cluster.cattle.io/v3/schema" managementSchema "github.com/rancher/types/apis/management.cattle.io/v3/schema" + publicSchema "github.com/rancher/types/apis/management.cattle.io/v3public/schema" projectSchema "github.com/rancher/types/apis/project.cattle.io/v3/schema" "github.com/rancher/types/generator" "k8s.io/api/apps/v1beta2" @@ -16,6 +17,7 @@ import ( func main() { generator.Generate(managementSchema.Schemas) + generator.Generate(publicSchema.PublicSchemas) generator.Generate(clusterSchema.Schemas) generator.Generate(projectSchema.Schemas) generator.GenerateNativeTypes(v1.SchemeGroupVersion, []interface{}{