From 162b3733b46149c0fc001bb8ba2f6a8ea7d27861 Mon Sep 17 00:00:00 2001 From: "Pilz, Alexander" Date: Fri, 6 Oct 2023 08:40:07 +0200 Subject: [PATCH] Add getTenantHistory endpoint to api --- .../tenant/get_tenant_history_parameters.go | 172 ++++++++++++++++ .../tenant/get_tenant_history_responses.go | 183 ++++++++++++++++++ api/client/tenant/tenant_client.go | 40 ++++ api/models/v1_tenant_get_history_request.go | 74 +++++++ metal-api.json | 54 ++++++ 5 files changed, 523 insertions(+) create mode 100644 api/client/tenant/get_tenant_history_parameters.go create mode 100644 api/client/tenant/get_tenant_history_responses.go create mode 100644 api/models/v1_tenant_get_history_request.go diff --git a/api/client/tenant/get_tenant_history_parameters.go b/api/client/tenant/get_tenant_history_parameters.go new file mode 100644 index 00000000..6c194856 --- /dev/null +++ b/api/client/tenant/get_tenant_history_parameters.go @@ -0,0 +1,172 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package tenant + +// 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" + + "github.com/metal-stack/metal-go/api/models" +) + +// NewGetTenantHistoryParams creates a new GetTenantHistoryParams 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 NewGetTenantHistoryParams() *GetTenantHistoryParams { + return &GetTenantHistoryParams{ + timeout: cr.DefaultTimeout, + } +} + +// NewGetTenantHistoryParamsWithTimeout creates a new GetTenantHistoryParams object +// with the ability to set a timeout on a request. +func NewGetTenantHistoryParamsWithTimeout(timeout time.Duration) *GetTenantHistoryParams { + return &GetTenantHistoryParams{ + timeout: timeout, + } +} + +// NewGetTenantHistoryParamsWithContext creates a new GetTenantHistoryParams object +// with the ability to set a context for a request. +func NewGetTenantHistoryParamsWithContext(ctx context.Context) *GetTenantHistoryParams { + return &GetTenantHistoryParams{ + Context: ctx, + } +} + +// NewGetTenantHistoryParamsWithHTTPClient creates a new GetTenantHistoryParams object +// with the ability to set a custom HTTPClient for a request. +func NewGetTenantHistoryParamsWithHTTPClient(client *http.Client) *GetTenantHistoryParams { + return &GetTenantHistoryParams{ + HTTPClient: client, + } +} + +/* +GetTenantHistoryParams contains all the parameters to send to the API endpoint + + for the get tenant history operation. + + Typically these are written to a http.Request. +*/ +type GetTenantHistoryParams struct { + + // Body. + Body *models.V1TenantGetHistoryRequest + + /* ID. + + identifier of the tenant + */ + ID string + + timeout time.Duration + Context context.Context + HTTPClient *http.Client +} + +// WithDefaults hydrates default values in the get tenant history params (not the query body). +// +// All values with no default are reset to their zero value. +func (o *GetTenantHistoryParams) WithDefaults() *GetTenantHistoryParams { + o.SetDefaults() + return o +} + +// SetDefaults hydrates default values in the get tenant history params (not the query body). +// +// All values with no default are reset to their zero value. +func (o *GetTenantHistoryParams) SetDefaults() { + // no default values defined for this parameter +} + +// WithTimeout adds the timeout to the get tenant history params +func (o *GetTenantHistoryParams) WithTimeout(timeout time.Duration) *GetTenantHistoryParams { + o.SetTimeout(timeout) + return o +} + +// SetTimeout adds the timeout to the get tenant history params +func (o *GetTenantHistoryParams) SetTimeout(timeout time.Duration) { + o.timeout = timeout +} + +// WithContext adds the context to the get tenant history params +func (o *GetTenantHistoryParams) WithContext(ctx context.Context) *GetTenantHistoryParams { + o.SetContext(ctx) + return o +} + +// SetContext adds the context to the get tenant history params +func (o *GetTenantHistoryParams) SetContext(ctx context.Context) { + o.Context = ctx +} + +// WithHTTPClient adds the HTTPClient to the get tenant history params +func (o *GetTenantHistoryParams) WithHTTPClient(client *http.Client) *GetTenantHistoryParams { + o.SetHTTPClient(client) + return o +} + +// SetHTTPClient adds the HTTPClient to the get tenant history params +func (o *GetTenantHistoryParams) SetHTTPClient(client *http.Client) { + o.HTTPClient = client +} + +// WithBody adds the body to the get tenant history params +func (o *GetTenantHistoryParams) WithBody(body *models.V1TenantGetHistoryRequest) *GetTenantHistoryParams { + o.SetBody(body) + return o +} + +// SetBody adds the body to the get tenant history params +func (o *GetTenantHistoryParams) SetBody(body *models.V1TenantGetHistoryRequest) { + o.Body = body +} + +// WithID adds the id to the get tenant history params +func (o *GetTenantHistoryParams) WithID(id string) *GetTenantHistoryParams { + o.SetID(id) + return o +} + +// SetID adds the id to the get tenant history params +func (o *GetTenantHistoryParams) SetID(id string) { + o.ID = id +} + +// WriteToRequest writes these params to a swagger request +func (o *GetTenantHistoryParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { + + if err := r.SetTimeout(o.timeout); err != nil { + return err + } + var res []error + if o.Body != nil { + if err := r.SetBodyParam(o.Body); err != nil { + return err + } + } + + // 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/tenant/get_tenant_history_responses.go b/api/client/tenant/get_tenant_history_responses.go new file mode 100644 index 00000000..8b7a5c11 --- /dev/null +++ b/api/client/tenant/get_tenant_history_responses.go @@ -0,0 +1,183 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package tenant + +// 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" +) + +// GetTenantHistoryReader is a Reader for the GetTenantHistory structure. +type GetTenantHistoryReader struct { + formats strfmt.Registry +} + +// ReadResponse reads a server response into the received o. +func (o *GetTenantHistoryReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { + switch response.Code() { + case 200: + result := NewGetTenantHistoryOK() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return result, nil + default: + result := NewGetTenantHistoryDefault(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 + } +} + +// NewGetTenantHistoryOK creates a GetTenantHistoryOK with default headers values +func NewGetTenantHistoryOK() *GetTenantHistoryOK { + return &GetTenantHistoryOK{} +} + +/* +GetTenantHistoryOK describes a response with status code 200, with default header values. + +OK +*/ +type GetTenantHistoryOK struct { + Payload *models.V1TenantResponse +} + +// IsSuccess returns true when this get tenant history o k response has a 2xx status code +func (o *GetTenantHistoryOK) IsSuccess() bool { + return true +} + +// IsRedirect returns true when this get tenant history o k response has a 3xx status code +func (o *GetTenantHistoryOK) IsRedirect() bool { + return false +} + +// IsClientError returns true when this get tenant history o k response has a 4xx status code +func (o *GetTenantHistoryOK) IsClientError() bool { + return false +} + +// IsServerError returns true when this get tenant history o k response has a 5xx status code +func (o *GetTenantHistoryOK) IsServerError() bool { + return false +} + +// IsCode returns true when this get tenant history o k response a status code equal to that given +func (o *GetTenantHistoryOK) IsCode(code int) bool { + return code == 200 +} + +// Code gets the status code for the get tenant history o k response +func (o *GetTenantHistoryOK) Code() int { + return 200 +} + +func (o *GetTenantHistoryOK) Error() string { + return fmt.Sprintf("[POST /v1/tenant/{id}/history][%d] getTenantHistoryOK %+v", 200, o.Payload) +} + +func (o *GetTenantHistoryOK) String() string { + return fmt.Sprintf("[POST /v1/tenant/{id}/history][%d] getTenantHistoryOK %+v", 200, o.Payload) +} + +func (o *GetTenantHistoryOK) GetPayload() *models.V1TenantResponse { + return o.Payload +} + +func (o *GetTenantHistoryOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(models.V1TenantResponse) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewGetTenantHistoryDefault creates a GetTenantHistoryDefault with default headers values +func NewGetTenantHistoryDefault(code int) *GetTenantHistoryDefault { + return &GetTenantHistoryDefault{ + _statusCode: code, + } +} + +/* +GetTenantHistoryDefault describes a response with status code -1, with default header values. + +Error +*/ +type GetTenantHistoryDefault struct { + _statusCode int + + Payload *httperrors.HTTPErrorResponse +} + +// IsSuccess returns true when this get tenant history default response has a 2xx status code +func (o *GetTenantHistoryDefault) IsSuccess() bool { + return o._statusCode/100 == 2 +} + +// IsRedirect returns true when this get tenant history default response has a 3xx status code +func (o *GetTenantHistoryDefault) IsRedirect() bool { + return o._statusCode/100 == 3 +} + +// IsClientError returns true when this get tenant history default response has a 4xx status code +func (o *GetTenantHistoryDefault) IsClientError() bool { + return o._statusCode/100 == 4 +} + +// IsServerError returns true when this get tenant history default response has a 5xx status code +func (o *GetTenantHistoryDefault) IsServerError() bool { + return o._statusCode/100 == 5 +} + +// IsCode returns true when this get tenant history default response a status code equal to that given +func (o *GetTenantHistoryDefault) IsCode(code int) bool { + return o._statusCode == code +} + +// Code gets the status code for the get tenant history default response +func (o *GetTenantHistoryDefault) Code() int { + return o._statusCode +} + +func (o *GetTenantHistoryDefault) Error() string { + return fmt.Sprintf("[POST /v1/tenant/{id}/history][%d] getTenantHistory default %+v", o._statusCode, o.Payload) +} + +func (o *GetTenantHistoryDefault) String() string { + return fmt.Sprintf("[POST /v1/tenant/{id}/history][%d] getTenantHistory default %+v", o._statusCode, o.Payload) +} + +func (o *GetTenantHistoryDefault) GetPayload() *httperrors.HTTPErrorResponse { + return o.Payload +} + +func (o *GetTenantHistoryDefault) 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/api/client/tenant/tenant_client.go b/api/client/tenant/tenant_client.go index 56ffa57c..d422360a 100644 --- a/api/client/tenant/tenant_client.go +++ b/api/client/tenant/tenant_client.go @@ -36,6 +36,8 @@ type ClientService interface { GetTenant(params *GetTenantParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*GetTenantOK, error) + GetTenantHistory(params *GetTenantHistoryParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*GetTenantHistoryOK, error) + ListTenants(params *ListTenantsParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*ListTenantsOK, error) UpdateTenant(params *UpdateTenantParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*UpdateTenantOK, error) @@ -195,6 +197,44 @@ func (a *Client) GetTenant(params *GetTenantParams, authInfo runtime.ClientAuthI return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code()) } +/* +GetTenantHistory gets tenant with this id at the given timestamp +*/ +func (a *Client) GetTenantHistory(params *GetTenantHistoryParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*GetTenantHistoryOK, error) { + // TODO: Validate the params before sending + if params == nil { + params = NewGetTenantHistoryParams() + } + op := &runtime.ClientOperation{ + ID: "getTenantHistory", + Method: "POST", + PathPattern: "/v1/tenant/{id}/history", + ProducesMediaTypes: []string{"application/json"}, + ConsumesMediaTypes: []string{"application/json"}, + Schemes: []string{"http"}, + Params: params, + Reader: &GetTenantHistoryReader{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.(*GetTenantHistoryOK) + if ok { + return success, nil + } + // unexpected success response + unexpectedSuccess := result.(*GetTenantHistoryDefault) + return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code()) +} + /* ListTenants gets all tenants */ diff --git a/api/models/v1_tenant_get_history_request.go b/api/models/v1_tenant_get_history_request.go new file mode 100644 index 00000000..904a8b6d --- /dev/null +++ b/api/models/v1_tenant_get_history_request.go @@ -0,0 +1,74 @@ +// 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 ( + "context" + + "github.com/go-openapi/errors" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" + "github.com/go-openapi/validate" +) + +// V1TenantGetHistoryRequest v1 tenant get history request +// +// swagger:model v1.TenantGetHistoryRequest +type V1TenantGetHistoryRequest struct { + + // at + // Format: date-time + At strfmt.DateTime `json:"at,omitempty" yaml:"at,omitempty"` +} + +// Validate validates this v1 tenant get history request +func (m *V1TenantGetHistoryRequest) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validateAt(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *V1TenantGetHistoryRequest) validateAt(formats strfmt.Registry) error { + if swag.IsZero(m.At) { // not required + return nil + } + + if err := validate.FormatOf("at", "body", "date-time", m.At.String(), formats); err != nil { + return err + } + + return nil +} + +// ContextValidate validates this v1 tenant get history request based on context it is used +func (m *V1TenantGetHistoryRequest) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (m *V1TenantGetHistoryRequest) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *V1TenantGetHistoryRequest) UnmarshalBinary(b []byte) error { + var res V1TenantGetHistoryRequest + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/metal-api.json b/metal-api.json index 98b5b858..623a9623 100644 --- a/metal-api.json +++ b/metal-api.json @@ -4707,6 +4707,14 @@ } } }, + "v1.TenantGetHistoryRequest": { + "properties": { + "at": { + "format": "date-time", + "type": "string" + } + } + }, "v1.TenantResponse": { "properties": { "default_quotas": { @@ -9072,6 +9080,52 @@ ] } }, + "/v1/tenant/{id}/history": { + "post": { + "consumes": [ + "application/json" + ], + "operationId": "getTenantHistory", + "parameters": [ + { + "description": "identifier of the tenant", + "in": "path", + "name": "id", + "required": true, + "type": "string" + }, + { + "in": "body", + "name": "body", + "required": true, + "schema": { + "$ref": "#/definitions/v1.TenantGetHistoryRequest" + } + } + ], + "produces": [ + "application/json" + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/v1.TenantResponse" + } + }, + "default": { + "description": "Error", + "schema": { + "$ref": "#/definitions/httperrors.HTTPErrorResponse" + } + } + }, + "summary": "get tenant with this id at the given timestamp", + "tags": [ + "tenant" + ] + } + }, "/v1/user/me": { "get": { "consumes": [