From 2b4a4ed20927882408e5349e0915e427fbf47912 Mon Sep 17 00:00:00 2001 From: Markus Wennrich Date: Mon, 26 Jul 2021 16:00:26 +0200 Subject: [PATCH] adapt to metal-api:images-by-os (#69) --- api/client/image/image_client.go | 40 +++++ .../image/query_images_by_id_parameters.go | 149 ++++++++++++++++++ .../image/query_images_by_id_responses.go | 114 ++++++++++++++ go.sum | 2 - image.go | 13 ++ metal-api.json | 41 +++++ 6 files changed, 357 insertions(+), 2 deletions(-) create mode 100644 api/client/image/query_images_by_id_parameters.go create mode 100644 api/client/image/query_images_by_id_responses.go diff --git a/api/client/image/image_client.go b/api/client/image/image_client.go index 6ef1060f..980bfa4c 100644 --- a/api/client/image/image_client.go +++ b/api/client/image/image_client.go @@ -38,6 +38,8 @@ type ClientService interface { ListImages(params *ListImagesParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*ListImagesOK, error) + QueryImagesByID(params *QueryImagesByIDParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*QueryImagesByIDOK, error) + UpdateImage(params *UpdateImageParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*UpdateImageOK, error) SetTransport(transport runtime.ClientTransport) @@ -233,6 +235,44 @@ func (a *Client) ListImages(params *ListImagesParams, authInfo runtime.ClientAut return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code()) } +/* + QueryImagesByID queries all images which match at least id +*/ +func (a *Client) QueryImagesByID(params *QueryImagesByIDParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*QueryImagesByIDOK, error) { + // TODO: Validate the params before sending + if params == nil { + params = NewQueryImagesByIDParams() + } + op := &runtime.ClientOperation{ + ID: "queryImages by id", + Method: "GET", + PathPattern: "/v1/image/{id}/query", + ProducesMediaTypes: []string{"application/json"}, + ConsumesMediaTypes: []string{"application/json"}, + Schemes: []string{"http"}, + Params: params, + Reader: &QueryImagesByIDReader{formats: a.formats}, + AuthInfo: authInfo, + Context: params.Context, + Client: params.HTTPClient, + } + for _, opt := range opts { + opt(op) + } + + result, err := a.transport.Submit(op) + if err != nil { + return nil, err + } + success, ok := result.(*QueryImagesByIDOK) + if ok { + return success, nil + } + // unexpected success response + unexpectedSuccess := result.(*QueryImagesByIDDefault) + return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code()) +} + /* UpdateImage updates an image if the image was changed since this one was read a conflict is returned */ diff --git a/api/client/image/query_images_by_id_parameters.go b/api/client/image/query_images_by_id_parameters.go new file mode 100644 index 00000000..8fb246d8 --- /dev/null +++ b/api/client/image/query_images_by_id_parameters.go @@ -0,0 +1,149 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package image + +// 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" + "github.com/go-openapi/strfmt" +) + +// NewQueryImagesByIDParams creates a new QueryImagesByIDParams object, +// with the default timeout for this client. +// +// Default values are not hydrated, since defaults are normally applied by the API server side. +// +// To enforce default values in parameter, use SetDefaults or WithDefaults. +func NewQueryImagesByIDParams() *QueryImagesByIDParams { + return &QueryImagesByIDParams{ + timeout: cr.DefaultTimeout, + } +} + +// NewQueryImagesByIDParamsWithTimeout creates a new QueryImagesByIDParams object +// with the ability to set a timeout on a request. +func NewQueryImagesByIDParamsWithTimeout(timeout time.Duration) *QueryImagesByIDParams { + return &QueryImagesByIDParams{ + timeout: timeout, + } +} + +// NewQueryImagesByIDParamsWithContext creates a new QueryImagesByIDParams object +// with the ability to set a context for a request. +func NewQueryImagesByIDParamsWithContext(ctx context.Context) *QueryImagesByIDParams { + return &QueryImagesByIDParams{ + Context: ctx, + } +} + +// NewQueryImagesByIDParamsWithHTTPClient creates a new QueryImagesByIDParams object +// with the ability to set a custom HTTPClient for a request. +func NewQueryImagesByIDParamsWithHTTPClient(client *http.Client) *QueryImagesByIDParams { + return &QueryImagesByIDParams{ + HTTPClient: client, + } +} + +/* QueryImagesByIDParams contains all the parameters to send to the API endpoint + for the query images by id operation. + + Typically these are written to a http.Request. +*/ +type QueryImagesByIDParams struct { + + /* ID. + + identifier of the image + */ + ID string + + timeout time.Duration + Context context.Context + HTTPClient *http.Client +} + +// WithDefaults hydrates default values in the query images by id params (not the query body). +// +// All values with no default are reset to their zero value. +func (o *QueryImagesByIDParams) WithDefaults() *QueryImagesByIDParams { + o.SetDefaults() + return o +} + +// SetDefaults hydrates default values in the query images by id params (not the query body). +// +// All values with no default are reset to their zero value. +func (o *QueryImagesByIDParams) SetDefaults() { + // no default values defined for this parameter +} + +// WithTimeout adds the timeout to the query images by id params +func (o *QueryImagesByIDParams) WithTimeout(timeout time.Duration) *QueryImagesByIDParams { + o.SetTimeout(timeout) + return o +} + +// SetTimeout adds the timeout to the query images by id params +func (o *QueryImagesByIDParams) SetTimeout(timeout time.Duration) { + o.timeout = timeout +} + +// WithContext adds the context to the query images by id params +func (o *QueryImagesByIDParams) WithContext(ctx context.Context) *QueryImagesByIDParams { + o.SetContext(ctx) + return o +} + +// SetContext adds the context to the query images by id params +func (o *QueryImagesByIDParams) SetContext(ctx context.Context) { + o.Context = ctx +} + +// WithHTTPClient adds the HTTPClient to the query images by id params +func (o *QueryImagesByIDParams) WithHTTPClient(client *http.Client) *QueryImagesByIDParams { + o.SetHTTPClient(client) + return o +} + +// SetHTTPClient adds the HTTPClient to the query images by id params +func (o *QueryImagesByIDParams) SetHTTPClient(client *http.Client) { + o.HTTPClient = client +} + +// WithID adds the id to the query images by id params +func (o *QueryImagesByIDParams) WithID(id string) *QueryImagesByIDParams { + o.SetID(id) + return o +} + +// SetID adds the id to the query images by id params +func (o *QueryImagesByIDParams) SetID(id string) { + o.ID = id +} + +// WriteToRequest writes these params to a swagger request +func (o *QueryImagesByIDParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { + + if err := r.SetTimeout(o.timeout); err != nil { + return err + } + var res []error + + // path param id + if err := r.SetPathParam("id", o.ID); err != nil { + return err + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} diff --git a/api/client/image/query_images_by_id_responses.go b/api/client/image/query_images_by_id_responses.go new file mode 100644 index 00000000..a1c576b4 --- /dev/null +++ b/api/client/image/query_images_by_id_responses.go @@ -0,0 +1,114 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package image + +// 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" + "github.com/go-openapi/strfmt" + + "github.com/metal-stack/metal-go/api/models" + "github.com/metal-stack/metal-lib/httperrors" +) + +// QueryImagesByIDReader is a Reader for the QueryImagesByID structure. +type QueryImagesByIDReader struct { + formats strfmt.Registry +} + +// ReadResponse reads a server response into the received o. +func (o *QueryImagesByIDReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { + switch response.Code() { + case 200: + result := NewQueryImagesByIDOK() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return result, nil + default: + result := NewQueryImagesByIDDefault(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 + } +} + +// NewQueryImagesByIDOK creates a QueryImagesByIDOK with default headers values +func NewQueryImagesByIDOK() *QueryImagesByIDOK { + return &QueryImagesByIDOK{} +} + +/* QueryImagesByIDOK describes a response with status code 200, with default header values. + +OK +*/ +type QueryImagesByIDOK struct { + Payload []*models.V1ImageResponse +} + +func (o *QueryImagesByIDOK) Error() string { + return fmt.Sprintf("[GET /v1/image/{id}/query][%d] queryImagesByIdOK %+v", 200, o.Payload) +} +func (o *QueryImagesByIDOK) GetPayload() []*models.V1ImageResponse { + return o.Payload +} + +func (o *QueryImagesByIDOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + // response payload + if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewQueryImagesByIDDefault creates a QueryImagesByIDDefault with default headers values +func NewQueryImagesByIDDefault(code int) *QueryImagesByIDDefault { + return &QueryImagesByIDDefault{ + _statusCode: code, + } +} + +/* QueryImagesByIDDefault describes a response with status code -1, with default header values. + +Error +*/ +type QueryImagesByIDDefault struct { + _statusCode int + + Payload *httperrors.HTTPErrorResponse +} + +// Code gets the status code for the query images by id default response +func (o *QueryImagesByIDDefault) Code() int { + return o._statusCode +} + +func (o *QueryImagesByIDDefault) Error() string { + return fmt.Sprintf("[GET /v1/image/{id}/query][%d] queryImages by id default %+v", o._statusCode, o.Payload) +} +func (o *QueryImagesByIDDefault) GetPayload() *httperrors.HTTPErrorResponse { + return o.Payload +} + +func (o *QueryImagesByIDDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(httperrors.HTTPErrorResponse) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} diff --git a/go.sum b/go.sum index b987109f..b4fde0aa 100644 --- a/go.sum +++ b/go.sum @@ -869,8 +869,6 @@ github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635/go.mod h1:hkRG github.com/tchap/go-patricia v2.2.6+incompatible/go.mod h1:bmLyhP68RS6kStMGxByiQ23RP/odRBOTVjwp2cDyi6I= github.com/testcontainers/testcontainers-go v0.11.0/go.mod h1:HztBCODzuA+YpMXGK8amjO8j50jz2gcT0BOzSKUiYIs= github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= -github.com/tidwall/pretty v1.1.0 h1:K3hMW5epkdAVwibsQEfR/7Zj0Qgt4DxtNumTq/VloO8= -github.com/tidwall/pretty v1.1.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs= github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= diff --git a/image.go b/image.go index e8b0064d..6d0ffcf1 100644 --- a/image.go +++ b/image.go @@ -46,6 +46,19 @@ func (d *Driver) ImageList() (*ImageListResponse, error) { return response, nil } +// ImageQueryByID return all machine images +func (d *Driver) ImageQueryByID(imageID string) (*ImageListResponse, error) { + response := &ImageListResponse{} + request := image.NewQueryImagesByIDParams() + request.ID = imageID + resp, err := d.image.QueryImagesByID(request, nil) + if err != nil { + return response, err + } + response.Image = resp.Payload + return response, nil +} + // ImageGet return a image func (d *Driver) ImageGet(imageID string) (*ImageGetResponse, error) { response := &ImageGetResponse{} diff --git a/metal-api.json b/metal-api.json index b75ac44e..ef1c89f8 100644 --- a/metal-api.json +++ b/metal-api.json @@ -5111,6 +5111,47 @@ ] } }, + "/v1/image/{id}/query": { + "get": { + "consumes": [ + "application/json" + ], + "operationId": "queryImages by id", + "parameters": [ + { + "description": "identifier of the image", + "in": "path", + "name": "id", + "required": true, + "type": "string" + } + ], + "produces": [ + "application/json" + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "items": { + "$ref": "#/definitions/v1.ImageResponse" + }, + "type": "array" + } + }, + "default": { + "description": "Error", + "schema": { + "$ref": "#/definitions/httperrors.HTTPErrorResponse" + } + } + }, + "summary": "query all images which match at least id", + "tags": [ + "image" + ] + } + }, "/v1/ip": { "get": { "consumes": [