From 10911731e04565974e65c5bc2369e773d4396662 Mon Sep 17 00:00:00 2001 From: cq-bot Date: Wed, 21 Aug 2024 09:59:26 +0000 Subject: [PATCH] fix: Generate CloudQuery Go API Client from `spec.json` --- client.gen.go | 305 ++++++++++++++++++++++++++++++++++++++++++++++++++ models.gen.go | 82 ++++++++++++++ spec.json | 107 ++++++++++++++++++ 3 files changed, 494 insertions(+) diff --git a/client.gen.go b/client.gen.go index 8677550..67b3d2a 100644 --- a/client.gen.go +++ b/client.gen.go @@ -609,9 +609,17 @@ type ClientInterface interface { // ListCurrentUserInvitations request ListCurrentUserInvitations(ctx context.Context, params *ListCurrentUserInvitationsParams, reqEditors ...RequestEditorFn) (*http.Response, error) + // LoginUserWithBody request with any body + LoginUserWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) + + LoginUser(ctx context.Context, body LoginUserJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + // GetCurrentUserMemberships request GetCurrentUserMemberships(ctx context.Context, params *GetCurrentUserMembershipsParams, reqEditors ...RequestEditorFn) (*http.Response, error) + // CreateUserToken request + CreateUserToken(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) + // DeleteUser request DeleteUser(ctx context.Context, userID UserID, reqEditors ...RequestEditorFn) (*http.Response, error) } @@ -2884,6 +2892,30 @@ func (c *Client) ListCurrentUserInvitations(ctx context.Context, params *ListCur return c.Client.Do(req) } +func (c *Client) LoginUserWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewLoginUserRequestWithBody(c.Server, 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) LoginUser(ctx context.Context, body LoginUserJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewLoginUserRequest(c.Server, 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) GetCurrentUserMemberships(ctx context.Context, params *GetCurrentUserMembershipsParams, reqEditors ...RequestEditorFn) (*http.Response, error) { req, err := NewGetCurrentUserMembershipsRequest(c.Server, params) if err != nil { @@ -2896,6 +2928,18 @@ func (c *Client) GetCurrentUserMemberships(ctx context.Context, params *GetCurre return c.Client.Do(req) } +func (c *Client) CreateUserToken(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewCreateUserTokenRequest(c.Server) + 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) DeleteUser(ctx context.Context, userID UserID, reqEditors ...RequestEditorFn) (*http.Response, error) { req, err := NewDeleteUserRequest(c.Server, userID) if err != nil { @@ -10751,6 +10795,46 @@ func NewListCurrentUserInvitationsRequest(server string, params *ListCurrentUser return req, nil } +// NewLoginUserRequest calls the generic LoginUser builder with application/json body +func NewLoginUserRequest(server string, body LoginUserJSONRequestBody) (*http.Request, error) { + var bodyReader io.Reader + buf, err := json.Marshal(body) + if err != nil { + return nil, err + } + bodyReader = bytes.NewReader(buf) + return NewLoginUserRequestWithBody(server, "application/json", bodyReader) +} + +// NewLoginUserRequestWithBody generates requests for LoginUser with any type of body +func NewLoginUserRequestWithBody(server string, contentType string, body io.Reader) (*http.Request, error) { + var err error + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/user/login") + 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 +} + // NewGetCurrentUserMembershipsRequest generates requests for GetCurrentUserMemberships func NewGetCurrentUserMembershipsRequest(server string, params *GetCurrentUserMembershipsParams) (*http.Request, error) { var err error @@ -10816,6 +10900,33 @@ func NewGetCurrentUserMembershipsRequest(server string, params *GetCurrentUserMe return req, nil } +// NewCreateUserTokenRequest generates requests for CreateUserToken +func NewCreateUserTokenRequest(server string) (*http.Request, error) { + var err error + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/user/token") + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("POST", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + // NewDeleteUserRequest generates requests for DeleteUser func NewDeleteUserRequest(server string, userID UserID) (*http.Request, error) { var err error @@ -11409,9 +11520,17 @@ type ClientWithResponsesInterface interface { // ListCurrentUserInvitationsWithResponse request ListCurrentUserInvitationsWithResponse(ctx context.Context, params *ListCurrentUserInvitationsParams, reqEditors ...RequestEditorFn) (*ListCurrentUserInvitationsResponse, error) + // LoginUserWithBodyWithResponse request with any body + LoginUserWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*LoginUserResponse, error) + + LoginUserWithResponse(ctx context.Context, body LoginUserJSONRequestBody, reqEditors ...RequestEditorFn) (*LoginUserResponse, error) + // GetCurrentUserMembershipsWithResponse request GetCurrentUserMembershipsWithResponse(ctx context.Context, params *GetCurrentUserMembershipsParams, reqEditors ...RequestEditorFn) (*GetCurrentUserMembershipsResponse, error) + // CreateUserTokenWithResponse request + CreateUserTokenWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*CreateUserTokenResponse, error) + // DeleteUserWithResponse request DeleteUserWithResponse(ctx context.Context, userID UserID, reqEditors ...RequestEditorFn) (*DeleteUserResponse, error) } @@ -15019,6 +15138,33 @@ func (r ListCurrentUserInvitationsResponse) StatusCode() int { return 0 } +type LoginUserResponse struct { + Body []byte + HTTPResponse *http.Response + JSON400 *BadRequest + JSON401 *RequiresAuthentication + JSON403 *Forbidden + JSON404 *NotFound + JSON405 *MethodNotAllowed + JSON500 *InternalError +} + +// Status returns HTTPResponse.Status +func (r LoginUserResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r LoginUserResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + type GetCurrentUserMembershipsResponse struct { Body []byte HTTPResponse *http.Response @@ -15044,6 +15190,31 @@ func (r GetCurrentUserMembershipsResponse) StatusCode() int { return 0 } +type CreateUserTokenResponse struct { + Body []byte + HTTPResponse *http.Response + JSON201 *CreateUserToken201Response + JSON400 *BadRequest + JSON401 *RequiresAuthentication + JSON500 *InternalError +} + +// Status returns HTTPResponse.Status +func (r CreateUserTokenResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r CreateUserTokenResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + type DeleteUserResponse struct { Body []byte HTTPResponse *http.Response @@ -16721,6 +16892,23 @@ func (c *ClientWithResponses) ListCurrentUserInvitationsWithResponse(ctx context return ParseListCurrentUserInvitationsResponse(rsp) } +// LoginUserWithBodyWithResponse request with arbitrary body returning *LoginUserResponse +func (c *ClientWithResponses) LoginUserWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*LoginUserResponse, error) { + rsp, err := c.LoginUserWithBody(ctx, contentType, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseLoginUserResponse(rsp) +} + +func (c *ClientWithResponses) LoginUserWithResponse(ctx context.Context, body LoginUserJSONRequestBody, reqEditors ...RequestEditorFn) (*LoginUserResponse, error) { + rsp, err := c.LoginUser(ctx, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseLoginUserResponse(rsp) +} + // GetCurrentUserMembershipsWithResponse request returning *GetCurrentUserMembershipsResponse func (c *ClientWithResponses) GetCurrentUserMembershipsWithResponse(ctx context.Context, params *GetCurrentUserMembershipsParams, reqEditors ...RequestEditorFn) (*GetCurrentUserMembershipsResponse, error) { rsp, err := c.GetCurrentUserMemberships(ctx, params, reqEditors...) @@ -16730,6 +16918,15 @@ func (c *ClientWithResponses) GetCurrentUserMembershipsWithResponse(ctx context. return ParseGetCurrentUserMembershipsResponse(rsp) } +// CreateUserTokenWithResponse request returning *CreateUserTokenResponse +func (c *ClientWithResponses) CreateUserTokenWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*CreateUserTokenResponse, error) { + rsp, err := c.CreateUserToken(ctx, reqEditors...) + if err != nil { + return nil, err + } + return ParseCreateUserTokenResponse(rsp) +} + // DeleteUserWithResponse request returning *DeleteUserResponse func (c *ClientWithResponses) DeleteUserWithResponse(ctx context.Context, userID UserID, reqEditors ...RequestEditorFn) (*DeleteUserResponse, error) { rsp, err := c.DeleteUser(ctx, userID, reqEditors...) @@ -24296,6 +24493,67 @@ func ParseListCurrentUserInvitationsResponse(rsp *http.Response) (*ListCurrentUs return response, nil } +// ParseLoginUserResponse parses an HTTP response from a LoginUserWithResponse call +func ParseLoginUserResponse(rsp *http.Response) (*LoginUserResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &LoginUserResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + 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 == 405: + var dest MethodNotAllowed + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON405 = &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 +} + // ParseGetCurrentUserMembershipsResponse parses an HTTP response from a GetCurrentUserMembershipsWithResponse call func ParseGetCurrentUserMembershipsResponse(rsp *http.Response) (*GetCurrentUserMembershipsResponse, error) { bodyBytes, err := io.ReadAll(rsp.Body) @@ -24343,6 +24601,53 @@ func ParseGetCurrentUserMembershipsResponse(rsp *http.Response) (*GetCurrentUser return response, nil } +// ParseCreateUserTokenResponse parses an HTTP response from a CreateUserTokenWithResponse call +func ParseCreateUserTokenResponse(rsp *http.Response) (*CreateUserTokenResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &CreateUserTokenResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 201: + var dest CreateUserToken201Response + 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 == 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 == 500: + var dest InternalError + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON500 = &dest + + } + + return response, nil +} + // ParseDeleteUserResponse parses an HTTP response from a DeleteUserWithResponse call func ParseDeleteUserResponse(rsp *http.Response) (*DeleteUserResponse, error) { bodyBytes, err := io.ReadAll(rsp.Body) diff --git a/models.gen.go b/models.gen.go index 7fb482f..709687a 100644 --- a/models.gen.go +++ b/models.gen.go @@ -14,6 +14,7 @@ import ( const ( BasicAuthScopes = "basicAuth.Scopes" BearerAuthScopes = "bearerAuth.Scopes" + CookieAuthScopes = "cookieAuth.Scopes" ) // Defines values for APIKeyScope. @@ -858,6 +859,12 @@ type CreateTeamRequest struct { AdditionalProperties map[string]interface{} `json:"-"` } +// CreateUserToken201Response defines model for CreateUserToken_201_response. +type CreateUserToken201Response struct { + // CustomToken Token to exchange for refresh token + CustomToken string `json:"custom_token"` +} + // DeletePluginVersionDocsRequest defines model for DeletePluginVersionDocs_request. type DeletePluginVersionDocsRequest struct { Names []PluginDocsPageName `json:"names"` @@ -1252,6 +1259,12 @@ type ListUsersByTeam200Response struct { Metadata ListMetadata `json:"metadata"` } +// LoginUserRequest defines model for LoginUser_request. +type LoginUserRequest struct { + IDToken interface{} `json:"id_token"` + AdditionalProperties map[string]interface{} `json:"-"` +} + // ManagedDatabase Managed Database definition type ManagedDatabase struct { // ConnectionString The connection string to the database @@ -3380,6 +3393,9 @@ type IncreaseTeamPluginUsageJSONRequestBody = UsageIncrease // UpdateCurrentUserJSONRequestBody defines body for UpdateCurrentUser for application/json ContentType. type UpdateCurrentUserJSONRequestBody = UpdateCurrentUserRequest +// LoginUserJSONRequestBody defines body for LoginUser for application/json ContentType. +type LoginUserJSONRequestBody = LoginUserRequest + // Getter for additional properties for ConnectorAuthFinishRequestOAuth. Returns the specified // element and whether it was found func (a ConnectorAuthFinishRequestOAuth) Get(fieldName string) (value interface{}, found bool) { @@ -3945,6 +3961,72 @@ func (a CreateTeamRequest) MarshalJSON() ([]byte, error) { return json.Marshal(object) } +// Getter for additional properties for LoginUserRequest. Returns the specified +// element and whether it was found +func (a LoginUserRequest) Get(fieldName string) (value interface{}, found bool) { + if a.AdditionalProperties != nil { + value, found = a.AdditionalProperties[fieldName] + } + return +} + +// Setter for additional properties for LoginUserRequest +func (a *LoginUserRequest) Set(fieldName string, value interface{}) { + if a.AdditionalProperties == nil { + a.AdditionalProperties = make(map[string]interface{}) + } + a.AdditionalProperties[fieldName] = value +} + +// Override default JSON handling for LoginUserRequest to handle AdditionalProperties +func (a *LoginUserRequest) UnmarshalJSON(b []byte) error { + object := make(map[string]json.RawMessage) + err := json.Unmarshal(b, &object) + if err != nil { + return err + } + + if raw, found := object["id_token"]; found { + err = json.Unmarshal(raw, &a.IDToken) + if err != nil { + return fmt.Errorf("error reading 'id_token': %w", err) + } + delete(object, "id_token") + } + + if len(object) != 0 { + a.AdditionalProperties = make(map[string]interface{}) + for fieldName, fieldBuf := range object { + var fieldVal interface{} + err := json.Unmarshal(fieldBuf, &fieldVal) + if err != nil { + return fmt.Errorf("error unmarshaling field %s: %w", fieldName, err) + } + a.AdditionalProperties[fieldName] = fieldVal + } + } + return nil +} + +// Override default JSON handling for LoginUserRequest to handle AdditionalProperties +func (a LoginUserRequest) MarshalJSON() ([]byte, error) { + var err error + object := make(map[string]json.RawMessage) + + object["id_token"], err = json.Marshal(a.IDToken) + if err != nil { + return nil, fmt.Errorf("error marshaling 'id_token': %w", err) + } + + for fieldName, field := range a.AdditionalProperties { + object[fieldName], err = json.Marshal(field) + if err != nil { + return nil, fmt.Errorf("error marshaling '%s': %w", fieldName, err) + } + } + return json.Marshal(object) +} + // Getter for additional properties for SpendSummary. Returns the specified // element and whether it was found func (a SpendSummary) Get(fieldName string) (value interface{}, found bool) { diff --git a/spec.json b/spec.json index c00a940..0608af3 100644 --- a/spec.json +++ b/spec.json @@ -21,6 +21,8 @@ } ], "security" : [ { "bearerAuth" : [ ] + }, { + "cookieAuth" : [ ] } ], "tags" : [ { "name" : "users" @@ -3573,6 +3575,89 @@ "tags" : [ "users" ] } }, + "/user/login" : { + "post" : { + "description" : "Start a session using ID token", + "operationId" : "LoginUser", + "parameters" : [ ], + "requestBody" : { + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/LoginUser_request" + } + } + } + }, + "responses" : { + "204" : { + "description" : "Authentication is complete.", + "headers" : { + "Set-Cookie" : { + "description" : "Session cookie", + "explode" : false, + "schema" : { + "example" : "__session=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9Cg...; HttpOnly; Secure; SameSite=Strict; Path=/; Max-Age=3600", + "type" : "string" + }, + "style" : "simple" + } + } + }, + "400" : { + "$ref" : "#/components/responses/BadRequest" + }, + "401" : { + "$ref" : "#/components/responses/RequiresAuthentication" + }, + "403" : { + "$ref" : "#/components/responses/Forbidden" + }, + "404" : { + "$ref" : "#/components/responses/NotFound" + }, + "405" : { + "$ref" : "#/components/responses/MethodNotAllowed" + }, + "500" : { + "$ref" : "#/components/responses/InternalError" + } + }, + "security" : [ ], + "tags" : [ "users" ] + } + }, + "/user/token" : { + "post" : { + "description" : "Start a CLI session and create a custom token", + "operationId" : "CreateUserToken", + "responses" : { + "201" : { + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/CreateUserToken_201_response" + } + } + }, + "description" : "Response" + }, + "400" : { + "$ref" : "#/components/responses/BadRequest" + }, + "401" : { + "$ref" : "#/components/responses/RequiresAuthentication" + }, + "500" : { + "$ref" : "#/components/responses/InternalError" + } + }, + "security" : [ { + "cookieAuth" : [ ] + } ], + "tags" : [ "users" ] + } + }, "/user/invitations" : { "get" : { "description" : "List of the current user's unaccepted invitations", @@ -10251,6 +10336,24 @@ } } }, + "LoginUser_request" : { + "additionalProperties" : { }, + "properties" : { + "id_token" : { + "x-go-name" : "IDToken" + } + }, + "required" : [ "id_token" ] + }, + "CreateUserToken_201_response" : { + "properties" : { + "custom_token" : { + "description" : "Token to exchange for refresh token", + "type" : "string" + } + }, + "required" : [ "custom_token" ] + }, "ListCurrentUserInvitations_200_response" : { "properties" : { "items" : { @@ -10567,6 +10670,10 @@ "basicAuth" : { "scheme" : "basic", "type" : "http" + }, + "cookieAuth" : { + "scheme" : "cookie", + "type" : "http" } } }