Browse code

generate AuthResponse type from swagger spec.

Signed-off-by: Daniel Nephin <dnephin@docker.com>

Daniel Nephin authored on 2016/10/19 09:52:46
Showing 7 changed files
... ...
@@ -13,6 +13,7 @@ import (
13 13
 	"github.com/docker/docker/api/types"
14 14
 	"github.com/docker/docker/api/types/events"
15 15
 	"github.com/docker/docker/api/types/filters"
16
+	"github.com/docker/docker/api/types/registry"
16 17
 	timetypes "github.com/docker/docker/api/types/time"
17 18
 	"github.com/docker/docker/api/types/versions"
18 19
 	"github.com/docker/docker/pkg/ioutils"
... ...
@@ -154,7 +155,7 @@ func (s *systemRouter) postAuth(ctx context.Context, w http.ResponseWriter, r *h
154 154
 	if err != nil {
155 155
 		return err
156 156
 	}
157
-	return httputils.WriteJSON(w, http.StatusOK, &types.AuthResponse{
157
+	return httputils.WriteJSON(w, http.StatusOK, &registry.AuthenticateOKBody{
158 158
 		Status:        status,
159 159
 		IdentityToken: token,
160 160
 	})
... ...
@@ -4612,23 +4612,24 @@ paths:
4612 4612
     post:
4613 4613
       summary: "Check auth configuration"
4614 4614
       description: "Validate credentials for a registry and, if available, get an identity token for accessing the registry without password."
4615
-      operationId: "checkAuthentication"
4616
-      consumes:
4617
-        - "application/json"
4618
-      produces:
4619
-        - "application/json"
4615
+      operationId: "Authenticate"
4616
+      consumes: ["application/json"]
4617
+      produces: ["application/json"]
4620 4618
       responses:
4621 4619
         200:
4622
-          description: "No error"
4620
+          description: "An identity token was generated successfully."
4623 4621
           schema:
4624 4622
             type: "object"
4623
+            required: [Status]
4625 4624
             properties:
4626 4625
               Status:
4627 4626
                 description: "The status of the authentication"
4628 4627
                 type: "string"
4628
+                x-nullable: false
4629 4629
               IdentityToken:
4630 4630
                 description: "An opaque token used to authenticate a user after a successful login"
4631 4631
                 type: "string"
4632
+                x-nullable: false
4632 4633
           examples:
4633 4634
             application/json:
4634 4635
               Status: "Login Succeeded"
... ...
@@ -4645,8 +4646,7 @@ paths:
4645 4645
           description: "Authentication to check"
4646 4646
           schema:
4647 4647
             $ref: "#/definitions/AuthConfig"
4648
-      tags:
4649
-        - "Misc"
4648
+      tags: ["Registry"]
4650 4649
   /info:
4651 4650
     get:
4652 4651
       summary: "Get system information"
4653 4652
new file mode 100644
... ...
@@ -0,0 +1,21 @@
0
+package registry
1
+
2
+// ----------------------------------------------------------------------------
3
+// DO NOT EDIT THIS FILE
4
+// This file was generated by `swagger generate operation`
5
+//
6
+// See hack/swagger-gen.sh
7
+// ----------------------------------------------------------------------------
8
+
9
+// AuthenticateOKBody authenticate o k body
10
+// swagger:model AuthenticateOKBody
11
+type AuthenticateOKBody struct {
12
+
13
+	// An opaque token used to authenticate a user after a successful login
14
+	// Required: true
15
+	IdentityToken string `json:"IdentityToken"`
16
+
17
+	// The status of the authentication
18
+	// Required: true
19
+	Status string `json:"Status"`
20
+}
... ...
@@ -13,17 +13,6 @@ import (
13 13
 	"github.com/docker/go-connections/nat"
14 14
 )
15 15
 
16
-// AuthResponse contains response of Remote API:
17
-// POST "/auth"
18
-type AuthResponse struct {
19
-	// Status is the authentication status
20
-	Status string `json:"Status"`
21
-
22
-	// IdentityToken is an opaque token used for authenticating
23
-	// a user after a successful login.
24
-	IdentityToken string `json:"IdentityToken,omitempty"`
25
-}
26
-
27 16
 // ContainerWaitResponse contains response of Remote API:
28 17
 // POST "/containers/"+containerID+"/wait"
29 18
 type ContainerWaitResponse struct {
... ...
@@ -127,7 +127,7 @@ type SwarmAPIClient interface {
127 127
 type SystemAPIClient interface {
128 128
 	Events(ctx context.Context, options types.EventsOptions) (<-chan events.Message, <-chan error)
129 129
 	Info(ctx context.Context) (types.Info, error)
130
-	RegistryLogin(ctx context.Context, auth types.AuthConfig) (types.AuthResponse, error)
130
+	RegistryLogin(ctx context.Context, auth types.AuthConfig) (registry.AuthenticateOKBody, error)
131 131
 	DiskUsage(ctx context.Context) (types.DiskUsage, error)
132 132
 	Ping(ctx context.Context) (bool, error)
133 133
 }
... ...
@@ -6,22 +6,23 @@ import (
6 6
 	"net/url"
7 7
 
8 8
 	"github.com/docker/docker/api/types"
9
+	"github.com/docker/docker/api/types/registry"
9 10
 	"golang.org/x/net/context"
10 11
 )
11 12
 
12 13
 // RegistryLogin authenticates the docker server with a given docker registry.
13 14
 // It returns UnauthorizerError when the authentication fails.
14
-func (cli *Client) RegistryLogin(ctx context.Context, auth types.AuthConfig) (types.AuthResponse, error) {
15
+func (cli *Client) RegistryLogin(ctx context.Context, auth types.AuthConfig) (registry.AuthenticateOKBody, error) {
15 16
 	resp, err := cli.post(ctx, "/auth", url.Values{}, auth, nil)
16 17
 
17 18
 	if resp.statusCode == http.StatusUnauthorized {
18
-		return types.AuthResponse{}, unauthorizedError{err}
19
+		return registry.AuthenticateOKBody{}, unauthorizedError{err}
19 20
 	}
20 21
 	if err != nil {
21
-		return types.AuthResponse{}, err
22
+		return registry.AuthenticateOKBody{}, err
22 23
 	}
23 24
 
24
-	var response types.AuthResponse
25
+	var response registry.AuthenticateOKBody
25 26
 	err = json.NewDecoder(resp.body).Decode(&response)
26 27
 	ensureReaderClosed(resp)
27 28
 	return response, err
... ...
@@ -16,4 +16,5 @@ swagger generate operation -f api/swagger.yaml \
16 16
     -n VolumesList \
17 17
     -n VolumesCreate \
18 18
     -n ContainerCreate \
19
-    -n ContainerUpdate
19
+    -n ContainerUpdate \
20
+    -n Authenticate