From c0e3e2037df8a4c25023fe04d6e47b10be49b51c Mon Sep 17 00:00:00 2001 From: cq-bot Date: Thu, 28 Dec 2023 10:24:22 +0000 Subject: [PATCH] fix: Generate CloudQuery Go API Client from `spec.json` --- client.gen.go | 187 -------------------------------------------------- models.gen.go | 19 ----- spec.json | 89 ------------------------ 3 files changed, 295 deletions(-) diff --git a/client.gen.go b/client.gen.go index b809063..bf2df16 100644 --- a/client.gen.go +++ b/client.gen.go @@ -219,9 +219,6 @@ type ClientInterface interface { // GetPluginVersionTable request GetPluginVersionTable(ctx context.Context, teamName TeamName, pluginKind PluginKind, pluginName PluginName, versionName VersionName, tableName string, reqEditors ...RequestEditorFn) (*http.Response, error) - // AuthRegistryRequest request - AuthRegistryRequest(ctx context.Context, params *AuthRegistryRequestParams, reqEditors ...RequestEditorFn) (*http.Response, error) - // ListTeams request ListTeams(ctx context.Context, params *ListTeamsParams, reqEditors ...RequestEditorFn) (*http.Response, error) @@ -938,18 +935,6 @@ func (c *Client) GetPluginVersionTable(ctx context.Context, teamName TeamName, p return c.Client.Do(req) } -func (c *Client) AuthRegistryRequest(ctx context.Context, params *AuthRegistryRequestParams, reqEditors ...RequestEditorFn) (*http.Response, error) { - req, err := NewAuthRegistryRequestRequest(c.Server, params) - if err != nil { - return nil, err - } - req = req.WithContext(ctx) - if err := c.applyEditors(ctx, req, reqEditors); err != nil { - return nil, err - } - return c.Client.Do(req) -} - func (c *Client) ListTeams(ctx context.Context, params *ListTeamsParams, reqEditors ...RequestEditorFn) (*http.Response, error) { req, err := NewListTeamsRequest(c.Server, params) if err != nil { @@ -3755,86 +3740,6 @@ func NewGetPluginVersionTableRequest(server string, teamName TeamName, pluginKin return req, nil } -// NewAuthRegistryRequestRequest generates requests for AuthRegistryRequest -func NewAuthRegistryRequestRequest(server string, params *AuthRegistryRequestParams) (*http.Request, error) { - var err error - - serverURL, err := url.Parse(server) - if err != nil { - return nil, err - } - - operationPath := fmt.Sprintf("/registry/auth") - if operationPath[0] == '/' { - operationPath = "." + operationPath - } - - queryURL, err := serverURL.Parse(operationPath) - if err != nil { - return nil, err - } - - if params != nil { - queryValues := queryURL.Query() - - if params.Account != nil { - - if queryFrag, err := runtime.StyleParamWithLocation("form", true, "account", runtime.ParamLocationQuery, *params.Account); err != nil { - return nil, err - } else if parsed, err := url.ParseQuery(queryFrag); err != nil { - return nil, err - } else { - for k, v := range parsed { - for _, v2 := range v { - queryValues.Add(k, v2) - } - } - } - - } - - if params.Scope != nil { - - if queryFrag, err := runtime.StyleParamWithLocation("form", true, "scope", runtime.ParamLocationQuery, *params.Scope); err != nil { - return nil, err - } else if parsed, err := url.ParseQuery(queryFrag); err != nil { - return nil, err - } else { - for k, v := range parsed { - for _, v2 := range v { - queryValues.Add(k, v2) - } - } - } - - } - - queryURL.RawQuery = queryValues.Encode() - } - - req, err := http.NewRequest("GET", queryURL.String(), nil) - if err != nil { - return nil, err - } - - if params != nil { - - if params.XPluginVersion != nil { - var headerParam0 string - - headerParam0, err = runtime.StyleParamWithLocation("simple", false, "X-Plugin-Version", runtime.ParamLocationHeader, *params.XPluginVersion) - if err != nil { - return nil, err - } - - req.Header.Set("X-Plugin-Version", headerParam0) - } - - } - - return req, nil -} - // NewListTeamsRequest generates requests for ListTeams func NewListTeamsRequest(server string, params *ListTeamsParams) (*http.Request, error) { var err error @@ -6197,9 +6102,6 @@ type ClientWithResponsesInterface interface { // GetPluginVersionTableWithResponse request GetPluginVersionTableWithResponse(ctx context.Context, teamName TeamName, pluginKind PluginKind, pluginName PluginName, versionName VersionName, tableName string, reqEditors ...RequestEditorFn) (*GetPluginVersionTableResponse, error) - // AuthRegistryRequestWithResponse request - AuthRegistryRequestWithResponse(ctx context.Context, params *AuthRegistryRequestParams, reqEditors ...RequestEditorFn) (*AuthRegistryRequestResponse, error) - // ListTeamsWithResponse request ListTeamsWithResponse(ctx context.Context, params *ListTeamsParams, reqEditors ...RequestEditorFn) (*ListTeamsResponse, error) @@ -7245,32 +7147,6 @@ func (r GetPluginVersionTableResponse) StatusCode() int { return 0 } -type AuthRegistryRequestResponse struct { - Body []byte - HTTPResponse *http.Response - JSON200 *RegistryAuthToken - JSON400 *BadRequest - JSON401 *RequiresAuthentication - JSON422 *UnprocessableEntity - JSON500 *InternalError -} - -// Status returns HTTPResponse.Status -func (r AuthRegistryRequestResponse) Status() string { - if r.HTTPResponse != nil { - return r.HTTPResponse.Status - } - return http.StatusText(0) -} - -// StatusCode returns HTTPResponse.StatusCode -func (r AuthRegistryRequestResponse) StatusCode() int { - if r.HTTPResponse != nil { - return r.HTTPResponse.StatusCode - } - return 0 -} - type ListTeamsResponse struct { Body []byte HTTPResponse *http.Response @@ -8742,15 +8618,6 @@ func (c *ClientWithResponses) GetPluginVersionTableWithResponse(ctx context.Cont return ParseGetPluginVersionTableResponse(rsp) } -// AuthRegistryRequestWithResponse request returning *AuthRegistryRequestResponse -func (c *ClientWithResponses) AuthRegistryRequestWithResponse(ctx context.Context, params *AuthRegistryRequestParams, reqEditors ...RequestEditorFn) (*AuthRegistryRequestResponse, error) { - rsp, err := c.AuthRegistryRequest(ctx, params, reqEditors...) - if err != nil { - return nil, err - } - return ParseAuthRegistryRequestResponse(rsp) -} - // ListTeamsWithResponse request returning *ListTeamsResponse func (c *ClientWithResponses) ListTeamsWithResponse(ctx context.Context, params *ListTeamsParams, reqEditors ...RequestEditorFn) (*ListTeamsResponse, error) { rsp, err := c.ListTeams(ctx, params, reqEditors...) @@ -11026,60 +10893,6 @@ func ParseGetPluginVersionTableResponse(rsp *http.Response) (*GetPluginVersionTa return response, nil } -// ParseAuthRegistryRequestResponse parses an HTTP response from a AuthRegistryRequestWithResponse call -func ParseAuthRegistryRequestResponse(rsp *http.Response) (*AuthRegistryRequestResponse, error) { - bodyBytes, err := io.ReadAll(rsp.Body) - defer func() { _ = rsp.Body.Close() }() - if err != nil { - return nil, err - } - - response := &AuthRegistryRequestResponse{ - Body: bodyBytes, - HTTPResponse: rsp, - } - - switch { - case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: - var dest RegistryAuthToken - if err := json.Unmarshal(bodyBytes, &dest); err != nil { - return nil, err - } - response.JSON200 = &dest - - case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: - var dest BadRequest - if err := json.Unmarshal(bodyBytes, &dest); err != nil { - return nil, err - } - response.JSON400 = &dest - - case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 401: - var dest RequiresAuthentication - if err := json.Unmarshal(bodyBytes, &dest); err != nil { - return nil, err - } - response.JSON401 = &dest - - case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 422: - var dest UnprocessableEntity - if err := json.Unmarshal(bodyBytes, &dest); err != nil { - return nil, err - } - response.JSON422 = &dest - - case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: - var dest InternalError - if err := json.Unmarshal(bodyBytes, &dest); err != nil { - return nil, err - } - response.JSON500 = &dest - - } - - return response, nil -} - // ParseListTeamsResponse parses an HTTP response from a ListTeamsWithResponse call func ParseListTeamsResponse(rsp *http.Response) (*ListTeamsResponse, error) { bodyBytes, err := io.ReadAll(rsp.Body) diff --git a/models.gen.go b/models.gen.go index 90d7af4..dca01a8 100644 --- a/models.gen.go +++ b/models.gen.go @@ -10,7 +10,6 @@ import ( ) const ( - BasicAuthScopes = "basicAuth.Scopes" BearerAuthScopes = "bearerAuth.Scopes" ) @@ -1011,12 +1010,6 @@ type PluginVersionUpdate struct { SupportedTargets *[]string `json:"supported_targets,omitempty"` } -// RegistryAuthToken JWT token for the image registry -type RegistryAuthToken struct { - AccessToken string `json:"access_token"` - Token string `json:"token"` -} - // ReleaseURL defines model for ReleaseURL. type ReleaseURL struct { Url string `json:"url"` @@ -1363,18 +1356,6 @@ type CreatePluginVersionTablesJSONBody struct { Tables []PluginTableCreate `json:"tables"` } -// AuthRegistryRequestParams defines parameters for AuthRegistryRequest. -type AuthRegistryRequestParams struct { - // Account Username used for `docker login` - Account *string `form:"account,omitempty" json:"account,omitempty"` - - // Scope Multi-value string containing the repository being access and the operation type (push/pull) - Scope *string `form:"scope,omitempty" json:"scope,omitempty"` - - // XPluginVersion Plugin version name - XPluginVersion *string `json:"X-Plugin-Version,omitempty"` -} - // ListTeamsParams defines parameters for ListTeams. type ListTeamsParams struct { // PerPage The number of results per page (max 1000). diff --git a/spec.json b/spec.json index e7bac33..dc32aee 100644 --- a/spec.json +++ b/spec.json @@ -52,9 +52,6 @@ }, { "name": "addons" - }, - { - "name": "registry" } ], "paths": { @@ -4101,71 +4098,6 @@ } } } - }, - "/registry/auth": { - "get": { - "description": "Performs authentication and authorization for our image registry.", - "operationId": "AuthRegistryRequest", - "parameters": [ - { - "in": "header", - "name": "X-Plugin-Version", - "schema": { - "type": "string" - }, - "description": "Plugin version name", - "example": "v1.0.0" - }, - { - "in": "query", - "name": "account", - "schema": { - "type": "string" - }, - "description": "Username used for `docker login`" - }, - { - "in": "query", - "name": "scope", - "schema": { - "type": "string" - }, - "description": "Multi-value string containing the repository being access and the operation type (push/pull)" - } - ], - "responses": { - "200": { - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/RegistryAuthToken" - } - } - }, - "description": "Response" - }, - "400": { - "$ref": "#/components/responses/BadRequest" - }, - "401": { - "$ref": "#/components/responses/RequiresAuthentication" - }, - "422": { - "$ref": "#/components/responses/UnprocessableEntity" - }, - "500": { - "$ref": "#/components/responses/InternalError" - } - }, - "tags": [ - "registry" - ], - "security": [ - { - "basicAuth": [] - } - ] - } } }, "components": { @@ -4173,10 +4105,6 @@ "bearerAuth": { "scheme": "bearer", "type": "http" - }, - "basicAuth": { - "scheme": "basic", - "type": "http" } }, "schemas": { @@ -6083,23 +6011,6 @@ "$ref": "#/components/schemas/APIKeyScope" } } - }, - "RegistryAuthToken": { - "type": "object", - "description": "JWT token for the image registry", - "additionalProperties": false, - "properties": { - "access_token": { - "type": "string" - }, - "token": { - "type": "string" - } - }, - "required": [ - "access_token", - "token" - ] } }, "responses": {