1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

generate AuthResponse type from swagger spec.

Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
Daniel Nephin 2016-10-18 17:52:46 -07:00
parent f196cf6a09
commit 2732b8a9bb
7 changed files with 39 additions and 26 deletions

View file

@ -13,6 +13,7 @@ import (
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/events" "github.com/docker/docker/api/types/events"
"github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/registry"
timetypes "github.com/docker/docker/api/types/time" timetypes "github.com/docker/docker/api/types/time"
"github.com/docker/docker/api/types/versions" "github.com/docker/docker/api/types/versions"
"github.com/docker/docker/pkg/ioutils" "github.com/docker/docker/pkg/ioutils"
@ -154,7 +155,7 @@ func (s *systemRouter) postAuth(ctx context.Context, w http.ResponseWriter, r *h
if err != nil { if err != nil {
return err return err
} }
return httputils.WriteJSON(w, http.StatusOK, &types.AuthResponse{ return httputils.WriteJSON(w, http.StatusOK, &registry.AuthenticateOKBody{
Status: status, Status: status,
IdentityToken: token, IdentityToken: token,
}) })

View file

@ -4612,23 +4612,24 @@ paths:
post: post:
summary: "Check auth configuration" summary: "Check auth configuration"
description: "Validate credentials for a registry and, if available, get an identity token for accessing the registry without password." description: "Validate credentials for a registry and, if available, get an identity token for accessing the registry without password."
operationId: "checkAuthentication" operationId: "Authenticate"
consumes: consumes: ["application/json"]
- "application/json" produces: ["application/json"]
produces:
- "application/json"
responses: responses:
200: 200:
description: "No error" description: "An identity token was generated successfully."
schema: schema:
type: "object" type: "object"
required: [Status]
properties: properties:
Status: Status:
description: "The status of the authentication" description: "The status of the authentication"
type: "string" type: "string"
x-nullable: false
IdentityToken: IdentityToken:
description: "An opaque token used to authenticate a user after a successful login" description: "An opaque token used to authenticate a user after a successful login"
type: "string" type: "string"
x-nullable: false
examples: examples:
application/json: application/json:
Status: "Login Succeeded" Status: "Login Succeeded"
@ -4645,8 +4646,7 @@ paths:
description: "Authentication to check" description: "Authentication to check"
schema: schema:
$ref: "#/definitions/AuthConfig" $ref: "#/definitions/AuthConfig"
tags: tags: ["Registry"]
- "Misc"
/info: /info:
get: get:
summary: "Get system information" summary: "Get system information"

View file

@ -0,0 +1,21 @@
package registry
// ----------------------------------------------------------------------------
// DO NOT EDIT THIS FILE
// This file was generated by `swagger generate operation`
//
// See hack/swagger-gen.sh
// ----------------------------------------------------------------------------
// AuthenticateOKBody authenticate o k body
// swagger:model AuthenticateOKBody
type AuthenticateOKBody struct {
// An opaque token used to authenticate a user after a successful login
// Required: true
IdentityToken string `json:"IdentityToken"`
// The status of the authentication
// Required: true
Status string `json:"Status"`
}

View file

@ -13,17 +13,6 @@ import (
"github.com/docker/go-connections/nat" "github.com/docker/go-connections/nat"
) )
// AuthResponse contains response of Remote API:
// POST "/auth"
type AuthResponse struct {
// Status is the authentication status
Status string `json:"Status"`
// IdentityToken is an opaque token used for authenticating
// a user after a successful login.
IdentityToken string `json:"IdentityToken,omitempty"`
}
// ContainerWaitResponse contains response of Remote API: // ContainerWaitResponse contains response of Remote API:
// POST "/containers/"+containerID+"/wait" // POST "/containers/"+containerID+"/wait"
type ContainerWaitResponse struct { type ContainerWaitResponse struct {

View file

@ -127,7 +127,7 @@ type SwarmAPIClient interface {
type SystemAPIClient interface { type SystemAPIClient interface {
Events(ctx context.Context, options types.EventsOptions) (<-chan events.Message, <-chan error) Events(ctx context.Context, options types.EventsOptions) (<-chan events.Message, <-chan error)
Info(ctx context.Context) (types.Info, error) Info(ctx context.Context) (types.Info, error)
RegistryLogin(ctx context.Context, auth types.AuthConfig) (types.AuthResponse, error) RegistryLogin(ctx context.Context, auth types.AuthConfig) (registry.AuthenticateOKBody, error)
DiskUsage(ctx context.Context) (types.DiskUsage, error) DiskUsage(ctx context.Context) (types.DiskUsage, error)
Ping(ctx context.Context) (bool, error) Ping(ctx context.Context) (bool, error)
} }

View file

@ -6,22 +6,23 @@ import (
"net/url" "net/url"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/registry"
"golang.org/x/net/context" "golang.org/x/net/context"
) )
// RegistryLogin authenticates the docker server with a given docker registry. // RegistryLogin authenticates the docker server with a given docker registry.
// It returns UnauthorizerError when the authentication fails. // It returns UnauthorizerError when the authentication fails.
func (cli *Client) RegistryLogin(ctx context.Context, auth types.AuthConfig) (types.AuthResponse, error) { func (cli *Client) RegistryLogin(ctx context.Context, auth types.AuthConfig) (registry.AuthenticateOKBody, error) {
resp, err := cli.post(ctx, "/auth", url.Values{}, auth, nil) resp, err := cli.post(ctx, "/auth", url.Values{}, auth, nil)
if resp.statusCode == http.StatusUnauthorized { if resp.statusCode == http.StatusUnauthorized {
return types.AuthResponse{}, unauthorizedError{err} return registry.AuthenticateOKBody{}, unauthorizedError{err}
} }
if err != nil { if err != nil {
return types.AuthResponse{}, err return registry.AuthenticateOKBody{}, err
} }
var response types.AuthResponse var response registry.AuthenticateOKBody
err = json.NewDecoder(resp.body).Decode(&response) err = json.NewDecoder(resp.body).Decode(&response)
ensureReaderClosed(resp) ensureReaderClosed(resp)
return response, err return response, err

View file

@ -16,4 +16,5 @@ swagger generate operation -f api/swagger.yaml \
-n VolumesList \ -n VolumesList \
-n VolumesCreate \ -n VolumesCreate \
-n ContainerCreate \ -n ContainerCreate \
-n ContainerUpdate -n ContainerUpdate \
-n Authenticate