From 35cefb7da9f4e0177444a440d1c965db2c999e44 Mon Sep 17 00:00:00 2001 From: Bobby Rullo Date: Fri, 15 Apr 2016 17:23:27 -0700 Subject: [PATCH] schema: generate code --- schema/adminschema/README.md | 35 +++++++----- schema/adminschema/v1-gen.go | 47 ++++++++-------- schema/adminschema/v1-json.go | 103 +++++++++++++++++++--------------- schema/workerschema/mapper.go | 13 +++-- 4 files changed, 112 insertions(+), 86 deletions(-) diff --git a/schema/adminschema/README.md b/schema/adminschema/README.md index c16da394..48699989 100644 --- a/schema/adminschema/README.md +++ b/schema/adminschema/README.md @@ -20,32 +20,41 @@ __Version:__ v1 } ``` +### Client + + + +``` +{ + clientName: string // OPTIONAL. Name of the Client to be presented to the End-User. If desired, representation of this Claim in different languages and scripts is represented as described in Section 2.1 ( Metadata Languages and Scripts ) ., + clientURI: string // OPTIONAL. URL of the home page of the Client. The value of this field MUST point to a valid Web page. If present, the server SHOULD display this URL to the End-User in a followable fashion. If desired, representation of this Claim in different languages and scripts is represented as described in Section 2.1 ( Metadata Languages and Scripts ) ., + id: string // The client ID. Ignored in client create requests., + isAdmin: boolean, + logoURI: string // OPTIONAL. URL that references a logo for the Client application. If present, the server SHOULD display this image to the End-User during approval. The value of this field MUST point to a valid image file. If desired, representation of this Claim in different languages and scripts is represented as described in Section 2.1 ( Metadata Languages and Scripts ) ., + redirectURIs: [ + string + ], + secret: string +} +``` + ### ClientCreateRequest A request to register a client with dex. ``` { - client: { - client_name: string // OPTIONAL. Name of the Client to be presented to the End-User. If desired, representation of this Claim in different languages and scripts is represented as described in Section 2.1 ( Metadata Languages and Scripts ) ., - client_uri: string // OPTIONAL. URL of the home page of the Client. The value of this field MUST point to a valid Web page. If present, the server SHOULD display this URL to the End-User in a followable fashion. If desired, representation of this Claim in different languages and scripts is represented as described in Section 2.1 ( Metadata Languages and Scripts ) ., - logo_uri: string // OPTIONAL. URL that references a logo for the Client application. If present, the server SHOULD display this image to the End-User during approval. The value of this field MUST point to a valid image file. If desired, representation of this Claim in different languages and scripts is represented as described in Section 2.1 ( Metadata Languages and Scripts ) ., - redirect_uris: [ - string - ] - }, - isAdmin: boolean + client: Client } ``` -### ClientRegistrationResponse +### ClientCreateResponse Upon successful registration, an ID and secret is assigned to the client. ``` { - client_id: string, - client_secret: string + client: Client } ``` @@ -137,7 +146,7 @@ Upon successful registration, an ID and secret is assigned to the client. > |Code|Description|Type| |:-----|:-----|:-----| -| 200 | | [ClientRegistrationResponse](#clientregistrationresponse) | +| 200 | | [ClientCreateResponse](#clientcreateresponse) | | default | Unexpected error | | diff --git a/schema/adminschema/v1-gen.go b/schema/adminschema/v1-gen.go index 8b276158..bd49ddf3 100644 --- a/schema/adminschema/v1-gen.go +++ b/schema/adminschema/v1-gen.go @@ -97,49 +97,52 @@ type Admin struct { Password string `json:"password,omitempty"` } -type ClientCreateRequest struct { - Client *ClientCreateRequestClient `json:"client,omitempty"` - - IsAdmin bool `json:"isAdmin,omitempty"` -} - -type ClientCreateRequestClient struct { - // Client_name: OPTIONAL. Name of the Client to be presented to the +type Client struct { + // ClientName: OPTIONAL. Name of the Client to be presented to the // End-User. If desired, representation of this Claim in different // languages and scripts is represented as described in Section 2.1 ( // Metadata Languages and Scripts ) . - Client_name string `json:"client_name,omitempty"` + ClientName string `json:"clientName,omitempty"` - // Client_uri: OPTIONAL. URL of the home page of the Client. The value - // of this field MUST point to a valid Web page. If present, the server + // ClientURI: OPTIONAL. URL of the home page of the Client. The value of + // this field MUST point to a valid Web page. If present, the server // SHOULD display this URL to the End-User in a followable fashion. If // desired, representation of this Claim in different languages and // scripts is represented as described in Section 2.1 ( Metadata // Languages and Scripts ) . - Client_uri string `json:"client_uri,omitempty"` + ClientURI string `json:"clientURI,omitempty"` - // Logo_uri: OPTIONAL. URL that references a logo for the Client + // Id: The client ID. Ignored in client create requests. + Id string `json:"id,omitempty"` + + IsAdmin bool `json:"isAdmin,omitempty"` + + // LogoURI: OPTIONAL. URL that references a logo for the Client // application. If present, the server SHOULD display this image to the // End-User during approval. The value of this field MUST point to a // valid image file. If desired, representation of this Claim in // different languages and scripts is represented as described in // Section 2.1 ( Metadata Languages and Scripts ) . - Logo_uri string `json:"logo_uri,omitempty"` + LogoURI string `json:"logoURI,omitempty"` - // Redirect_uris: REQUIRED. Array of Redirection URI values used by the + // RedirectURIs: REQUIRED. Array of Redirection URI values used by the // Client. One of these registered Redirection URI values MUST exactly // match the redirect_uri parameter value used in each Authorization // Request, with the matching performed as described in Section 6.2.1 of // [RFC3986] ( Berners-Lee, T., Fielding, R., and L. Masinter, // “Uniform Resource Identifier (URI): Generic Syntax,” January // 2005. ) (Simple String Comparison). - Redirect_uris []string `json:"redirect_uris,omitempty"` + RedirectURIs []string `json:"redirectURIs,omitempty"` + + Secret string `json:"secret,omitempty"` } -type ClientRegistrationResponse struct { - Client_id string `json:"client_id,omitempty"` +type ClientCreateRequest struct { + Client *Client `json:"client,omitempty"` +} - Client_secret string `json:"client_secret,omitempty"` +type ClientCreateResponse struct { + Client *Client `json:"client,omitempty"` } type State struct { @@ -310,7 +313,7 @@ func (c *ClientCreateCall) Fields(s ...googleapi.Field) *ClientCreateCall { return c } -func (c *ClientCreateCall) Do() (*ClientRegistrationResponse, error) { +func (c *ClientCreateCall) Do() (*ClientCreateResponse, error) { var body io.Reader = nil body, err := googleapi.WithoutDataWrapper.JSONReader(c.clientcreaterequest) if err != nil { @@ -336,7 +339,7 @@ func (c *ClientCreateCall) Do() (*ClientRegistrationResponse, error) { if err := googleapi.CheckResponse(res); err != nil { return nil, err } - var ret *ClientRegistrationResponse + var ret *ClientCreateResponse if err := json.NewDecoder(res.Body).Decode(&ret); err != nil { return nil, err } @@ -350,7 +353,7 @@ func (c *ClientCreateCall) Do() (*ClientRegistrationResponse, error) { // "$ref": "ClientCreateRequest" // }, // "response": { - // "$ref": "ClientRegistrationResponse" + // "$ref": "ClientCreateResponse" // } // } diff --git a/schema/adminschema/v1-json.go b/schema/adminschema/v1-json.go index f99dfb71..64c29f61 100644 --- a/schema/adminschema/v1-json.go +++ b/schema/adminschema/v1-json.go @@ -51,53 +51,66 @@ const DiscoveryJSON = `{ } } }, - "ClientCreateRequest": { - "id": "ClientCreateRequest", - "type": "object", - "description": "A request to register a client with dex.", - "properties": { - "isAdmin": { - "type": "boolean" - }, - "client": { - "type": "object", - "properties": { - "redirect_uris": { - "type": "array", - "items": { - "type": "string" - }, - "description": "REQUIRED. Array of Redirection URI values used by the Client. One of these registered Redirection URI values MUST exactly match the redirect_uri parameter value used in each Authorization Request, with the matching performed as described in Section 6.2.1 of [RFC3986] ( Berners-Lee, T., Fielding, R., and L. Masinter, “Uniform Resource Identifier (URI): Generic Syntax,” January 2005. ) (Simple String Comparison)." - }, - "client_name": { - "type": "string", - "description": "OPTIONAL. Name of the Client to be presented to the End-User. If desired, representation of this Claim in different languages and scripts is represented as described in Section 2.1 ( Metadata Languages and Scripts ) ." - }, - "logo_uri": { - "type": "string", - "description": "OPTIONAL. URL that references a logo for the Client application. If present, the server SHOULD display this image to the End-User during approval. The value of this field MUST point to a valid image file. If desired, representation of this Claim in different languages and scripts is represented as described in Section 2.1 ( Metadata Languages and Scripts ) ." - }, - "client_uri": { - "type": "string", - "description": "OPTIONAL. URL of the home page of the Client. The value of this field MUST point to a valid Web page. If present, the server SHOULD display this URL to the End-User in a followable fashion. If desired, representation of this Claim in different languages and scripts is represented as described in Section 2.1 ( Metadata Languages and Scripts ) ." - } - } - } + "Client": { + "id": "Client", + "type": "object", + "properties": { + "id": { + "type": "string", + "description": "The client ID. Ignored in client create requests." + }, + "secret": { + "type": "string", + "description": "The client secret. Ignored in client create requests." + }, + "secret": { + "type": "string", + "format": "byte" + }, + "isAdmin": { + "type": "boolean" + }, + "redirectURIs": { + "type": "array", + "items": { + "type": "string" + }, + "description": "REQUIRED. Array of Redirection URI values used by the Client. One of these registered Redirection URI values MUST exactly match the redirect_uri parameter value used in each Authorization Request, with the matching performed as described in Section 6.2.1 of [RFC3986] ( Berners-Lee, T., Fielding, R., and L. Masinter, “Uniform Resource Identifier (URI): Generic Syntax,” January 2005. ) (Simple String Comparison)." + }, + "clientName": { + "type": "string", + "description": "OPTIONAL. Name of the Client to be presented to the End-User. If desired, representation of this Claim in different languages and scripts is represented as described in Section 2.1 ( Metadata Languages and Scripts ) ." + }, + "logoURI": { + "type": "string", + "description": "OPTIONAL. URL that references a logo for the Client application. If present, the server SHOULD display this image to the End-User during approval. The value of this field MUST point to a valid image file. If desired, representation of this Claim in different languages and scripts is represented as described in Section 2.1 ( Metadata Languages and Scripts ) ." + }, + "clientURI": { + "type": "string", + "description": "OPTIONAL. URL of the home page of the Client. The value of this field MUST point to a valid Web page. If present, the server SHOULD display this URL to the End-User in a followable fashion. If desired, representation of this Claim in different languages and scripts is represented as described in Section 2.1 ( Metadata Languages and Scripts ) ." } + } }, - "ClientRegistrationResponse": { - "id": "ClientRegistrationResponse", - "type": "object", - "description": "Upon successful registration, an ID and secret is assigned to the client.", - "properties": { - "client_id": { - "type": "string" - }, - "client_secret": { - "type": "string" - } - } + "ClientCreateRequest": { + "id": "ClientCreateRequest", + "type": "object", + "description": "A request to register a client with dex.", + "properties": { + "client": { + "$ref": "Client" + } } + }, + "ClientCreateResponse": { + "id": "ClientCreateResponse", + "type": "object", + "description": "Upon successful registration, an ID and secret is assigned to the client.", + "properties": { + "client":{ + "$ref": "Client" + } + } + } }, "resources": { "Admin": { @@ -160,7 +173,7 @@ const DiscoveryJSON = `{ "$ref": "ClientCreateRequest" }, "response": { - "$ref": "ClientRegistrationResponse" + "$ref": "ClientCreateResponse" } } } diff --git a/schema/workerschema/mapper.go b/schema/workerschema/mapper.go index ab9c16e7..7cdf4ab3 100644 --- a/schema/workerschema/mapper.go +++ b/schema/workerschema/mapper.go @@ -4,11 +4,12 @@ import ( "errors" "net/url" + "github.com/coreos/dex/client" "github.com/coreos/go-oidc/oidc" ) -func MapSchemaClientToClientIdentity(sc Client) (oidc.ClientIdentity, error) { - ci := oidc.ClientIdentity{ +func MapSchemaClientToClient(sc Client) (client.Client, error) { + ci := client.Client{ Credentials: oidc.ClientCredentials{ ID: sc.Id, }, @@ -19,12 +20,12 @@ func MapSchemaClientToClientIdentity(sc Client) (oidc.ClientIdentity, error) { for i, ru := range sc.RedirectURIs { if ru == "" { - return oidc.ClientIdentity{}, errors.New("redirect URL empty") + return client.Client{}, errors.New("redirect URL empty") } u, err := url.Parse(ru) if err != nil { - return oidc.ClientIdentity{}, errors.New("redirect URL invalid") + return client.Client{}, errors.New("redirect URL invalid") } ci.Metadata.RedirectURIs[i] = *u @@ -33,7 +34,7 @@ func MapSchemaClientToClientIdentity(sc Client) (oidc.ClientIdentity, error) { return ci, nil } -func MapClientIdentityToSchemaClient(c oidc.ClientIdentity) Client { +func MapClientToSchemaClient(c client.Client) Client { cl := Client{ Id: c.Credentials.ID, RedirectURIs: make([]string, len(c.Metadata.RedirectURIs)), @@ -44,7 +45,7 @@ func MapClientIdentityToSchemaClient(c oidc.ClientIdentity) Client { return cl } -func MapClientIdentityToSchemaClientWithSecret(c oidc.ClientIdentity) ClientWithSecret { +func MapClientToSchemaClientWithSecret(c client.Client) ClientWithSecret { cl := ClientWithSecret{ Id: c.Credentials.ID, Secret: c.Credentials.Secret,