From b8ead7c4ae372f36266dd437f0590067ce731598 Mon Sep 17 00:00:00 2001 From: CloudQuery Bot <102256036+cq-bot@users.noreply.github.com> Date: Wed, 3 Apr 2024 11:37:58 +0300 Subject: [PATCH 1/4] fix: Generate CloudQuery Go API Client from `spec.json` (#142) This PR was created by a scheduled workflow to generate the CloudQuery Go API Client from `spec.json` --- client.gen.go | 706 +++++++++++++++++++++++++++++++++++++++++++++++--- models.gen.go | 47 +++- spec.json | 263 ++++++++++++++++++- 3 files changed, 980 insertions(+), 36 deletions(-) diff --git a/client.gen.go b/client.gen.go index 091f789..7a640df 100644 --- a/client.gen.go +++ b/client.gen.go @@ -346,6 +346,22 @@ type ClientInterface interface { // DownloadPluginAssetByTeam request DownloadPluginAssetByTeam(ctx context.Context, teamName TeamName, pluginTeam PluginTeam, pluginKind PluginKind, pluginName PluginName, versionName VersionName, targetName TargetName, params *DownloadPluginAssetByTeamParams, reqEditors ...RequestEditorFn) (*http.Response, error) + // DeleteSpendingLimit request + DeleteSpendingLimit(ctx context.Context, teamName TeamName, reqEditors ...RequestEditorFn) (*http.Response, error) + + // GetSpendingLimit request + GetSpendingLimit(ctx context.Context, teamName TeamName, reqEditors ...RequestEditorFn) (*http.Response, error) + + // CreateSpendingLimitWithBody request with any body + CreateSpendingLimitWithBody(ctx context.Context, teamName TeamName, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) + + CreateSpendingLimit(ctx context.Context, teamName TeamName, body CreateSpendingLimitJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + + // UpdateSpendingLimitWithBody request with any body + UpdateSpendingLimitWithBody(ctx context.Context, teamName TeamName, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) + + UpdateSpendingLimit(ctx context.Context, teamName TeamName, body UpdateSpendingLimitJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + // ListSubscriptionOrdersByTeam request ListSubscriptionOrdersByTeam(ctx context.Context, teamName TeamName, params *ListSubscriptionOrdersByTeamParams, reqEditors ...RequestEditorFn) (*http.Response, error) @@ -1605,6 +1621,78 @@ func (c *Client) DownloadPluginAssetByTeam(ctx context.Context, teamName TeamNam return c.Client.Do(req) } +func (c *Client) DeleteSpendingLimit(ctx context.Context, teamName TeamName, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewDeleteSpendingLimitRequest(c.Server, teamName) + 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) GetSpendingLimit(ctx context.Context, teamName TeamName, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewGetSpendingLimitRequest(c.Server, teamName) + 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) CreateSpendingLimitWithBody(ctx context.Context, teamName TeamName, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewCreateSpendingLimitRequestWithBody(c.Server, teamName, contentType, body) + 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) CreateSpendingLimit(ctx context.Context, teamName TeamName, body CreateSpendingLimitJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewCreateSpendingLimitRequest(c.Server, teamName, body) + 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) UpdateSpendingLimitWithBody(ctx context.Context, teamName TeamName, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewUpdateSpendingLimitRequestWithBody(c.Server, teamName, contentType, body) + 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) UpdateSpendingLimit(ctx context.Context, teamName TeamName, body UpdateSpendingLimitJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewUpdateSpendingLimitRequest(c.Server, teamName, body) + 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) ListSubscriptionOrdersByTeam(ctx context.Context, teamName TeamName, params *ListSubscriptionOrdersByTeamParams, reqEditors ...RequestEditorFn) (*http.Response, error) { req, err := NewListSubscriptionOrdersByTeamRequest(c.Server, teamName, params) if err != nil { @@ -6444,6 +6532,168 @@ func NewDownloadPluginAssetByTeamRequest(server string, teamName TeamName, plugi return req, nil } +// NewDeleteSpendingLimitRequest generates requests for DeleteSpendingLimit +func NewDeleteSpendingLimitRequest(server string, teamName TeamName) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "team_name", runtime.ParamLocationPath, teamName) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/teams/%s/spending-limits", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("DELETE", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewGetSpendingLimitRequest generates requests for GetSpendingLimit +func NewGetSpendingLimitRequest(server string, teamName TeamName) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "team_name", runtime.ParamLocationPath, teamName) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/teams/%s/spending-limits", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("GET", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewCreateSpendingLimitRequest calls the generic CreateSpendingLimit builder with application/json body +func NewCreateSpendingLimitRequest(server string, teamName TeamName, body CreateSpendingLimitJSONRequestBody) (*http.Request, error) { + var bodyReader io.Reader + buf, err := json.Marshal(body) + if err != nil { + return nil, err + } + bodyReader = bytes.NewReader(buf) + return NewCreateSpendingLimitRequestWithBody(server, teamName, "application/json", bodyReader) +} + +// NewCreateSpendingLimitRequestWithBody generates requests for CreateSpendingLimit with any type of body +func NewCreateSpendingLimitRequestWithBody(server string, teamName TeamName, contentType string, body io.Reader) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "team_name", runtime.ParamLocationPath, teamName) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/teams/%s/spending-limits", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("POST", queryURL.String(), body) + if err != nil { + return nil, err + } + + req.Header.Add("Content-Type", contentType) + + return req, nil +} + +// NewUpdateSpendingLimitRequest calls the generic UpdateSpendingLimit builder with application/json body +func NewUpdateSpendingLimitRequest(server string, teamName TeamName, body UpdateSpendingLimitJSONRequestBody) (*http.Request, error) { + var bodyReader io.Reader + buf, err := json.Marshal(body) + if err != nil { + return nil, err + } + bodyReader = bytes.NewReader(buf) + return NewUpdateSpendingLimitRequestWithBody(server, teamName, "application/json", bodyReader) +} + +// NewUpdateSpendingLimitRequestWithBody generates requests for UpdateSpendingLimit with any type of body +func NewUpdateSpendingLimitRequestWithBody(server string, teamName TeamName, contentType string, body io.Reader) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "team_name", runtime.ParamLocationPath, teamName) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/teams/%s/spending-limits", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("PUT", queryURL.String(), body) + if err != nil { + return nil, err + } + + req.Header.Add("Content-Type", contentType) + + return req, nil +} + // NewListSubscriptionOrdersByTeamRequest generates requests for ListSubscriptionOrdersByTeam func NewListSubscriptionOrdersByTeamRequest(server string, teamName TeamName, params *ListSubscriptionOrdersByTeamParams) (*http.Request, error) { var err error @@ -8713,6 +8963,22 @@ type ClientWithResponsesInterface interface { // DownloadPluginAssetByTeamWithResponse request DownloadPluginAssetByTeamWithResponse(ctx context.Context, teamName TeamName, pluginTeam PluginTeam, pluginKind PluginKind, pluginName PluginName, versionName VersionName, targetName TargetName, params *DownloadPluginAssetByTeamParams, reqEditors ...RequestEditorFn) (*DownloadPluginAssetByTeamResponse, error) + // DeleteSpendingLimitWithResponse request + DeleteSpendingLimitWithResponse(ctx context.Context, teamName TeamName, reqEditors ...RequestEditorFn) (*DeleteSpendingLimitResponse, error) + + // GetSpendingLimitWithResponse request + GetSpendingLimitWithResponse(ctx context.Context, teamName TeamName, reqEditors ...RequestEditorFn) (*GetSpendingLimitResponse, error) + + // CreateSpendingLimitWithBodyWithResponse request with any body + CreateSpendingLimitWithBodyWithResponse(ctx context.Context, teamName TeamName, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*CreateSpendingLimitResponse, error) + + CreateSpendingLimitWithResponse(ctx context.Context, teamName TeamName, body CreateSpendingLimitJSONRequestBody, reqEditors ...RequestEditorFn) (*CreateSpendingLimitResponse, error) + + // UpdateSpendingLimitWithBodyWithResponse request with any body + UpdateSpendingLimitWithBodyWithResponse(ctx context.Context, teamName TeamName, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*UpdateSpendingLimitResponse, error) + + UpdateSpendingLimitWithResponse(ctx context.Context, teamName TeamName, body UpdateSpendingLimitJSONRequestBody, reqEditors ...RequestEditorFn) (*UpdateSpendingLimitResponse, error) + // ListSubscriptionOrdersByTeamWithResponse request ListSubscriptionOrdersByTeamWithResponse(ctx context.Context, teamName TeamName, params *ListSubscriptionOrdersByTeamParams, reqEditors ...RequestEditorFn) (*ListSubscriptionOrdersByTeamResponse, error) @@ -10712,21 +10978,17 @@ func (r DownloadPluginAssetByTeamResponse) StatusCode() int { return 0 } -type ListSubscriptionOrdersByTeamResponse struct { +type DeleteSpendingLimitResponse struct { Body []byte HTTPResponse *http.Response - JSON200 *struct { - Items []TeamSubscriptionOrder `json:"items"` - Metadata ListMetadata `json:"metadata"` - } - JSON401 *RequiresAuthentication - JSON403 *Forbidden - JSON404 *NotFound - JSON500 *InternalError + JSON401 *RequiresAuthentication + JSON403 *Forbidden + JSON404 *NotFound + JSON500 *InternalError } // Status returns HTTPResponse.Status -func (r ListSubscriptionOrdersByTeamResponse) Status() string { +func (r DeleteSpendingLimitResponse) Status() string { if r.HTTPResponse != nil { return r.HTTPResponse.Status } @@ -10734,27 +10996,25 @@ func (r ListSubscriptionOrdersByTeamResponse) Status() string { } // StatusCode returns HTTPResponse.StatusCode -func (r ListSubscriptionOrdersByTeamResponse) StatusCode() int { +func (r DeleteSpendingLimitResponse) StatusCode() int { if r.HTTPResponse != nil { return r.HTTPResponse.StatusCode } return 0 } -type CreateSubscriptionOrderForTeamResponse struct { +type GetSpendingLimitResponse struct { Body []byte HTTPResponse *http.Response - JSON201 *TeamSubscriptionOrder - JSON400 *BadRequest + JSON200 *SpendingLimit JSON401 *RequiresAuthentication JSON403 *Forbidden JSON404 *NotFound - JSON422 *UnprocessableEntity JSON500 *InternalError } // Status returns HTTPResponse.Status -func (r CreateSubscriptionOrderForTeamResponse) Status() string { +func (r GetSpendingLimitResponse) Status() string { if r.HTTPResponse != nil { return r.HTTPResponse.Status } @@ -10762,25 +11022,26 @@ func (r CreateSubscriptionOrderForTeamResponse) Status() string { } // StatusCode returns HTTPResponse.StatusCode -func (r CreateSubscriptionOrderForTeamResponse) StatusCode() int { +func (r GetSpendingLimitResponse) StatusCode() int { if r.HTTPResponse != nil { return r.HTTPResponse.StatusCode } return 0 } -type GetSubscriptionOrderByTeamResponse struct { +type CreateSpendingLimitResponse struct { Body []byte HTTPResponse *http.Response - JSON200 *TeamSubscriptionOrder + JSON201 *SpendingLimit JSON401 *RequiresAuthentication JSON403 *Forbidden JSON404 *NotFound + JSON422 *UnprocessableEntity JSON500 *InternalError } // Status returns HTTPResponse.Status -func (r GetSubscriptionOrderByTeamResponse) Status() string { +func (r CreateSpendingLimitResponse) Status() string { if r.HTTPResponse != nil { return r.HTTPResponse.Status } @@ -10788,27 +11049,137 @@ func (r GetSubscriptionOrderByTeamResponse) Status() string { } // StatusCode returns HTTPResponse.StatusCode -func (r GetSubscriptionOrderByTeamResponse) StatusCode() int { +func (r CreateSpendingLimitResponse) StatusCode() int { if r.HTTPResponse != nil { return r.HTTPResponse.StatusCode } return 0 } -type ListSyncDestinationsResponse struct { +type UpdateSpendingLimitResponse struct { Body []byte HTTPResponse *http.Response - JSON200 *struct { - Items []SyncDestination `json:"items"` - Metadata ListMetadata `json:"metadata"` - } - JSON401 *RequiresAuthentication - JSON404 *NotFound - JSON500 *InternalError + JSON200 *SpendingLimit + JSON400 *BadRequest + JSON401 *RequiresAuthentication + JSON403 *Forbidden + JSON404 *NotFound + JSON500 *InternalError } // Status returns HTTPResponse.Status -func (r ListSyncDestinationsResponse) Status() string { +func (r UpdateSpendingLimitResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r UpdateSpendingLimitResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type ListSubscriptionOrdersByTeamResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *struct { + Items []TeamSubscriptionOrder `json:"items"` + Metadata ListMetadata `json:"metadata"` + } + JSON401 *RequiresAuthentication + JSON403 *Forbidden + JSON404 *NotFound + JSON500 *InternalError +} + +// Status returns HTTPResponse.Status +func (r ListSubscriptionOrdersByTeamResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r ListSubscriptionOrdersByTeamResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type CreateSubscriptionOrderForTeamResponse struct { + Body []byte + HTTPResponse *http.Response + JSON201 *TeamSubscriptionOrder + JSON400 *BadRequest + JSON401 *RequiresAuthentication + JSON403 *Forbidden + JSON404 *NotFound + JSON422 *UnprocessableEntity + JSON500 *InternalError +} + +// Status returns HTTPResponse.Status +func (r CreateSubscriptionOrderForTeamResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r CreateSubscriptionOrderForTeamResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type GetSubscriptionOrderByTeamResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *TeamSubscriptionOrder + JSON401 *RequiresAuthentication + JSON403 *Forbidden + JSON404 *NotFound + JSON500 *InternalError +} + +// Status returns HTTPResponse.Status +func (r GetSubscriptionOrderByTeamResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r GetSubscriptionOrderByTeamResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type ListSyncDestinationsResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *struct { + Items []SyncDestination `json:"items"` + Metadata ListMetadata `json:"metadata"` + } + JSON401 *RequiresAuthentication + JSON404 *NotFound + JSON500 *InternalError +} + +// Status returns HTTPResponse.Status +func (r ListSyncDestinationsResponse) Status() string { if r.HTTPResponse != nil { return r.HTTPResponse.Status } @@ -12540,6 +12911,58 @@ func (c *ClientWithResponses) DownloadPluginAssetByTeamWithResponse(ctx context. return ParseDownloadPluginAssetByTeamResponse(rsp) } +// DeleteSpendingLimitWithResponse request returning *DeleteSpendingLimitResponse +func (c *ClientWithResponses) DeleteSpendingLimitWithResponse(ctx context.Context, teamName TeamName, reqEditors ...RequestEditorFn) (*DeleteSpendingLimitResponse, error) { + rsp, err := c.DeleteSpendingLimit(ctx, teamName, reqEditors...) + if err != nil { + return nil, err + } + return ParseDeleteSpendingLimitResponse(rsp) +} + +// GetSpendingLimitWithResponse request returning *GetSpendingLimitResponse +func (c *ClientWithResponses) GetSpendingLimitWithResponse(ctx context.Context, teamName TeamName, reqEditors ...RequestEditorFn) (*GetSpendingLimitResponse, error) { + rsp, err := c.GetSpendingLimit(ctx, teamName, reqEditors...) + if err != nil { + return nil, err + } + return ParseGetSpendingLimitResponse(rsp) +} + +// CreateSpendingLimitWithBodyWithResponse request with arbitrary body returning *CreateSpendingLimitResponse +func (c *ClientWithResponses) CreateSpendingLimitWithBodyWithResponse(ctx context.Context, teamName TeamName, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*CreateSpendingLimitResponse, error) { + rsp, err := c.CreateSpendingLimitWithBody(ctx, teamName, contentType, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseCreateSpendingLimitResponse(rsp) +} + +func (c *ClientWithResponses) CreateSpendingLimitWithResponse(ctx context.Context, teamName TeamName, body CreateSpendingLimitJSONRequestBody, reqEditors ...RequestEditorFn) (*CreateSpendingLimitResponse, error) { + rsp, err := c.CreateSpendingLimit(ctx, teamName, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseCreateSpendingLimitResponse(rsp) +} + +// UpdateSpendingLimitWithBodyWithResponse request with arbitrary body returning *UpdateSpendingLimitResponse +func (c *ClientWithResponses) UpdateSpendingLimitWithBodyWithResponse(ctx context.Context, teamName TeamName, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*UpdateSpendingLimitResponse, error) { + rsp, err := c.UpdateSpendingLimitWithBody(ctx, teamName, contentType, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseUpdateSpendingLimitResponse(rsp) +} + +func (c *ClientWithResponses) UpdateSpendingLimitWithResponse(ctx context.Context, teamName TeamName, body UpdateSpendingLimitJSONRequestBody, reqEditors ...RequestEditorFn) (*UpdateSpendingLimitResponse, error) { + rsp, err := c.UpdateSpendingLimit(ctx, teamName, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseUpdateSpendingLimitResponse(rsp) +} + // ListSubscriptionOrdersByTeamWithResponse request returning *ListSubscriptionOrdersByTeamResponse func (c *ClientWithResponses) ListSubscriptionOrdersByTeamWithResponse(ctx context.Context, teamName TeamName, params *ListSubscriptionOrdersByTeamParams, reqEditors ...RequestEditorFn) (*ListSubscriptionOrdersByTeamResponse, error) { rsp, err := c.ListSubscriptionOrdersByTeam(ctx, teamName, params, reqEditors...) @@ -16773,6 +17196,229 @@ func ParseDownloadPluginAssetByTeamResponse(rsp *http.Response) (*DownloadPlugin return response, nil } +// ParseDeleteSpendingLimitResponse parses an HTTP response from a DeleteSpendingLimitWithResponse call +func ParseDeleteSpendingLimitResponse(rsp *http.Response) (*DeleteSpendingLimitResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &DeleteSpendingLimitResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + 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 == 403: + var dest Forbidden + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON403 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest NotFound + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON404 = &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 +} + +// ParseGetSpendingLimitResponse parses an HTTP response from a GetSpendingLimitWithResponse call +func ParseGetSpendingLimitResponse(rsp *http.Response) (*GetSpendingLimitResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &GetSpendingLimitResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest SpendingLimit + 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 == 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 == 403: + var dest Forbidden + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON403 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest NotFound + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON404 = &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 +} + +// ParseCreateSpendingLimitResponse parses an HTTP response from a CreateSpendingLimitWithResponse call +func ParseCreateSpendingLimitResponse(rsp *http.Response) (*CreateSpendingLimitResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &CreateSpendingLimitResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 201: + var dest SpendingLimit + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON201 = &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 == 403: + var dest Forbidden + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON403 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest NotFound + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON404 = &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 +} + +// ParseUpdateSpendingLimitResponse parses an HTTP response from a UpdateSpendingLimitWithResponse call +func ParseUpdateSpendingLimitResponse(rsp *http.Response) (*UpdateSpendingLimitResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &UpdateSpendingLimitResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest SpendingLimit + 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 == 403: + var dest Forbidden + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON403 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest NotFound + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON404 = &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 +} + // ParseListSubscriptionOrdersByTeamResponse parses an HTTP response from a ListSubscriptionOrdersByTeamWithResponse call func ParseListSubscriptionOrdersByTeamResponse(rsp *http.Response) (*ListSubscriptionOrdersByTeamResponse, error) { bodyBytes, err := io.ReadAll(rsp.Body) diff --git a/models.gen.go b/models.gen.go index 87513fc..3e86ccb 100644 --- a/models.gen.go +++ b/models.gen.go @@ -154,8 +154,10 @@ const ( // Defines values for TeamPlan. const ( - Free TeamPlan = "free" - Paid TeamPlan = "paid" + Enterprise TeamPlan = "enterprise" + Free TeamPlan = "free" + Paid TeamPlan = "paid" + Trial TeamPlan = "trial" ) // Defines values for TeamSubscriptionOrderStatus. @@ -1209,6 +1211,30 @@ type ReleaseURL struct { Url string `json:"url"` } +// SpendingLimit A configurable spending limit for the team. +type SpendingLimit struct { + // CreatedAt The date and time the team limit was created. + CreatedAt time.Time `json:"created_at"` + + // UpdatedAt The date and time the team limit was last updated. + UpdatedAt time.Time `json:"updated_at"` + + // Usd The maximum USD amount the team is allowed to use within a calendar month. + USD int `json:"usd"` +} + +// SpendingLimitCreate A configurable monthly limit for team usage. +type SpendingLimitCreate struct { + // Usd The maximum USD amount the team is allowed to use within a calendar month. + USD int `json:"usd"` +} + +// SpendingLimitUpdate A configurable spending limit for the team. +type SpendingLimitUpdate struct { + // Usd The maximum USD amount the team is allowed to use within a calendar month. + USD int `json:"usd"` +} + // Sync Managed Sync definition type Sync struct { // Cpu CPU quota for the sync @@ -1641,8 +1667,15 @@ type UsageIncrease struct { // RequestId A unique ID associated with the usage increase. RequestId openapi_types.UUID `json:"request_id"` - // Rows The additional rows used by the plugin. - Rows int `json:"rows"` + // Rows The total number of additional rows used by the plugin. + Rows int `json:"rows"` + Tables *[]struct { + // Name The name of the table. + Name string `json:"name"` + + // Rows The additional rows used by the table. + Rows int `json:"rows"` + } `json:"tables,omitempty"` } // User CloudQuery User @@ -2264,6 +2297,12 @@ type CreateMonthlyLimitJSONRequestBody = MonthlyLimitCreate // UpdateMonthlyLimitJSONRequestBody defines body for UpdateMonthlyLimit for application/json ContentType. type UpdateMonthlyLimitJSONRequestBody = MonthlyLimitUpdate +// CreateSpendingLimitJSONRequestBody defines body for CreateSpendingLimit for application/json ContentType. +type CreateSpendingLimitJSONRequestBody = SpendingLimitCreate + +// UpdateSpendingLimitJSONRequestBody defines body for UpdateSpendingLimit for application/json ContentType. +type UpdateSpendingLimitJSONRequestBody = SpendingLimitUpdate + // CreateSubscriptionOrderForTeamJSONRequestBody defines body for CreateSubscriptionOrderForTeam for application/json ContentType. type CreateSubscriptionOrderForTeamJSONRequestBody = TeamSubscriptionOrderCreate diff --git a/spec.json b/spec.json index 2267851..6cfd450 100644 --- a/spec.json +++ b/spec.json @@ -3161,6 +3161,169 @@ ] } }, + "/teams/{team_name}/spending-limits": { + "get": { + "description": "Get monthly spending limit for team.", + "operationId": "GetSpendingLimit", + "parameters": [ + { + "$ref": "#/components/parameters/team_name" + } + ], + "responses": { + "200": { + "description": "Spending limit retrieved.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/SpendingLimit" + } + } + } + }, + "401": { + "$ref": "#/components/responses/RequiresAuthentication" + }, + "403": { + "$ref": "#/components/responses/Forbidden" + }, + "404": { + "$ref": "#/components/responses/NotFound" + }, + "500": { + "$ref": "#/components/responses/InternalError" + } + }, + "tags": [ + "teams" + ] + }, + "post": { + "description": "Create a spending limit for a team", + "operationId": "CreateSpendingLimit", + "parameters": [ + { + "$ref": "#/components/parameters/team_name" + } + ], + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/SpendingLimitCreate" + } + } + } + }, + "responses": { + "201": { + "description": "New spending limit created.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/SpendingLimit" + } + } + } + }, + "401": { + "$ref": "#/components/responses/RequiresAuthentication" + }, + "403": { + "$ref": "#/components/responses/Forbidden" + }, + "404": { + "$ref": "#/components/responses/NotFound" + }, + "422": { + "$ref": "#/components/responses/UnprocessableEntity" + }, + "500": { + "$ref": "#/components/responses/InternalError" + } + }, + "tags": [ + "teams" + ] + }, + "put": { + "description": "Update a spending limit for a team", + "operationId": "UpdateSpendingLimit", + "parameters": [ + { + "$ref": "#/components/parameters/team_name" + } + ], + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/SpendingLimitUpdate" + } + } + } + }, + "responses": { + "200": { + "description": "Spending limit updated.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/SpendingLimit" + } + } + } + }, + "400": { + "$ref": "#/components/responses/BadRequest" + }, + "401": { + "$ref": "#/components/responses/RequiresAuthentication" + }, + "403": { + "$ref": "#/components/responses/Forbidden" + }, + "404": { + "$ref": "#/components/responses/NotFound" + }, + "500": { + "$ref": "#/components/responses/InternalError" + } + }, + "tags": [ + "teams" + ] + }, + "delete": { + "description": "Delete a spending limit for a team", + "operationId": "DeleteSpendingLimit", + "parameters": [ + { + "$ref": "#/components/parameters/team_name" + } + ], + "responses": { + "204": { + "description": "Spending limit deleted." + }, + "401": { + "$ref": "#/components/responses/RequiresAuthentication" + }, + "403": { + "$ref": "#/components/responses/Forbidden" + }, + "404": { + "$ref": "#/components/responses/NotFound" + }, + "500": { + "$ref": "#/components/responses/InternalError" + } + }, + "tags": [ + "teams" + ] + } + }, "/teams/{team_name}/monthly-limits/{plugin_team}/{plugin_kind}/{plugin_name}": { "get": { "description": "Get a monthly limit for a plugin", @@ -7214,7 +7377,9 @@ "type": "string", "enum": [ "free", - "paid" + "paid", + "enterprise", + "trial" ] }, "Team": { @@ -7542,6 +7707,77 @@ } } }, + "SpendingLimit": { + "title": "Team Spending Limit", + "description": "A configurable spending limit for the team.", + "type": "object", + "additionalProperties": false, + "required": [ + "created_at", + "updated_at", + "usd" + ], + "properties": { + "created_at": { + "example": "2017-07-14T16:53:42Z", + "format": "date-time", + "type": "string", + "description": "The date and time the team limit was created." + }, + "updated_at": { + "example": "2017-07-14T16:53:42Z", + "format": "date-time", + "type": "string", + "description": "The date and time the team limit was last updated." + }, + "usd": { + "example": 1000, + "type": "integer", + "minimum": 0, + "maximum": 1000000000, + "description": "The maximum USD amount the team is allowed to use within a calendar month.", + "x-go-name": "USD" + } + } + }, + "SpendingLimitUpdate": { + "title": "Team Spending Limit", + "description": "A configurable spending limit for the team.", + "type": "object", + "additionalProperties": false, + "required": [ + "usd" + ], + "properties": { + "usd": { + "example": 1000, + "type": "integer", + "minimum": 0, + "maximum": 1000000000, + "description": "The maximum USD amount the team is allowed to use within a calendar month.", + "x-go-name": "USD" + } + } + }, + "SpendingLimitCreate": { + "title": "Team Spending Limit", + "description": "A configurable monthly limit for team usage.", + "type": "object", + "additionalProperties": false, + "required": [ + "usd" + ], + "properties": { + "usd": { + "example": 1000, + "type": "integer", + "minimum": 0, + "maximum": 1000000000, + "description": "The maximum USD amount the team is allowed to use within a calendar month.", + "x-go-name": "USD" + } + } + }, "MonthlyLimitUpdate": { "title": "CloudQuery Plugin Monthly Limit", "description": "A configurable monthly limit for plugin usage.", @@ -7674,11 +7910,34 @@ "plugin_name": { "$ref": "#/components/schemas/PluginName" }, + "tables": { + "type": "array", + "items": { + "type": "object", + "required": [ + "name", + "rows" + ], + "properties": { + "name": { + "type": "string", + "description": "The name of the table.", + "example": "my_table" + }, + "rows": { + "type": "integer", + "minimum": 0, + "description": "The additional rows used by the table.", + "example": 100 + } + } + } + }, "rows": { "example": 1000000, "type": "integer", "minimum": 0, - "description": "The additional rows used by the plugin." + "description": "The total number of additional rows used by the plugin." }, "request_id": { "type": "string", From 738de6d0c2b5e8d260e33f8ccd7343fc7a291c49 Mon Sep 17 00:00:00 2001 From: Erez Rokah Date: Thu, 4 Apr 2024 11:30:30 +0200 Subject: [PATCH 2/4] fix: Disable retry logging (#144) --- client.gen.go | 4 +++- templates/client.tmpl | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/client.gen.go b/client.gen.go index 7a640df..4b4e1fd 100644 --- a/client.gen.go +++ b/client.gen.go @@ -49,7 +49,9 @@ type ClientOption func(*Client) error // Creates a new Client, with reasonable defaults func NewClient(server string, opts ...ClientOption) (*Client, error) { - opts = append([]ClientOption{WithHTTPClient(retryablehttp.NewClient().StandardClient())}, opts...) + retryClient := retryablehttp.NewClient() + retryClient.Logger = nil + opts = append([]ClientOption{WithHTTPClient(retryClient.StandardClient())}, opts...) // create a client with sane default values client := Client{ Server: server, diff --git a/templates/client.tmpl b/templates/client.tmpl index 8d2f604..92deb84 100644 --- a/templates/client.tmpl +++ b/templates/client.tmpl @@ -32,7 +32,9 @@ type ClientOption func(*{{ $clientTypeName }}) error // Creates a new {{ $clientTypeName }}, with reasonable defaults func NewClient(server string, opts ...ClientOption) (*{{ $clientTypeName }}, error) { - opts = append([]ClientOption{WithHTTPClient(retryablehttp.NewClient().StandardClient())}, opts...) + retryClient := retryablehttp.NewClient() + retryClient.Logger = nil + opts = append([]ClientOption{WithHTTPClient(retryClient.StandardClient())}, opts...) // create a client with sane default values client := {{ $clientTypeName }}{ Server: server, From dfa5a8af33c13e0ae3f6e9837856e21e04907177 Mon Sep 17 00:00:00 2001 From: Erez Rokah Date: Thu, 4 Apr 2024 11:33:11 +0200 Subject: [PATCH 3/4] refactor: Use spaces (#145) --- templates/client.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/client.tmpl b/templates/client.tmpl index 92deb84..bfe47aa 100644 --- a/templates/client.tmpl +++ b/templates/client.tmpl @@ -33,7 +33,7 @@ type ClientOption func(*{{ $clientTypeName }}) error // Creates a new {{ $clientTypeName }}, with reasonable defaults func NewClient(server string, opts ...ClientOption) (*{{ $clientTypeName }}, error) { retryClient := retryablehttp.NewClient() - retryClient.Logger = nil + retryClient.Logger = nil opts = append([]ClientOption{WithHTTPClient(retryClient.StandardClient())}, opts...) // create a client with sane default values client := {{ $clientTypeName }}{ From 20d6b4e785021fb4cd76b32880d6514d74b6b815 Mon Sep 17 00:00:00 2001 From: CloudQuery Bot <102256036+cq-bot@users.noreply.github.com> Date: Thu, 4 Apr 2024 12:36:49 +0300 Subject: [PATCH 4/4] chore(main): Release v1.9.1 (#143) :robot: I have created a release *beep* *boop* --- ## [1.9.1](https://github.com/cloudquery/cloudquery-api-go/compare/v1.9.0...v1.9.1) (2024-04-04) ### Bug Fixes * Disable retry logging ([#144](https://github.com/cloudquery/cloudquery-api-go/issues/144)) ([738de6d](https://github.com/cloudquery/cloudquery-api-go/commit/738de6d0c2b5e8d260e33f8ccd7343fc7a291c49)) * Generate CloudQuery Go API Client from `spec.json` ([#142](https://github.com/cloudquery/cloudquery-api-go/issues/142)) ([b8ead7c](https://github.com/cloudquery/cloudquery-api-go/commit/b8ead7c4ae372f36266dd437f0590067ce731598)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cde2c2d..78ecdd7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## [1.9.1](https://github.com/cloudquery/cloudquery-api-go/compare/v1.9.0...v1.9.1) (2024-04-04) + + +### Bug Fixes + +* Disable retry logging ([#144](https://github.com/cloudquery/cloudquery-api-go/issues/144)) ([738de6d](https://github.com/cloudquery/cloudquery-api-go/commit/738de6d0c2b5e8d260e33f8ccd7343fc7a291c49)) +* Generate CloudQuery Go API Client from `spec.json` ([#142](https://github.com/cloudquery/cloudquery-api-go/issues/142)) ([b8ead7c](https://github.com/cloudquery/cloudquery-api-go/commit/b8ead7c4ae372f36266dd437f0590067ce731598)) + ## [1.9.0](https://github.com/cloudquery/cloudquery-api-go/compare/v1.8.1...v1.9.0) (2024-03-28)