From 32b72a821e4696f0765bc1f7c5934bd824614a26 Mon Sep 17 00:00:00 2001 From: Jan Knipper Date: Thu, 13 Jul 2023 11:25:43 +0200 Subject: [PATCH] Add get clusters to swagger --- pkg/api/client/kubernikus_client.go | 9 +- .../operations/get_clusters_parameters.go | 148 +++++++++++++++ .../operations/get_clusters_responses.go | 177 ++++++++++++++++++ .../client/operations/operations_client.go | 40 ++++ swagger.yml | 21 +++ 5 files changed, 394 insertions(+), 1 deletion(-) create mode 100644 pkg/api/client/operations/get_clusters_parameters.go create mode 100644 pkg/api/client/operations/get_clusters_responses.go diff --git a/pkg/api/client/kubernikus_client.go b/pkg/api/client/kubernikus_client.go index 5469ca3e91..78923f7474 100644 --- a/pkg/api/client/kubernikus_client.go +++ b/pkg/api/client/kubernikus_client.go @@ -6,10 +6,17 @@ package client // Editing this file might prove futile when you re-run the swagger generate command import ( + "net/http" + + "github.com/go-openapi/errors" "github.com/go-openapi/runtime" httptransport "github.com/go-openapi/runtime/client" + "github.com/go-openapi/spec" "github.com/go-openapi/strfmt" - "github.com/sapcc/kubernikus/pkg/api/client/operations" + "github.com/go-openapi/swag" + + "github.com/sapcc/kubernikus/pkg/api/client" + "github.com/sapcc/kubernikus/pkg/api/models" ) // Default kubernikus HTTP client. diff --git a/pkg/api/client/operations/get_clusters_parameters.go b/pkg/api/client/operations/get_clusters_parameters.go new file mode 100644 index 0000000000..06c26b98fa --- /dev/null +++ b/pkg/api/client/operations/get_clusters_parameters.go @@ -0,0 +1,148 @@ +// 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" + "github.com/go-openapi/strfmt" +) + +// NewGetClustersParams creates a new GetClustersParams 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 NewGetClustersParams() *GetClustersParams { + return &GetClustersParams{ + timeout: cr.DefaultTimeout, + } +} + +// NewGetClustersParamsWithTimeout creates a new GetClustersParams object +// with the ability to set a timeout on a request. +func NewGetClustersParamsWithTimeout(timeout time.Duration) *GetClustersParams { + return &GetClustersParams{ + timeout: timeout, + } +} + +// NewGetClustersParamsWithContext creates a new GetClustersParams object +// with the ability to set a context for a request. +func NewGetClustersParamsWithContext(ctx context.Context) *GetClustersParams { + return &GetClustersParams{ + Context: ctx, + } +} + +// NewGetClustersParamsWithHTTPClient creates a new GetClustersParams object +// with the ability to set a custom HTTPClient for a request. +func NewGetClustersParamsWithHTTPClient(client *http.Client) *GetClustersParams { + return &GetClustersParams{ + HTTPClient: client, + } +} + +/* +GetClustersParams contains all the parameters to send to the API endpoint + + for the get clusters operation. + + Typically these are written to a http.Request. +*/ +type GetClustersParams struct { + + // Account. + Account string + + timeout time.Duration + Context context.Context + HTTPClient *http.Client +} + +// WithDefaults hydrates default values in the get clusters params (not the query body). +// +// All values with no default are reset to their zero value. +func (o *GetClustersParams) WithDefaults() *GetClustersParams { + o.SetDefaults() + return o +} + +// SetDefaults hydrates default values in the get clusters params (not the query body). +// +// All values with no default are reset to their zero value. +func (o *GetClustersParams) SetDefaults() { + // no default values defined for this parameter +} + +// WithTimeout adds the timeout to the get clusters params +func (o *GetClustersParams) WithTimeout(timeout time.Duration) *GetClustersParams { + o.SetTimeout(timeout) + return o +} + +// SetTimeout adds the timeout to the get clusters params +func (o *GetClustersParams) SetTimeout(timeout time.Duration) { + o.timeout = timeout +} + +// WithContext adds the context to the get clusters params +func (o *GetClustersParams) WithContext(ctx context.Context) *GetClustersParams { + o.SetContext(ctx) + return o +} + +// SetContext adds the context to the get clusters params +func (o *GetClustersParams) SetContext(ctx context.Context) { + o.Context = ctx +} + +// WithHTTPClient adds the HTTPClient to the get clusters params +func (o *GetClustersParams) WithHTTPClient(client *http.Client) *GetClustersParams { + o.SetHTTPClient(client) + return o +} + +// SetHTTPClient adds the HTTPClient to the get clusters params +func (o *GetClustersParams) SetHTTPClient(client *http.Client) { + o.HTTPClient = client +} + +// WithAccount adds the account to the get clusters params +func (o *GetClustersParams) WithAccount(account string) *GetClustersParams { + o.SetAccount(account) + return o +} + +// SetAccount adds the account to the get clusters params +func (o *GetClustersParams) SetAccount(account string) { + o.Account = account +} + +// WriteToRequest writes these params to a swagger request +func (o *GetClustersParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { + + if err := r.SetTimeout(o.timeout); err != nil { + return err + } + var res []error + + // path param account + if err := r.SetPathParam("account", o.Account); err != nil { + return err + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} diff --git a/pkg/api/client/operations/get_clusters_responses.go b/pkg/api/client/operations/get_clusters_responses.go new file mode 100644 index 0000000000..4f89b9f465 --- /dev/null +++ b/pkg/api/client/operations/get_clusters_responses.go @@ -0,0 +1,177 @@ +// 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" + "github.com/go-openapi/strfmt" + + "github.com/sapcc/kubernikus/pkg/api/models" +) + +// GetClustersReader is a Reader for the GetClusters structure. +type GetClustersReader struct { + formats strfmt.Registry +} + +// ReadResponse reads a server response into the received o. +func (o *GetClustersReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { + switch response.Code() { + case 200: + result := NewGetClustersOK() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return result, nil + default: + result := NewGetClustersDefault(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 + } +} + +// NewGetClustersOK creates a GetClustersOK with default headers values +func NewGetClustersOK() *GetClustersOK { + return &GetClustersOK{} +} + +/* +GetClustersOK describes a response with status code 200, with default header values. + +OK +*/ +type GetClustersOK struct { + Payload *models.GetClustersOKBody +} + +// IsSuccess returns true when this get clusters o k response has a 2xx status code +func (o *GetClustersOK) IsSuccess() bool { + return true +} + +// IsRedirect returns true when this get clusters o k response has a 3xx status code +func (o *GetClustersOK) IsRedirect() bool { + return false +} + +// IsClientError returns true when this get clusters o k response has a 4xx status code +func (o *GetClustersOK) IsClientError() bool { + return false +} + +// IsServerError returns true when this get clusters o k response has a 5xx status code +func (o *GetClustersOK) IsServerError() bool { + return false +} + +// IsCode returns true when this get clusters o k response a status code equal to that given +func (o *GetClustersOK) IsCode(code int) bool { + return code == 200 +} + +func (o *GetClustersOK) Error() string { + return fmt.Sprintf("[GET /api/v1/{account}/clusters][%d] getClustersOK %+v", 200, o.Payload) +} + +func (o *GetClustersOK) String() string { + return fmt.Sprintf("[GET /api/v1/{account}/clusters][%d] getClustersOK %+v", 200, o.Payload) +} + +func (o *GetClustersOK) GetPayload() *models.GetClustersOKBody { + return o.Payload +} + +func (o *GetClustersOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(models.GetClustersOKBody) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewGetClustersDefault creates a GetClustersDefault with default headers values +func NewGetClustersDefault(code int) *GetClustersDefault { + return &GetClustersDefault{ + _statusCode: code, + } +} + +/* +GetClustersDefault describes a response with status code -1, with default header values. + +Error +*/ +type GetClustersDefault struct { + _statusCode int + + Payload *models.Error +} + +// Code gets the status code for the get clusters default response +func (o *GetClustersDefault) Code() int { + return o._statusCode +} + +// IsSuccess returns true when this get clusters default response has a 2xx status code +func (o *GetClustersDefault) IsSuccess() bool { + return o._statusCode/100 == 2 +} + +// IsRedirect returns true when this get clusters default response has a 3xx status code +func (o *GetClustersDefault) IsRedirect() bool { + return o._statusCode/100 == 3 +} + +// IsClientError returns true when this get clusters default response has a 4xx status code +func (o *GetClustersDefault) IsClientError() bool { + return o._statusCode/100 == 4 +} + +// IsServerError returns true when this get clusters default response has a 5xx status code +func (o *GetClustersDefault) IsServerError() bool { + return o._statusCode/100 == 5 +} + +// IsCode returns true when this get clusters default response a status code equal to that given +func (o *GetClustersDefault) IsCode(code int) bool { + return o._statusCode == code +} + +func (o *GetClustersDefault) Error() string { + return fmt.Sprintf("[GET /api/v1/{account}/clusters][%d] GetClusters default %+v", o._statusCode, o.Payload) +} + +func (o *GetClustersDefault) String() string { + return fmt.Sprintf("[GET /api/v1/{account}/clusters][%d] GetClusters default %+v", o._statusCode, o.Payload) +} + +func (o *GetClustersDefault) GetPayload() *models.Error { + return o.Payload +} + +func (o *GetClustersDefault) 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/pkg/api/client/operations/operations_client.go b/pkg/api/client/operations/operations_client.go index cc32c57c2a..8d36544e45 100644 --- a/pkg/api/client/operations/operations_client.go +++ b/pkg/api/client/operations/operations_client.go @@ -48,6 +48,8 @@ type ClientService interface { GetClusterValues(params *GetClusterValuesParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*GetClusterValuesOK, error) + GetClusters(params *GetClustersParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*GetClustersOK, error) + GetOpenstackMetadata(params *GetOpenstackMetadataParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*GetOpenstackMetadataOK, error) Info(params *InfoParams, opts ...ClientOption) (*InfoOK, error) @@ -399,6 +401,44 @@ func (a *Client) GetClusterValues(params *GetClusterValuesParams, authInfo runti return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code()) } +/* +GetClusters gets all clusters in a project admin only +*/ +func (a *Client) GetClusters(params *GetClustersParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*GetClustersOK, error) { + // TODO: Validate the params before sending + if params == nil { + params = NewGetClustersParams() + } + op := &runtime.ClientOperation{ + ID: "GetClusters", + Method: "GET", + PathPattern: "/api/v1/{account}/clusters", + ProducesMediaTypes: []string{"application/json"}, + ConsumesMediaTypes: []string{"application/json"}, + Schemes: []string{"https"}, + Params: params, + Reader: &GetClustersReader{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.(*GetClustersOK) + if ok { + return success, nil + } + // unexpected success response + unexpectedSuccess := result.(*GetClustersDefault) + return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code()) +} + /* GetOpenstackMetadata grabs bag of openstack metadata */ diff --git a/swagger.yml b/swagger.yml index 3569722676..a1d9f0a3e3 100644 --- a/swagger.yml +++ b/swagger.yml @@ -283,6 +283,27 @@ paths: type: string default: $ref: '#/responses/errorResponse' + '/api/v1/{account}/clusters': + parameters: + - uniqueItems: true + type: string + name: account + required: true + in: path + get: + operationId: GetClusters + summary: Get all clusters in a project (admin-only) + responses: + '200': + description: OK + schema: + type: object + properties: + values: + description: All clusters in json format + type: string + default: + $ref: '#/responses/errorResponse' definitions: Event: type: object