Skip to content
This repository was archived by the owner on Aug 5, 2020. It is now read-only.

Commit b95c60c

Browse files
author
smothiki
committed
feat(swagger): add doctor api get spec
1 parent d8f48be commit b95c60c

7 files changed

Lines changed: 206 additions & 8 deletions

File tree

api/swagger-spec/swagger.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,18 @@ paths:
5555
/v3/doctor/{uuid}:
5656
parameters:
5757
- $ref: "#/parameters/UUID"
58+
get:
59+
operationId: getDoctorInfo
60+
summary: "get the specified doctor report as per UUID"
61+
responses:
62+
200:
63+
description: doctor get response
64+
schema:
65+
$ref: "#/definitions/doctorInfo"
66+
default:
67+
description: unexpected error
68+
schema:
69+
$ref: "#/definitions/error"
5870
post:
5971
operationId: publishDoctorInfo
6072
summary: "publish doctor info to Workflow Manager API"

boot.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func main() {
5454
defer close(ch)
5555

5656
// Get a new router, with handler functions
57-
r := handlers.RegisterRoutes(mux.NewRouter(), secretInterface, rcInterface, availableVersion, apiClient)
57+
r := handlers.RegisterRoutes(mux.NewRouter(), secretInterface, rcInterface, availableVersion)
5858
// Bind to a port and pass our router in
5959
hostStr := fmt.Sprintf(":%s", config.Spec.Port)
6060
log.Printf("Serving on %s", hostStr)

data/data.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,10 @@ func GetDoctorInfo(
160160
) (models.DoctorInfo, error) {
161161
cluster, err := GetCluster(c, i, v, secretGetterCreator)
162162
if err != nil {
163-
return nil, err
163+
return models.DoctorInfo{}, err
164164
}
165165
doctor := models.DoctorInfo{
166-
cluster: &cluster,
166+
Cluster: &cluster,
167167
}
168168
return doctor, nil
169169
}

handlers/handlers.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"net/http"
77

88
"github.com/arschles/kubeapp/api/rc"
9+
"github.com/deis/workflow-manager/config"
910
"github.com/deis/workflow-manager/data"
1011
"github.com/deis/workflow-manager/pkg/swagger/client/operations"
1112
"github.com/gorilla/mux"
@@ -24,7 +25,6 @@ func RegisterRoutes(
2425
secretGetterCreator data.KubeSecretGetterCreator,
2526
rcLister rc.Lister,
2627
availableVersions data.AvailableVersions,
27-
apiClient *apiclient.WorkflowManager,
2828
) *mux.Router {
2929

3030
clusterID := data.NewClusterIDFromPersistentStorage(secretGetterCreator)
@@ -40,8 +40,7 @@ func RegisterRoutes(
4040
clusterID,
4141
data.NewLatestReleasedComponent(secretGetterCreator, rcLister, availableVersions),
4242
secretGetterCreator,
43-
apiclient,
44-
))
43+
)).Methods("POST")
4544
return r
4645
}
4746

