Merged in feature/client (pull request #31)

Client Entity

* repolevel

* servicefunctions

* openapiclientget

* openapiupdate

* client

* vendor
This commit is contained in:
Michael McGuinness
2025-01-21 18:24:14 +00:00
parent 4ccb980593
commit 04d8eaf52c
39 changed files with 1532 additions and 432 deletions
+434 -116
View File
@@ -41,6 +41,21 @@ const (
JSONEXTRACTOR QueryType = "JSON_EXTRACTOR"
)
// ClientCreate defines model for ClientCreate.
type ClientCreate struct {
// Name The client name
Name string `json:"name"`
}
// ClientUpdate defines model for ClientUpdate.
type ClientUpdate struct {
// CanSync If the client is allowing active syncs
CanSync *bool `json:"can_sync,omitempty"`
// Name The client name
Name *string `json:"name,omitempty"`
}
// ExportDetails Payload for export trigger response.
type ExportDetails struct {
// JobId The job id relative to the export.
@@ -95,6 +110,18 @@ type IdMessage struct {
Id string `json:"id"`
}
// JobClient defines model for JobClient.
type JobClient struct {
// CanSync If the client is allowing active syncs
CanSync bool `json:"can_sync"`
// Id The client id
Id string `json:"id"`
// Name The client name
Name string `json:"name"`
}
// JobCollector JobCollector model.
type JobCollector struct {
// ActiveVersion The active version of the collector.
@@ -209,6 +236,12 @@ type QueryUpdate struct {
RequiredQueries *[]string `json:"required_queries,omitempty"`
}
// CreateClientJSONRequestBody defines body for CreateClient for application/json ContentType.
type CreateClientJSONRequestBody = ClientCreate
// UpdateClientJSONRequestBody defines body for UpdateClient for application/json ContentType.
type UpdateClientJSONRequestBody = ClientUpdate
// TriggerExportJSONRequestBody defines body for TriggerExport for application/json ContentType.
type TriggerExportJSONRequestBody = ExportTrigger
@@ -297,6 +330,19 @@ func WithRequestEditorFn(fn RequestEditorFn) ClientOption {
// The interface specification for the client above.
type ClientInterface interface {
// CreateClientWithBody request with any body
CreateClientWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)
CreateClient(ctx context.Context, body CreateClientJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)
// GetClient request
GetClient(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*http.Response, error)
// UpdateClientWithBody request with any body
UpdateClientWithBody(ctx context.Context, id string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)
UpdateClient(ctx context.Context, id string, body UpdateClientJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)
// TriggerExportWithBody request with any body
TriggerExportWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)
@@ -321,11 +367,8 @@ type ClientInterface interface {
CreateQuery(ctx context.Context, body CreateQueryJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)
// DeprecateQuery request
DeprecateQuery(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*http.Response, error)
// GetQueryById request
GetQueryById(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*http.Response, error)
// GetQuery request
GetQuery(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*http.Response, error)
// UpdateQueryWithBody request with any body
UpdateQueryWithBody(ctx context.Context, id string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)
@@ -338,6 +381,66 @@ type ClientInterface interface {
TestQuery(ctx context.Context, id string, body TestQueryJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)
}
func (c *Client) CreateClientWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) {
req, err := NewCreateClientRequestWithBody(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) CreateClient(ctx context.Context, body CreateClientJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) {
req, err := NewCreateClientRequest(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) GetClient(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*http.Response, error) {
req, err := NewGetClientRequest(c.Server, id)
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) UpdateClientWithBody(ctx context.Context, id string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) {
req, err := NewUpdateClientRequestWithBody(c.Server, id, 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) UpdateClient(ctx context.Context, id string, body UpdateClientJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) {
req, err := NewUpdateClientRequest(c.Server, id, 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) TriggerExportWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) {
req, err := NewTriggerExportRequestWithBody(c.Server, contentType, body)
if err != nil {
@@ -446,20 +549,8 @@ func (c *Client) CreateQuery(ctx context.Context, body CreateQueryJSONRequestBod
return c.Client.Do(req)
}
func (c *Client) DeprecateQuery(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*http.Response, error) {
req, err := NewDeprecateQueryRequest(c.Server, id)
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) GetQueryById(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*http.Response, error) {
req, err := NewGetQueryByIdRequest(c.Server, id)
func (c *Client) GetQuery(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*http.Response, error) {
req, err := NewGetQueryRequest(c.Server, id)
if err != nil {
return nil, err
}
@@ -518,6 +609,127 @@ func (c *Client) TestQuery(ctx context.Context, id string, body TestQueryJSONReq
return c.Client.Do(req)
}
// NewCreateClientRequest calls the generic CreateClient builder with application/json body
func NewCreateClientRequest(server string, body CreateClientJSONRequestBody) (*http.Request, error) {
var bodyReader io.Reader
buf, err := json.Marshal(body)
if err != nil {
return nil, err
}
bodyReader = bytes.NewReader(buf)
return NewCreateClientRequestWithBody(server, "application/json", bodyReader)
}
// NewCreateClientRequestWithBody generates requests for CreateClient with any type of body
func NewCreateClientRequestWithBody(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("/clients")
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
}
// NewGetClientRequest generates requests for GetClient
func NewGetClientRequest(server string, id string) (*http.Request, error) {
var err error
var pathParam0 string
pathParam0, err = runtime.StyleParamWithLocation("simple", false, "id", runtime.ParamLocationPath, id)
if err != nil {
return nil, err
}
serverURL, err := url.Parse(server)
if err != nil {
return nil, err
}
operationPath := fmt.Sprintf("/clients/%s", 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
}
// NewUpdateClientRequest calls the generic UpdateClient builder with application/json body
func NewUpdateClientRequest(server string, id string, body UpdateClientJSONRequestBody) (*http.Request, error) {
var bodyReader io.Reader
buf, err := json.Marshal(body)
if err != nil {
return nil, err
}
bodyReader = bytes.NewReader(buf)
return NewUpdateClientRequestWithBody(server, id, "application/json", bodyReader)
}
// NewUpdateClientRequestWithBody generates requests for UpdateClient with any type of body
func NewUpdateClientRequestWithBody(server string, id string, contentType string, body io.Reader) (*http.Request, error) {
var err error
var pathParam0 string
pathParam0, err = runtime.StyleParamWithLocation("simple", false, "id", runtime.ParamLocationPath, id)
if err != nil {
return nil, err
}
serverURL, err := url.Parse(server)
if err != nil {
return nil, err
}
operationPath := fmt.Sprintf("/clients/%s", pathParam0)
if operationPath[0] == '/' {
operationPath = "." + operationPath
}
queryURL, err := serverURL.Parse(operationPath)
if err != nil {
return nil, err
}
req, err := http.NewRequest("PATCH", queryURL.String(), body)
if err != nil {
return nil, err
}
req.Header.Add("Content-Type", contentType)
return req, nil
}
// NewTriggerExportRequest calls the generic TriggerExport builder with application/json body
func NewTriggerExportRequest(server string, body TriggerExportJSONRequestBody) (*http.Request, error) {
var bodyReader io.Reader
@@ -740,42 +952,8 @@ func NewCreateQueryRequestWithBody(server string, contentType string, body io.Re
return req, nil
}
// NewDeprecateQueryRequest generates requests for DeprecateQuery
func NewDeprecateQueryRequest(server string, id string) (*http.Request, error) {
var err error
var pathParam0 string
pathParam0, err = runtime.StyleParamWithLocation("simple", false, "id", runtime.ParamLocationPath, id)
if err != nil {
return nil, err
}
serverURL, err := url.Parse(server)
if err != nil {
return nil, err
}
operationPath := fmt.Sprintf("/queries/%s", 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
}
// NewGetQueryByIdRequest generates requests for GetQueryById
func NewGetQueryByIdRequest(server string, id string) (*http.Request, error) {
// NewGetQueryRequest generates requests for GetQuery
func NewGetQueryRequest(server string, id string) (*http.Request, error) {
var err error
var pathParam0 string
@@ -945,6 +1123,19 @@ func WithBaseURL(baseURL string) ClientOption {
// ClientWithResponsesInterface is the interface specification for the client with responses above.
type ClientWithResponsesInterface interface {
// CreateClientWithBodyWithResponse request with any body
CreateClientWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*CreateClientResponse, error)
CreateClientWithResponse(ctx context.Context, body CreateClientJSONRequestBody, reqEditors ...RequestEditorFn) (*CreateClientResponse, error)
// GetClientWithResponse request
GetClientWithResponse(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*GetClientResponse, error)
// UpdateClientWithBodyWithResponse request with any body
UpdateClientWithBodyWithResponse(ctx context.Context, id string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*UpdateClientResponse, error)
UpdateClientWithResponse(ctx context.Context, id string, body UpdateClientJSONRequestBody, reqEditors ...RequestEditorFn) (*UpdateClientResponse, error)
// TriggerExportWithBodyWithResponse request with any body
TriggerExportWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*TriggerExportResponse, error)
@@ -969,11 +1160,8 @@ type ClientWithResponsesInterface interface {
CreateQueryWithResponse(ctx context.Context, body CreateQueryJSONRequestBody, reqEditors ...RequestEditorFn) (*CreateQueryResponse, error)
// DeprecateQueryWithResponse request
DeprecateQueryWithResponse(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*DeprecateQueryResponse, error)
// GetQueryByIdWithResponse request
GetQueryByIdWithResponse(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*GetQueryByIdResponse, error)
// GetQueryWithResponse request
GetQueryWithResponse(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*GetQueryResponse, error)
// UpdateQueryWithBodyWithResponse request with any body
UpdateQueryWithBodyWithResponse(ctx context.Context, id string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*UpdateQueryResponse, error)
@@ -986,6 +1174,71 @@ type ClientWithResponsesInterface interface {
TestQueryWithResponse(ctx context.Context, id string, body TestQueryJSONRequestBody, reqEditors ...RequestEditorFn) (*TestQueryResponse, error)
}
type CreateClientResponse struct {
Body []byte
HTTPResponse *http.Response
JSON201 *IdMessage
}
// Status returns HTTPResponse.Status
func (r CreateClientResponse) Status() string {
if r.HTTPResponse != nil {
return r.HTTPResponse.Status
}
return http.StatusText(0)
}
// StatusCode returns HTTPResponse.StatusCode
func (r CreateClientResponse) StatusCode() int {
if r.HTTPResponse != nil {
return r.HTTPResponse.StatusCode
}
return 0
}
type GetClientResponse struct {
Body []byte
HTTPResponse *http.Response
JSON200 *JobClient
}
// Status returns HTTPResponse.Status
func (r GetClientResponse) Status() string {
if r.HTTPResponse != nil {
return r.HTTPResponse.Status
}
return http.StatusText(0)
}
// StatusCode returns HTTPResponse.StatusCode
func (r GetClientResponse) StatusCode() int {
if r.HTTPResponse != nil {
return r.HTTPResponse.StatusCode
}
return 0
}
type UpdateClientResponse struct {
Body []byte
HTTPResponse *http.Response
}
// Status returns HTTPResponse.Status
func (r UpdateClientResponse) Status() string {
if r.HTTPResponse != nil {
return r.HTTPResponse.Status
}
return http.StatusText(0)
}
// StatusCode returns HTTPResponse.StatusCode
func (r UpdateClientResponse) StatusCode() int {
if r.HTTPResponse != nil {
return r.HTTPResponse.StatusCode
}
return 0
}
type TriggerExportResponse struct {
Body []byte
HTTPResponse *http.Response
@@ -1117,35 +1370,14 @@ func (r CreateQueryResponse) StatusCode() int {
return 0
}
type DeprecateQueryResponse struct {
Body []byte
HTTPResponse *http.Response
}
// Status returns HTTPResponse.Status
func (r DeprecateQueryResponse) Status() string {
if r.HTTPResponse != nil {
return r.HTTPResponse.Status
}
return http.StatusText(0)
}
// StatusCode returns HTTPResponse.StatusCode
func (r DeprecateQueryResponse) StatusCode() int {
if r.HTTPResponse != nil {
return r.HTTPResponse.StatusCode
}
return 0
}
type GetQueryByIdResponse struct {
type GetQueryResponse struct {
Body []byte
HTTPResponse *http.Response
JSON200 *Query
}
// Status returns HTTPResponse.Status
func (r GetQueryByIdResponse) Status() string {
func (r GetQueryResponse) Status() string {
if r.HTTPResponse != nil {
return r.HTTPResponse.Status
}
@@ -1153,7 +1385,7 @@ func (r GetQueryByIdResponse) Status() string {
}
// StatusCode returns HTTPResponse.StatusCode
func (r GetQueryByIdResponse) StatusCode() int {
func (r GetQueryResponse) StatusCode() int {
if r.HTTPResponse != nil {
return r.HTTPResponse.StatusCode
}
@@ -1203,6 +1435,49 @@ func (r TestQueryResponse) StatusCode() int {
return 0
}
// CreateClientWithBodyWithResponse request with arbitrary body returning *CreateClientResponse
func (c *ClientWithResponses) CreateClientWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*CreateClientResponse, error) {
rsp, err := c.CreateClientWithBody(ctx, contentType, body, reqEditors...)
if err != nil {
return nil, err
}
return ParseCreateClientResponse(rsp)
}
func (c *ClientWithResponses) CreateClientWithResponse(ctx context.Context, body CreateClientJSONRequestBody, reqEditors ...RequestEditorFn) (*CreateClientResponse, error) {
rsp, err := c.CreateClient(ctx, body, reqEditors...)
if err != nil {
return nil, err
}
return ParseCreateClientResponse(rsp)
}
// GetClientWithResponse request returning *GetClientResponse
func (c *ClientWithResponses) GetClientWithResponse(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*GetClientResponse, error) {
rsp, err := c.GetClient(ctx, id, reqEditors...)
if err != nil {
return nil, err
}
return ParseGetClientResponse(rsp)
}
// UpdateClientWithBodyWithResponse request with arbitrary body returning *UpdateClientResponse
func (c *ClientWithResponses) UpdateClientWithBodyWithResponse(ctx context.Context, id string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*UpdateClientResponse, error) {
rsp, err := c.UpdateClientWithBody(ctx, id, contentType, body, reqEditors...)
if err != nil {
return nil, err
}
return ParseUpdateClientResponse(rsp)
}
func (c *ClientWithResponses) UpdateClientWithResponse(ctx context.Context, id string, body UpdateClientJSONRequestBody, reqEditors ...RequestEditorFn) (*UpdateClientResponse, error) {
rsp, err := c.UpdateClient(ctx, id, body, reqEditors...)
if err != nil {
return nil, err
}
return ParseUpdateClientResponse(rsp)
}
// TriggerExportWithBodyWithResponse request with arbitrary body returning *TriggerExportResponse
func (c *ClientWithResponses) TriggerExportWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*TriggerExportResponse, error) {
rsp, err := c.TriggerExportWithBody(ctx, contentType, body, reqEditors...)
@@ -1281,22 +1556,13 @@ func (c *ClientWithResponses) CreateQueryWithResponse(ctx context.Context, body
return ParseCreateQueryResponse(rsp)
}
// DeprecateQueryWithResponse request returning *DeprecateQueryResponse
func (c *ClientWithResponses) DeprecateQueryWithResponse(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*DeprecateQueryResponse, error) {
rsp, err := c.DeprecateQuery(ctx, id, reqEditors...)
// GetQueryWithResponse request returning *GetQueryResponse
func (c *ClientWithResponses) GetQueryWithResponse(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*GetQueryResponse, error) {
rsp, err := c.GetQuery(ctx, id, reqEditors...)
if err != nil {
return nil, err
}
return ParseDeprecateQueryResponse(rsp)
}
// GetQueryByIdWithResponse request returning *GetQueryByIdResponse
func (c *ClientWithResponses) GetQueryByIdWithResponse(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*GetQueryByIdResponse, error) {
rsp, err := c.GetQueryById(ctx, id, reqEditors...)
if err != nil {
return nil, err
}
return ParseGetQueryByIdResponse(rsp)
return ParseGetQueryResponse(rsp)
}
// UpdateQueryWithBodyWithResponse request with arbitrary body returning *UpdateQueryResponse
@@ -1333,6 +1599,74 @@ func (c *ClientWithResponses) TestQueryWithResponse(ctx context.Context, id stri
return ParseTestQueryResponse(rsp)
}
// ParseCreateClientResponse parses an HTTP response from a CreateClientWithResponse call
func ParseCreateClientResponse(rsp *http.Response) (*CreateClientResponse, error) {
bodyBytes, err := io.ReadAll(rsp.Body)
defer func() { _ = rsp.Body.Close() }()
if err != nil {
return nil, err
}
response := &CreateClientResponse{
Body: bodyBytes,
HTTPResponse: rsp,
}
switch {
case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 201:
var dest IdMessage
if err := json.Unmarshal(bodyBytes, &dest); err != nil {
return nil, err
}
response.JSON201 = &dest
}
return response, nil
}
// ParseGetClientResponse parses an HTTP response from a GetClientWithResponse call
func ParseGetClientResponse(rsp *http.Response) (*GetClientResponse, error) {
bodyBytes, err := io.ReadAll(rsp.Body)
defer func() { _ = rsp.Body.Close() }()
if err != nil {
return nil, err
}
response := &GetClientResponse{
Body: bodyBytes,
HTTPResponse: rsp,
}
switch {
case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200:
var dest JobClient
if err := json.Unmarshal(bodyBytes, &dest); err != nil {
return nil, err
}
response.JSON200 = &dest
}
return response, nil
}
// ParseUpdateClientResponse parses an HTTP response from a UpdateClientWithResponse call
func ParseUpdateClientResponse(rsp *http.Response) (*UpdateClientResponse, error) {
bodyBytes, err := io.ReadAll(rsp.Body)
defer func() { _ = rsp.Body.Close() }()
if err != nil {
return nil, err
}
response := &UpdateClientResponse{
Body: bodyBytes,
HTTPResponse: rsp,
}
return response, nil
}
// ParseTriggerExportResponse parses an HTTP response from a TriggerExportWithResponse call
func ParseTriggerExportResponse(rsp *http.Response) (*TriggerExportResponse, error) {
bodyBytes, err := io.ReadAll(rsp.Body)
@@ -1479,31 +1813,15 @@ func ParseCreateQueryResponse(rsp *http.Response) (*CreateQueryResponse, error)
return response, nil
}
// ParseDeprecateQueryResponse parses an HTTP response from a DeprecateQueryWithResponse call
func ParseDeprecateQueryResponse(rsp *http.Response) (*DeprecateQueryResponse, error) {
// ParseGetQueryResponse parses an HTTP response from a GetQueryWithResponse call
func ParseGetQueryResponse(rsp *http.Response) (*GetQueryResponse, error) {
bodyBytes, err := io.ReadAll(rsp.Body)
defer func() { _ = rsp.Body.Close() }()
if err != nil {
return nil, err
}
response := &DeprecateQueryResponse{
Body: bodyBytes,
HTTPResponse: rsp,
}
return response, nil
}
// ParseGetQueryByIdResponse parses an HTTP response from a GetQueryByIdWithResponse call
func ParseGetQueryByIdResponse(rsp *http.Response) (*GetQueryByIdResponse, error) {
bodyBytes, err := io.ReadAll(rsp.Body)
defer func() { _ = rsp.Body.Close() }()
if err != nil {
return nil, err
}
response := &GetQueryByIdResponse{
response := &GetQueryResponse{
Body: bodyBytes,
HTTPResponse: rsp,
}