From f11de0f101aeb46a783bdb4375233f1dbfd9bf1f Mon Sep 17 00:00:00 2001 From: Vivian Brown Date: Fri, 8 May 2020 18:46:39 -0700 Subject: [PATCH 1/3] Add plugin_runs to open-api --- swagger.yml | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/swagger.yml b/swagger.yml index b3e0cded..cf5ee817 100644 --- a/swagger.yml +++ b/swagger.yml @@ -902,6 +902,26 @@ paths: $ref: '#/definitions/function' default: $ref: '#/responses/error' + /deploys/{deploy_id}/plugin_runs: + post: + operationId: createPluginRun + tags: [x-internal] + parameters: + - name: deploy_id + type: string + in: path + required: true + - name: plugin_run + in: body + schema: + $ref: '#/definitions/pluginRun' + responses: + '201': + description: CREATED + schema: + $ref: '#/definitions/pluginRun' + default: + $ref: '#/responses/error' /forms: get: operationId: listForms @@ -2259,6 +2279,25 @@ definitions: type: string error: type: boolean + pluginRun: + type: object + properties: + deploy_id: + type: string + package: + type: string + version: + type: string + state: + type: string + reporting_event: + type: string + title: + type: string + summary: + type: string + text: + type: string metadata: type: object dnsZoneSetup: From 8e2ac17bbbe8ef38403667f2bd0eec6a975e1fd8 Mon Sep 17 00:00:00 2001 From: Vivian Brown Date: Mon, 11 May 2020 11:32:01 -0700 Subject: [PATCH 2/3] Add description --- swagger.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/swagger.yml b/swagger.yml index cf5ee817..0a1027c2 100644 --- a/swagger.yml +++ b/swagger.yml @@ -906,6 +906,7 @@ paths: post: operationId: createPluginRun tags: [x-internal] + description: "This is an internal-only endpoint." parameters: - name: deploy_id type: string From e0fdc4a5a70807a2a6cf7660e7f254127a4c2cf6 Mon Sep 17 00:00:00 2001 From: Vivian Brown Date: Mon, 11 May 2020 11:32:49 -0700 Subject: [PATCH 3/3] Generate go --- go/models/plugin_run.go | 64 ++++++++ .../create_plugin_run_parameters.go | 154 ++++++++++++++++++ .../operations/create_plugin_run_responses.go | 118 ++++++++++++++ go/plumbing/operations/operations_client.go | 34 ++++ 4 files changed, 370 insertions(+) create mode 100644 go/models/plugin_run.go create mode 100644 go/plumbing/operations/create_plugin_run_parameters.go create mode 100644 go/plumbing/operations/create_plugin_run_responses.go diff --git a/go/models/plugin_run.go b/go/models/plugin_run.go new file mode 100644 index 00000000..bceb2b16 --- /dev/null +++ b/go/models/plugin_run.go @@ -0,0 +1,64 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + strfmt "github.com/go-openapi/strfmt" + + "github.com/go-openapi/swag" +) + +// PluginRun plugin run +// swagger:model pluginRun +type PluginRun struct { + + // deploy id + DeployID string `json:"deploy_id,omitempty"` + + // package + Package string `json:"package,omitempty"` + + // reporting event + ReportingEvent string `json:"reporting_event,omitempty"` + + // state + State string `json:"state,omitempty"` + + // summary + Summary string `json:"summary,omitempty"` + + // text + Text string `json:"text,omitempty"` + + // title + Title string `json:"title,omitempty"` + + // version + Version string `json:"version,omitempty"` +} + +// Validate validates this plugin run +func (m *PluginRun) Validate(formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (m *PluginRun) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *PluginRun) UnmarshalBinary(b []byte) error { + var res PluginRun + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/go/plumbing/operations/create_plugin_run_parameters.go b/go/plumbing/operations/create_plugin_run_parameters.go new file mode 100644 index 00000000..d27cd5f9 --- /dev/null +++ b/go/plumbing/operations/create_plugin_run_parameters.go @@ -0,0 +1,154 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package operations + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + "net/http" + "time" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + cr "github.com/go-openapi/runtime/client" + + strfmt "github.com/go-openapi/strfmt" + + models "github.com/netlify/open-api/go/models" +) + +// NewCreatePluginRunParams creates a new CreatePluginRunParams object +// with the default values initialized. +func NewCreatePluginRunParams() *CreatePluginRunParams { + var () + return &CreatePluginRunParams{ + + timeout: cr.DefaultTimeout, + } +} + +// NewCreatePluginRunParamsWithTimeout creates a new CreatePluginRunParams object +// with the default values initialized, and the ability to set a timeout on a request +func NewCreatePluginRunParamsWithTimeout(timeout time.Duration) *CreatePluginRunParams { + var () + return &CreatePluginRunParams{ + + timeout: timeout, + } +} + +// NewCreatePluginRunParamsWithContext creates a new CreatePluginRunParams object +// with the default values initialized, and the ability to set a context for a request +func NewCreatePluginRunParamsWithContext(ctx context.Context) *CreatePluginRunParams { + var () + return &CreatePluginRunParams{ + + Context: ctx, + } +} + +// NewCreatePluginRunParamsWithHTTPClient creates a new CreatePluginRunParams object +// with the default values initialized, and the ability to set a custom HTTPClient for a request +func NewCreatePluginRunParamsWithHTTPClient(client *http.Client) *CreatePluginRunParams { + var () + return &CreatePluginRunParams{ + HTTPClient: client, + } +} + +/*CreatePluginRunParams contains all the parameters to send to the API endpoint +for the create plugin run operation typically these are written to a http.Request +*/ +type CreatePluginRunParams struct { + + /*DeployID*/ + DeployID string + /*PluginRun*/ + PluginRun *models.PluginRun + + timeout time.Duration + Context context.Context + HTTPClient *http.Client +} + +// WithTimeout adds the timeout to the create plugin run params +func (o *CreatePluginRunParams) WithTimeout(timeout time.Duration) *CreatePluginRunParams { + o.SetTimeout(timeout) + return o +} + +// SetTimeout adds the timeout to the create plugin run params +func (o *CreatePluginRunParams) SetTimeout(timeout time.Duration) { + o.timeout = timeout +} + +// WithContext adds the context to the create plugin run params +func (o *CreatePluginRunParams) WithContext(ctx context.Context) *CreatePluginRunParams { + o.SetContext(ctx) + return o +} + +// SetContext adds the context to the create plugin run params +func (o *CreatePluginRunParams) SetContext(ctx context.Context) { + o.Context = ctx +} + +// WithHTTPClient adds the HTTPClient to the create plugin run params +func (o *CreatePluginRunParams) WithHTTPClient(client *http.Client) *CreatePluginRunParams { + o.SetHTTPClient(client) + return o +} + +// SetHTTPClient adds the HTTPClient to the create plugin run params +func (o *CreatePluginRunParams) SetHTTPClient(client *http.Client) { + o.HTTPClient = client +} + +// WithDeployID adds the deployID to the create plugin run params +func (o *CreatePluginRunParams) WithDeployID(deployID string) *CreatePluginRunParams { + o.SetDeployID(deployID) + return o +} + +// SetDeployID adds the deployId to the create plugin run params +func (o *CreatePluginRunParams) SetDeployID(deployID string) { + o.DeployID = deployID +} + +// WithPluginRun adds the pluginRun to the create plugin run params +func (o *CreatePluginRunParams) WithPluginRun(pluginRun *models.PluginRun) *CreatePluginRunParams { + o.SetPluginRun(pluginRun) + return o +} + +// SetPluginRun adds the pluginRun to the create plugin run params +func (o *CreatePluginRunParams) SetPluginRun(pluginRun *models.PluginRun) { + o.PluginRun = pluginRun +} + +// WriteToRequest writes these params to a swagger request +func (o *CreatePluginRunParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { + + if err := r.SetTimeout(o.timeout); err != nil { + return err + } + var res []error + + // path param deploy_id + if err := r.SetPathParam("deploy_id", o.DeployID); err != nil { + return err + } + + if o.PluginRun != nil { + if err := r.SetBodyParam(o.PluginRun); err != nil { + return err + } + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} diff --git a/go/plumbing/operations/create_plugin_run_responses.go b/go/plumbing/operations/create_plugin_run_responses.go new file mode 100644 index 00000000..938d8be7 --- /dev/null +++ b/go/plumbing/operations/create_plugin_run_responses.go @@ -0,0 +1,118 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package operations + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "fmt" + "io" + + "github.com/go-openapi/runtime" + + strfmt "github.com/go-openapi/strfmt" + + models "github.com/netlify/open-api/go/models" +) + +// CreatePluginRunReader is a Reader for the CreatePluginRun structure. +type CreatePluginRunReader struct { + formats strfmt.Registry +} + +// ReadResponse reads a server response into the received o. +func (o *CreatePluginRunReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { + switch response.Code() { + case 201: + result := NewCreatePluginRunCreated() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return result, nil + default: + result := NewCreatePluginRunDefault(response.Code()) + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + if response.Code()/100 == 2 { + return result, nil + } + return nil, result + } +} + +// NewCreatePluginRunCreated creates a CreatePluginRunCreated with default headers values +func NewCreatePluginRunCreated() *CreatePluginRunCreated { + return &CreatePluginRunCreated{} +} + +/*CreatePluginRunCreated handles this case with default header values. + +CREATED +*/ +type CreatePluginRunCreated struct { + Payload *models.PluginRun +} + +func (o *CreatePluginRunCreated) Error() string { + return fmt.Sprintf("[POST /deploys/{deploy_id}/plugin_runs][%d] createPluginRunCreated %+v", 201, o.Payload) +} + +func (o *CreatePluginRunCreated) GetPayload() *models.PluginRun { + return o.Payload +} + +func (o *CreatePluginRunCreated) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(models.PluginRun) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewCreatePluginRunDefault creates a CreatePluginRunDefault with default headers values +func NewCreatePluginRunDefault(code int) *CreatePluginRunDefault { + return &CreatePluginRunDefault{ + _statusCode: code, + } +} + +/*CreatePluginRunDefault handles this case with default header values. + +error +*/ +type CreatePluginRunDefault struct { + _statusCode int + + Payload *models.Error +} + +// Code gets the status code for the create plugin run default response +func (o *CreatePluginRunDefault) Code() int { + return o._statusCode +} + +func (o *CreatePluginRunDefault) Error() string { + return fmt.Sprintf("[POST /deploys/{deploy_id}/plugin_runs][%d] createPluginRun default %+v", o._statusCode, o.Payload) +} + +func (o *CreatePluginRunDefault) GetPayload() *models.Error { + return o.Payload +} + +func (o *CreatePluginRunDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(models.Error) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} diff --git a/go/plumbing/operations/operations_client.go b/go/plumbing/operations/operations_client.go index dbb7b4be..67fbd766 100644 --- a/go/plumbing/operations/operations_client.go +++ b/go/plumbing/operations/operations_client.go @@ -332,6 +332,40 @@ func (a *Client) CreateHookBySiteID(params *CreateHookBySiteIDParams, authInfo r return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code()) } +/* +CreatePluginRun This is an internal-only endpoint. +*/ +func (a *Client) CreatePluginRun(params *CreatePluginRunParams, authInfo runtime.ClientAuthInfoWriter) (*CreatePluginRunCreated, error) { + // TODO: Validate the params before sending + if params == nil { + params = NewCreatePluginRunParams() + } + + result, err := a.transport.Submit(&runtime.ClientOperation{ + ID: "createPluginRun", + Method: "POST", + PathPattern: "/deploys/{deploy_id}/plugin_runs", + ProducesMediaTypes: []string{"application/json"}, + ConsumesMediaTypes: []string{"application/json"}, + Schemes: []string{"https"}, + Params: params, + Reader: &CreatePluginRunReader{formats: a.formats}, + AuthInfo: authInfo, + Context: params.Context, + Client: params.HTTPClient, + }) + if err != nil { + return nil, err + } + success, ok := result.(*CreatePluginRunCreated) + if ok { + return success, nil + } + // unexpected success response + unexpectedSuccess := result.(*CreatePluginRunDefault) + return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code()) +} + /* CreateServiceInstance create service instance API */