@@ -70,19 +69,21 @@ func DoctorHandler(
7069
i data.ClusterID,
7170
v data.AvailableComponentVersion,
7271
secretGetterCreator data.KubeSecretGetterCreator,
73-
apiClient *apiclient.WorkflowManager,
7472
) http.Handler {
7573
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
7674
doctor, err := data.GetDoctorInfo(c, i, v, secretGetterCreator)
7775
if err != nil {
7876
http.Error(w, err.Error(), http.StatusInternalServerError)
7977
return
8078
}
81-
_, err = apiClient.Operations.PublishDoctorInfo(&operations.PublishDoctorInfoParams{Body: doctor, UUID: uuid.NewV4().String()})
79+
apiClient, err := config.GetSwaggerClient(config.Spec.DoctorAPIURL)
80+
uid := uuid.NewV4().String()
81+
_, err = apiClient.Operations.PublishDoctorInfo(&operations.PublishDoctorInfoParams{Body: &doctor, UUID: uid})
8282
if err != nil {
8383
http.Error(w, err.Error(), http.StatusInternalServerError)
8484
return
8585
}
86+
writePlainText(uid, w)
8687
})
8788
}
8889

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package operations
2+
3+
// This file was generated by the swagger tool.
4+
// Editing this file might prove futile when you re-run the swagger generate command
5+
6+
import (
7+
"github.com/go-swagger/go-swagger/client"
8+
"github.com/go-swagger/go-swagger/errors"
9+
10+
strfmt "github.com/go-swagger/go-swagger/strfmt"
11+
)
12+
13+
// NewGetDoctorInfoParams creates a new GetDoctorInfoParams object
14+
// with the default values initialized.
15+
func NewGetDoctorInfoParams() *GetDoctorInfoParams {
16+
var ()
17+
return &GetDoctorInfoParams{}
18+
}
19+
20+
/*GetDoctorInfoParams contains all the parameters to send to the API endpoint
21+
for the get doctor info operation typically these are written to a http.Request
22+
*/
23+
type GetDoctorInfoParams struct {
24+
25+
/*UUID
26+
A universal Id to represent a sepcific request or report
27+
28+
*/
29+
UUID string
30+
}
31+
32+
// WithUUID adds the uuid to the get doctor info params
33+
func (o *GetDoctorInfoParams) WithUUID(uuid string) *GetDoctorInfoParams {
34+
o.UUID = uuid
35+
return o
36+
}
37+
38+
// WriteToRequest writes these params to a swagger request
39+
func (o *GetDoctorInfoParams) WriteToRequest(r client.Request, reg strfmt.Registry) error {
40+
41+
var res []error
42+
43+
// path param uuid
44+
if err := r.SetPathParam("uuid", o.UUID); err != nil {
45+
return err
46+
}
47+
48+
if len(res) > 0 {
49+
return errors.CompositeValidationError(res...)
50+
}
51+
return nil
52+
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
package operations
2+
3+
// This file was generated by the swagger tool.
4+
// Editing this file might prove futile when you re-run the swagger generate command
5+
6+
import (
7+
"fmt"
8+
"io"
9+
10+
"github.com/go-swagger/go-swagger/client"
11+
"github.com/go-swagger/go-swagger/httpkit"
12+
13+
strfmt "github.com/go-swagger/go-swagger/strfmt"
14+
15+
"github.com/deis/workflow-manager/pkg/swagger/models"
16+
)
17+
18+
// GetDoctorInfoReader is a Reader for the GetDoctorInfo structure.
19+
type GetDoctorInfoReader struct {
20+
formats strfmt.Registry
21+
}
22+
23+
// ReadResponse reads a server response into the recieved o.
24+
func (o *GetDoctorInfoReader) ReadResponse(response client.Response, consumer httpkit.Consumer) (interface{}, error) {
25+
switch response.Code() {
26+
27+
case 200:
28+
result := NewGetDoctorInfoOK()
29+
if err := result.readResponse(response, consumer, o.formats); err != nil {
30+
return nil, err
31+
}
32+
return result, nil
33+
34+
default:
35+
result := NewGetDoctorInfoDefault(response.Code())
36+
if err := result.readResponse(response, consumer, o.formats); err != nil {
37+
return nil, err
38+
}
39+
return nil, result
40+
}
41+
}
42+
43+
// NewGetDoctorInfoOK creates a GetDoctorInfoOK with default headers values
44+
func NewGetDoctorInfoOK() *GetDoctorInfoOK {
45+
return &GetDoctorInfoOK{}
46+
}
47+
48+
/*GetDoctorInfoOK handles this case with default header values.
49+
50+
doctor get response
51+
*/
52+
type GetDoctorInfoOK struct {
53+
Payload *models.DoctorInfo
54+
}
55+
56+
func (o *GetDoctorInfoOK) Error() string {
57+
return fmt.Sprintf("[GET /v3/doctor/{uuid}][%d] getDoctorInfoOK %+v", 200, o.Payload)
58+
}
59+
60+
func (o *GetDoctorInfoOK) readResponse(response client.Response, consumer httpkit.Consumer, formats strfmt.Registry) error {
61+
62+
o.Payload = new(models.DoctorInfo)
63+
64+
// response payload
65+
if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
66+
return err
67+
}
68+
69+
return nil
70+
}
71+
72+
// NewGetDoctorInfoDefault creates a GetDoctorInfoDefault with default headers values
73+
func NewGetDoctorInfoDefault(code int) *GetDoctorInfoDefault {
74+
return &GetDoctorInfoDefault{
75+
_statusCode: code,
76+
}
77+
}
78+
79+
/*GetDoctorInfoDefault handles this case with default header values.
80+
81+
unexpected error
82+
*/
83+
type GetDoctorInfoDefault struct {
84+
_statusCode int
85+
86+
Payload *models.Error
87+
}
88+
89+
// Code gets the status code for the get doctor info default response
90+
func (o *GetDoctorInfoDefault) Code() int {
91+
return o._statusCode
92+
}
93+
94+
func (o *GetDoctorInfoDefault) Error() string {
95+
return fmt.Sprintf("[GET /v3/doctor/{uuid}][%d] getDoctorInfo default %+v", o._statusCode, o.Payload)
96+
}
97+
98+
func (o *GetDoctorInfoDefault) readResponse(response client.Response, consumer httpkit.Consumer, formats strfmt.Registry) error {
99+
100+
o.Payload = new(models.Error)
101+
102+
// response payload
103+
if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
104+
return err
105+
}
106+
107+
return nil
108+
}

pkg/swagger/client/operations/operations_client.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,31 @@ func (a *Client) GetComponentsByLatestReleaseForV2(params *GetComponentsByLatest
247247
return result.(*GetComponentsByLatestReleaseForV2OK), nil
248248
}
249249

250+
/*
251+
GetDoctorInfo gets the specified doctor report as per UUID
252+
*/
253+
func (a *Client) GetDoctorInfo(params *GetDoctorInfoParams) (*GetDoctorInfoOK, error) {
254+
// TODO: Validate the params before sending
255+
if params == nil {
256+
params = NewGetDoctorInfoParams()
257+
}
258+
259+
result, err := a.transport.Submit(&client.Operation{
260+
ID: "getDoctorInfo",
261+
Method: "GET",
262+
PathPattern: "/v3/doctor/{uuid}",
263+
ProducesMediaTypes: []string{"application/json"},
264+
ConsumesMediaTypes: []string{"application/json"},
265+
Schemes: []string{"http"},
266+
Params: params,
267+
Reader: &GetDoctorInfoReader{formats: a.formats},
268+
})
269+
if err != nil {
270+
return nil, err
271+
}
272+
return result.(*GetDoctorInfoOK), nil
273+
}
274+
250275
/*
251276
Ping pings the versions API server
252277
*/

0 commit comments

Comments
 (0)