pkg/api/client.gen.go (1,769 lines of code) (raw):

// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one // or more contributor license agreements. Licensed under the Elastic License; // you may not use this file except in compliance with the Elastic License. // Package api provides primitives to interact with the openapi HTTP API. // // Code generated by github.com/deepmap/oapi-codegen/v2 version v2.0.0 DO NOT EDIT. package api import ( "bytes" "context" "encoding/json" "fmt" "io" "net/http" "net/url" "strings" "github.com/oapi-codegen/runtime" ) // RequestEditorFn is the function signature for the RequestEditor callback function type RequestEditorFn func(ctx context.Context, req *http.Request) error // Doer performs HTTP requests. // // The standard http.Client implements this interface. type HttpRequestDoer interface { Do(req *http.Request) (*http.Response, error) } // Client which conforms to the OpenAPI3 specification for this service. type Client struct { // The endpoint of the server conforming to this interface, with scheme, // https://api.deepmap.com for example. This can contain a path relative // to the server, such as https://api.deepmap.com/dev-test, and all the // paths in the swagger spec will be appended to the server. Server string // Doer for performing requests, typically a *http.Client with any // customized settings, such as certificate chains. Client HttpRequestDoer // A list of callbacks for modifying requests which are generated before sending over // the network. RequestEditors []RequestEditorFn } // ClientOption allows setting custom parameters during construction type ClientOption func(*Client) error // Creates a new Client, with reasonable defaults func NewClient(server string, opts ...ClientOption) (*Client, error) { // create a client with sane default values client := Client{ Server: server, } // mutate client and add all optional params for _, o := range opts { if err := o(&client); err != nil { return nil, err } } // ensure the server URL always has a trailing slash if !strings.HasSuffix(client.Server, "/") { client.Server += "/" } // create httpClient, if not already present if client.Client == nil { client.Client = &http.Client{} } return &client, nil } // WithHTTPClient allows overriding the default Doer, which is // automatically created using http.Client. This is useful for tests. func WithHTTPClient(doer HttpRequestDoer) ClientOption { return func(c *Client) error { c.Client = doer return nil } } // WithRequestEditorFn allows setting up a callback function, which will be // called right before sending the request. This can be used to mutate the request. func WithRequestEditorFn(fn RequestEditorFn) ClientOption { return func(c *Client) error { c.RequestEditors = append(c.RequestEditors, fn) return nil } } // The interface specification for the client above. type ClientInterface interface { // GetPGPKey request GetPGPKey(ctx context.Context, major int, minor int, patch int, params *GetPGPKeyParams, reqEditors ...RequestEditorFn) (*http.Response, error) // AgentEnrollWithBody request with any body AgentEnrollWithBody(ctx context.Context, params *AgentEnrollParams, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) AgentEnroll(ctx context.Context, params *AgentEnrollParams, body AgentEnrollJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) // AgentAcksWithBody request with any body AgentAcksWithBody(ctx context.Context, id string, params *AgentAcksParams, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) AgentAcks(ctx context.Context, id string, params *AgentAcksParams, body AgentAcksJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) // AuditUnenrollWithBody request with any body AuditUnenrollWithBody(ctx context.Context, id string, params *AuditUnenrollParams, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) AuditUnenroll(ctx context.Context, id string, params *AuditUnenrollParams, body AuditUnenrollJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) // AgentCheckinWithBody request with any body AgentCheckinWithBody(ctx context.Context, id string, params *AgentCheckinParams, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) AgentCheckin(ctx context.Context, id string, params *AgentCheckinParams, body AgentCheckinJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) // Artifact request Artifact(ctx context.Context, id string, sha2 string, params *ArtifactParams, reqEditors ...RequestEditorFn) (*http.Response, error) // GetFile request GetFile(ctx context.Context, id string, params *GetFileParams, reqEditors ...RequestEditorFn) (*http.Response, error) // UploadBeginWithBody request with any body UploadBeginWithBody(ctx context.Context, params *UploadBeginParams, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) UploadBegin(ctx context.Context, params *UploadBeginParams, body UploadBeginJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) // UploadCompleteWithBody request with any body UploadCompleteWithBody(ctx context.Context, id string, params *UploadCompleteParams, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) UploadComplete(ctx context.Context, id string, params *UploadCompleteParams, body UploadCompleteJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) // UploadChunkWithBody request with any body UploadChunkWithBody(ctx context.Context, id string, chunkNum int, params *UploadChunkParams, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) // Status request Status(ctx context.Context, params *StatusParams, reqEditors ...RequestEditorFn) (*http.Response, error) } func (c *Client) GetPGPKey(ctx context.Context, major int, minor int, patch int, params *GetPGPKeyParams, reqEditors ...RequestEditorFn) (*http.Response, error) { req, err := NewGetPGPKeyRequest(c.Server, major, minor, patch, 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) AgentEnrollWithBody(ctx context.Context, params *AgentEnrollParams, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { req, err := NewAgentEnrollRequestWithBody(c.Server, params, 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) AgentEnroll(ctx context.Context, params *AgentEnrollParams, body AgentEnrollJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { req, err := NewAgentEnrollRequest(c.Server, params, 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) AgentAcksWithBody(ctx context.Context, id string, params *AgentAcksParams, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { req, err := NewAgentAcksRequestWithBody(c.Server, id, params, 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) AgentAcks(ctx context.Context, id string, params *AgentAcksParams, body AgentAcksJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { req, err := NewAgentAcksRequest(c.Server, id, params, 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) AuditUnenrollWithBody(ctx context.Context, id string, params *AuditUnenrollParams, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { req, err := NewAuditUnenrollRequestWithBody(c.Server, id, params, 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) AuditUnenroll(ctx context.Context, id string, params *AuditUnenrollParams, body AuditUnenrollJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { req, err := NewAuditUnenrollRequest(c.Server, id, params, 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) AgentCheckinWithBody(ctx context.Context, id string, params *AgentCheckinParams, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { req, err := NewAgentCheckinRequestWithBody(c.Server, id, params, 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) AgentCheckin(ctx context.Context, id string, params *AgentCheckinParams, body AgentCheckinJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { req, err := NewAgentCheckinRequest(c.Server, id, params, 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) Artifact(ctx context.Context, id string, sha2 string, params *ArtifactParams, reqEditors ...RequestEditorFn) (*http.Response, error) { req, err := NewArtifactRequest(c.Server, id, sha2, 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) GetFile(ctx context.Context, id string, params *GetFileParams, reqEditors ...RequestEditorFn) (*http.Response, error) { req, err := NewGetFileRequest(c.Server, id, 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) UploadBeginWithBody(ctx context.Context, params *UploadBeginParams, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { req, err := NewUploadBeginRequestWithBody(c.Server, params, 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) UploadBegin(ctx context.Context, params *UploadBeginParams, body UploadBeginJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { req, err := NewUploadBeginRequest(c.Server, params, 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) UploadCompleteWithBody(ctx context.Context, id string, params *UploadCompleteParams, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { req, err := NewUploadCompleteRequestWithBody(c.Server, id, params, 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) UploadComplete(ctx context.Context, id string, params *UploadCompleteParams, body UploadCompleteJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { req, err := NewUploadCompleteRequest(c.Server, id, params, 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) UploadChunkWithBody(ctx context.Context, id string, chunkNum int, params *UploadChunkParams, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { req, err := NewUploadChunkRequestWithBody(c.Server, id, chunkNum, params, 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) Status(ctx context.Context, params *StatusParams, reqEditors ...RequestEditorFn) (*http.Response, error) { req, err := NewStatusRequest(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) } // NewGetPGPKeyRequest generates requests for GetPGPKey func NewGetPGPKeyRequest(server string, major int, minor int, patch int, params *GetPGPKeyParams) (*http.Request, error) { var err error var pathParam0 string pathParam0, err = runtime.StyleParamWithLocation("simple", false, "major", runtime.ParamLocationPath, major) if err != nil { return nil, err } var pathParam1 string pathParam1, err = runtime.StyleParamWithLocation("simple", false, "minor", runtime.ParamLocationPath, minor) if err != nil { return nil, err } var pathParam2 string pathParam2, err = runtime.StyleParamWithLocation("simple", false, "patch", runtime.ParamLocationPath, patch) if err != nil { return nil, err } serverURL, err := url.Parse(server) if err != nil { return nil, err } operationPath := fmt.Sprintf("/api/agents/upgrades/%s.%s.%s/pgp-public-key", pathParam0, pathParam1, pathParam2) 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 } if params != nil { if params.ElasticApiVersion != nil { var headerParam0 string headerParam0, err = runtime.StyleParamWithLocation("simple", false, "elastic-api-version", runtime.ParamLocationHeader, *params.ElasticApiVersion) if err != nil { return nil, err } req.Header.Set("elastic-api-version", headerParam0) } if params.XRequestId != nil { var headerParam1 string headerParam1, err = runtime.StyleParamWithLocation("simple", false, "X-Request-Id", runtime.ParamLocationHeader, *params.XRequestId) if err != nil { return nil, err } req.Header.Set("X-Request-Id", headerParam1) } } return req, nil } // NewAgentEnrollRequest calls the generic AgentEnroll builder with application/json body func NewAgentEnrollRequest(server string, params *AgentEnrollParams, body AgentEnrollJSONRequestBody) (*http.Request, error) { var bodyReader io.Reader buf, err := json.Marshal(body) if err != nil { return nil, err } bodyReader = bytes.NewReader(buf) return NewAgentEnrollRequestWithBody(server, params, "application/json", bodyReader) } // NewAgentEnrollRequestWithBody generates requests for AgentEnroll with any type of body func NewAgentEnrollRequestWithBody(server string, params *AgentEnrollParams, 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("/api/fleet/agents/enroll") 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) if params != nil { var headerParam0 string headerParam0, err = runtime.StyleParamWithLocation("simple", false, "User-Agent", runtime.ParamLocationHeader, params.UserAgent) if err != nil { return nil, err } req.Header.Set("User-Agent", headerParam0) if params.XRequestId != nil { var headerParam1 string headerParam1, err = runtime.StyleParamWithLocation("simple", false, "X-Request-Id", runtime.ParamLocationHeader, *params.XRequestId) if err != nil { return nil, err } req.Header.Set("X-Request-Id", headerParam1) } if params.ElasticApiVersion != nil { var headerParam2 string headerParam2, err = runtime.StyleParamWithLocation("simple", false, "elastic-api-version", runtime.ParamLocationHeader, *params.ElasticApiVersion) if err != nil { return nil, err } req.Header.Set("elastic-api-version", headerParam2) } } return req, nil } // NewAgentAcksRequest calls the generic AgentAcks builder with application/json body func NewAgentAcksRequest(server string, id string, params *AgentAcksParams, body AgentAcksJSONRequestBody) (*http.Request, error) { var bodyReader io.Reader buf, err := json.Marshal(body) if err != nil { return nil, err } bodyReader = bytes.NewReader(buf) return NewAgentAcksRequestWithBody(server, id, params, "application/json", bodyReader) } // NewAgentAcksRequestWithBody generates requests for AgentAcks with any type of body func NewAgentAcksRequestWithBody(server string, id string, params *AgentAcksParams, 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("/api/fleet/agents/%s/acks", 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) if params != nil { if params.XRequestId != nil { var headerParam0 string headerParam0, err = runtime.StyleParamWithLocation("simple", false, "X-Request-Id", runtime.ParamLocationHeader, *params.XRequestId) if err != nil { return nil, err } req.Header.Set("X-Request-Id", headerParam0) } if params.ElasticApiVersion != nil { var headerParam1 string headerParam1, err = runtime.StyleParamWithLocation("simple", false, "elastic-api-version", runtime.ParamLocationHeader, *params.ElasticApiVersion) if err != nil { return nil, err } req.Header.Set("elastic-api-version", headerParam1) } } return req, nil } // NewAuditUnenrollRequest calls the generic AuditUnenroll builder with application/json body func NewAuditUnenrollRequest(server string, id string, params *AuditUnenrollParams, body AuditUnenrollJSONRequestBody) (*http.Request, error) { var bodyReader io.Reader buf, err := json.Marshal(body) if err != nil { return nil, err } bodyReader = bytes.NewReader(buf) return NewAuditUnenrollRequestWithBody(server, id, params, "application/json", bodyReader) } // NewAuditUnenrollRequestWithBody generates requests for AuditUnenroll with any type of body func NewAuditUnenrollRequestWithBody(server string, id string, params *AuditUnenrollParams, 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("/api/fleet/agents/%s/audit/unenroll", 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) if params != nil { if params.XRequestId != nil { var headerParam0 string headerParam0, err = runtime.StyleParamWithLocation("simple", false, "X-Request-Id", runtime.ParamLocationHeader, *params.XRequestId) if err != nil { return nil, err } req.Header.Set("X-Request-Id", headerParam0) } if params.ElasticApiVersion != nil { var headerParam1 string headerParam1, err = runtime.StyleParamWithLocation("simple", false, "elastic-api-version", runtime.ParamLocationHeader, *params.ElasticApiVersion) if err != nil { return nil, err } req.Header.Set("elastic-api-version", headerParam1) } } return req, nil } // NewAgentCheckinRequest calls the generic AgentCheckin builder with application/json body func NewAgentCheckinRequest(server string, id string, params *AgentCheckinParams, body AgentCheckinJSONRequestBody) (*http.Request, error) { var bodyReader io.Reader buf, err := json.Marshal(body) if err != nil { return nil, err } bodyReader = bytes.NewReader(buf) return NewAgentCheckinRequestWithBody(server, id, params, "application/json", bodyReader) } // NewAgentCheckinRequestWithBody generates requests for AgentCheckin with any type of body func NewAgentCheckinRequestWithBody(server string, id string, params *AgentCheckinParams, 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("/api/fleet/agents/%s/checkin", 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) if params != nil { if params.AcceptEncoding != nil { var headerParam0 string headerParam0, err = runtime.StyleParamWithLocation("simple", false, "Accept-Encoding", runtime.ParamLocationHeader, *params.AcceptEncoding) if err != nil { return nil, err } req.Header.Set("Accept-Encoding", headerParam0) } var headerParam1 string headerParam1, err = runtime.StyleParamWithLocation("simple", false, "User-Agent", runtime.ParamLocationHeader, params.UserAgent) if err != nil { return nil, err } req.Header.Set("User-Agent", headerParam1) if params.XRequestId != nil { var headerParam2 string headerParam2, err = runtime.StyleParamWithLocation("simple", false, "X-Request-Id", runtime.ParamLocationHeader, *params.XRequestId) if err != nil { return nil, err } req.Header.Set("X-Request-Id", headerParam2) } if params.ElasticApiVersion != nil { var headerParam3 string headerParam3, err = runtime.StyleParamWithLocation("simple", false, "elastic-api-version", runtime.ParamLocationHeader, *params.ElasticApiVersion) if err != nil { return nil, err } req.Header.Set("elastic-api-version", headerParam3) } } return req, nil } // NewArtifactRequest generates requests for Artifact func NewArtifactRequest(server string, id string, sha2 string, params *ArtifactParams) (*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 } var pathParam1 string pathParam1, err = runtime.StyleParamWithLocation("simple", false, "sha2", runtime.ParamLocationPath, sha2) if err != nil { return nil, err } serverURL, err := url.Parse(server) if err != nil { return nil, err } operationPath := fmt.Sprintf("/api/fleet/artifacts/%s/%s", pathParam0, pathParam1) 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 } if params != nil { if params.XRequestId != nil { var headerParam0 string headerParam0, err = runtime.StyleParamWithLocation("simple", false, "X-Request-Id", runtime.ParamLocationHeader, *params.XRequestId) if err != nil { return nil, err } req.Header.Set("X-Request-Id", headerParam0) } if params.ElasticApiVersion != nil { var headerParam1 string headerParam1, err = runtime.StyleParamWithLocation("simple", false, "elastic-api-version", runtime.ParamLocationHeader, *params.ElasticApiVersion) if err != nil { return nil, err } req.Header.Set("elastic-api-version", headerParam1) } } return req, nil } // NewGetFileRequest generates requests for GetFile func NewGetFileRequest(server string, id string, params *GetFileParams) (*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("/api/fleet/file/%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 } if params != nil { if params.ElasticApiVersion != nil { var headerParam0 string headerParam0, err = runtime.StyleParamWithLocation("simple", false, "elastic-api-version", runtime.ParamLocationHeader, *params.ElasticApiVersion) if err != nil { return nil, err } req.Header.Set("elastic-api-version", headerParam0) } if params.XRequestId != nil { var headerParam1 string headerParam1, err = runtime.StyleParamWithLocation("simple", false, "X-Request-Id", runtime.ParamLocationHeader, *params.XRequestId) if err != nil { return nil, err } req.Header.Set("X-Request-Id", headerParam1) } } return req, nil } // NewUploadBeginRequest calls the generic UploadBegin builder with application/json body func NewUploadBeginRequest(server string, params *UploadBeginParams, body UploadBeginJSONRequestBody) (*http.Request, error) { var bodyReader io.Reader buf, err := json.Marshal(body) if err != nil { return nil, err } bodyReader = bytes.NewReader(buf) return NewUploadBeginRequestWithBody(server, params, "application/json", bodyReader) } // NewUploadBeginRequestWithBody generates requests for UploadBegin with any type of body func NewUploadBeginRequestWithBody(server string, params *UploadBeginParams, 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("/api/fleet/uploads") 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) if params != nil { if params.XRequestId != nil { var headerParam0 string headerParam0, err = runtime.StyleParamWithLocation("simple", false, "X-Request-Id", runtime.ParamLocationHeader, *params.XRequestId) if err != nil { return nil, err } req.Header.Set("X-Request-Id", headerParam0) } if params.ElasticApiVersion != nil { var headerParam1 string headerParam1, err = runtime.StyleParamWithLocation("simple", false, "elastic-api-version", runtime.ParamLocationHeader, *params.ElasticApiVersion) if err != nil { return nil, err } req.Header.Set("elastic-api-version", headerParam1) } } return req, nil } // NewUploadCompleteRequest calls the generic UploadComplete builder with application/json body func NewUploadCompleteRequest(server string, id string, params *UploadCompleteParams, body UploadCompleteJSONRequestBody) (*http.Request, error) { var bodyReader io.Reader buf, err := json.Marshal(body) if err != nil { return nil, err } bodyReader = bytes.NewReader(buf) return NewUploadCompleteRequestWithBody(server, id, params, "application/json", bodyReader) } // NewUploadCompleteRequestWithBody generates requests for UploadComplete with any type of body func NewUploadCompleteRequestWithBody(server string, id string, params *UploadCompleteParams, 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("/api/fleet/uploads/%s", 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) if params != nil { if params.XRequestId != nil { var headerParam0 string headerParam0, err = runtime.StyleParamWithLocation("simple", false, "X-Request-Id", runtime.ParamLocationHeader, *params.XRequestId) if err != nil { return nil, err } req.Header.Set("X-Request-Id", headerParam0) } if params.ElasticApiVersion != nil { var headerParam1 string headerParam1, err = runtime.StyleParamWithLocation("simple", false, "elastic-api-version", runtime.ParamLocationHeader, *params.ElasticApiVersion) if err != nil { return nil, err } req.Header.Set("elastic-api-version", headerParam1) } } return req, nil } // NewUploadChunkRequestWithBody generates requests for UploadChunk with any type of body func NewUploadChunkRequestWithBody(server string, id string, chunkNum int, params *UploadChunkParams, 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 } var pathParam1 string pathParam1, err = runtime.StyleParamWithLocation("simple", false, "chunkNum", runtime.ParamLocationPath, chunkNum) if err != nil { return nil, err } serverURL, err := url.Parse(server) if err != nil { return nil, err } operationPath := fmt.Sprintf("/api/fleet/uploads/%s/%s", pathParam0, pathParam1) 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) if params != nil { var headerParam0 string headerParam0, err = runtime.StyleParamWithLocation("simple", false, "X-Chunk-SHA2", runtime.ParamLocationHeader, params.XChunkSHA2) if err != nil { return nil, err } req.Header.Set("X-Chunk-SHA2", headerParam0) if params.XRequestId != nil { var headerParam1 string headerParam1, err = runtime.StyleParamWithLocation("simple", false, "X-Request-Id", runtime.ParamLocationHeader, *params.XRequestId) if err != nil { return nil, err } req.Header.Set("X-Request-Id", headerParam1) } if params.ElasticApiVersion != nil { var headerParam2 string headerParam2, err = runtime.StyleParamWithLocation("simple", false, "elastic-api-version", runtime.ParamLocationHeader, *params.ElasticApiVersion) if err != nil { return nil, err } req.Header.Set("elastic-api-version", headerParam2) } } return req, nil } // NewStatusRequest generates requests for Status func NewStatusRequest(server string, params *StatusParams) (*http.Request, error) { var err error serverURL, err := url.Parse(server) if err != nil { return nil, err } operationPath := fmt.Sprintf("/api/status") 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 } if params != nil { if params.XRequestId != nil { var headerParam0 string headerParam0, err = runtime.StyleParamWithLocation("simple", false, "X-Request-Id", runtime.ParamLocationHeader, *params.XRequestId) if err != nil { return nil, err } req.Header.Set("X-Request-Id", headerParam0) } if params.ElasticApiVersion != nil { var headerParam1 string headerParam1, err = runtime.StyleParamWithLocation("simple", false, "elastic-api-version", runtime.ParamLocationHeader, *params.ElasticApiVersion) if err != nil { return nil, err } req.Header.Set("elastic-api-version", headerParam1) } } return req, nil } func (c *Client) applyEditors(ctx context.Context, req *http.Request, additionalEditors []RequestEditorFn) error { for _, r := range c.RequestEditors { if err := r(ctx, req); err != nil { return err } } for _, r := range additionalEditors { if err := r(ctx, req); err != nil { return err } } return nil } // ClientWithResponses builds on ClientInterface to offer response payloads type ClientWithResponses struct { ClientInterface } // NewClientWithResponses creates a new ClientWithResponses, which wraps // Client with return type handling func NewClientWithResponses(server string, opts ...ClientOption) (*ClientWithResponses, error) { client, err := NewClient(server, opts...) if err != nil { return nil, err } return &ClientWithResponses{client}, nil } // WithBaseURL overrides the baseURL. func WithBaseURL(baseURL string) ClientOption { return func(c *Client) error { newBaseURL, err := url.Parse(baseURL) if err != nil { return err } c.Server = newBaseURL.String() return nil } } // ClientWithResponsesInterface is the interface specification for the client with responses above. type ClientWithResponsesInterface interface { // GetPGPKeyWithResponse request GetPGPKeyWithResponse(ctx context.Context, major int, minor int, patch int, params *GetPGPKeyParams, reqEditors ...RequestEditorFn) (*GetPGPKeyResponse, error) // AgentEnrollWithBodyWithResponse request with any body AgentEnrollWithBodyWithResponse(ctx context.Context, params *AgentEnrollParams, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*AgentEnrollResponse, error) AgentEnrollWithResponse(ctx context.Context, params *AgentEnrollParams, body AgentEnrollJSONRequestBody, reqEditors ...RequestEditorFn) (*AgentEnrollResponse, error) // AgentAcksWithBodyWithResponse request with any body AgentAcksWithBodyWithResponse(ctx context.Context, id string, params *AgentAcksParams, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*AgentAcksResponse, error) AgentAcksWithResponse(ctx context.Context, id string, params *AgentAcksParams, body AgentAcksJSONRequestBody, reqEditors ...RequestEditorFn) (*AgentAcksResponse, error) // AuditUnenrollWithBodyWithResponse request with any body AuditUnenrollWithBodyWithResponse(ctx context.Context, id string, params *AuditUnenrollParams, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*AuditUnenrollResponse, error) AuditUnenrollWithResponse(ctx context.Context, id string, params *AuditUnenrollParams, body AuditUnenrollJSONRequestBody, reqEditors ...RequestEditorFn) (*AuditUnenrollResponse, error) // AgentCheckinWithBodyWithResponse request with any body AgentCheckinWithBodyWithResponse(ctx context.Context, id string, params *AgentCheckinParams, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*AgentCheckinResponse, error) AgentCheckinWithResponse(ctx context.Context, id string, params *AgentCheckinParams, body AgentCheckinJSONRequestBody, reqEditors ...RequestEditorFn) (*AgentCheckinResponse, error) // ArtifactWithResponse request ArtifactWithResponse(ctx context.Context, id string, sha2 string, params *ArtifactParams, reqEditors ...RequestEditorFn) (*ArtifactResponse, error) // GetFileWithResponse request GetFileWithResponse(ctx context.Context, id string, params *GetFileParams, reqEditors ...RequestEditorFn) (*GetFileResponse, error) // UploadBeginWithBodyWithResponse request with any body UploadBeginWithBodyWithResponse(ctx context.Context, params *UploadBeginParams, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*UploadBeginResponse, error) UploadBeginWithResponse(ctx context.Context, params *UploadBeginParams, body UploadBeginJSONRequestBody, reqEditors ...RequestEditorFn) (*UploadBeginResponse, error) // UploadCompleteWithBodyWithResponse request with any body UploadCompleteWithBodyWithResponse(ctx context.Context, id string, params *UploadCompleteParams, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*UploadCompleteResponse, error) UploadCompleteWithResponse(ctx context.Context, id string, params *UploadCompleteParams, body UploadCompleteJSONRequestBody, reqEditors ...RequestEditorFn) (*UploadCompleteResponse, error) // UploadChunkWithBodyWithResponse request with any body UploadChunkWithBodyWithResponse(ctx context.Context, id string, chunkNum int, params *UploadChunkParams, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*UploadChunkResponse, error) // StatusWithResponse request StatusWithResponse(ctx context.Context, params *StatusParams, reqEditors ...RequestEditorFn) (*StatusResponse, error) } type GetPGPKeyResponse struct { Body []byte HTTPResponse *http.Response JSON400 *BadRequest } // Status returns HTTPResponse.Status func (r GetPGPKeyResponse) Status() string { if r.HTTPResponse != nil { return r.HTTPResponse.Status } return http.StatusText(0) } // StatusCode returns HTTPResponse.StatusCode func (r GetPGPKeyResponse) StatusCode() int { if r.HTTPResponse != nil { return r.HTTPResponse.StatusCode } return 0 } type AgentEnrollResponse struct { Body []byte HTTPResponse *http.Response JSON200 *EnrollResponse JSON400 *BadRequest JSON401 *KeyNotEnabled JSON408 *Deadline JSON500 *InternalServerError JSON503 *Unavailable } // Status returns HTTPResponse.Status func (r AgentEnrollResponse) Status() string { if r.HTTPResponse != nil { return r.HTTPResponse.Status } return http.StatusText(0) } // StatusCode returns HTTPResponse.StatusCode func (r AgentEnrollResponse) StatusCode() int { if r.HTTPResponse != nil { return r.HTTPResponse.StatusCode } return 0 } type AgentAcksResponse struct { Body []byte HTTPResponse *http.Response JSON200 *AckResponse JSON400 *BadRequest JSON401 *KeyNotEnabled JSON403 *Forbidden JSON404 *AgentNotFound JSON408 *Deadline JSON500 *InternalServerError JSON503 *Unavailable } // Status returns HTTPResponse.Status func (r AgentAcksResponse) Status() string { if r.HTTPResponse != nil { return r.HTTPResponse.Status } return http.StatusText(0) } // StatusCode returns HTTPResponse.StatusCode func (r AgentAcksResponse) StatusCode() int { if r.HTTPResponse != nil { return r.HTTPResponse.StatusCode } return 0 } type AuditUnenrollResponse struct { Body []byte HTTPResponse *http.Response JSON400 *BadRequest JSON401 *KeyNotEnabled JSON409 *Conflict JSON500 *InternalServerError JSON503 *Unavailable } // Status returns HTTPResponse.Status func (r AuditUnenrollResponse) Status() string { if r.HTTPResponse != nil { return r.HTTPResponse.Status } return http.StatusText(0) } // StatusCode returns HTTPResponse.StatusCode func (r AuditUnenrollResponse) StatusCode() int { if r.HTTPResponse != nil { return r.HTTPResponse.StatusCode } return 0 } type AgentCheckinResponse struct { Body []byte HTTPResponse *http.Response JSON200 *CheckinResponse JSON400 *BadRequest JSON401 *KeyNotEnabled JSON403 *Forbidden JSON404 *AgentNotFound JSON408 *Deadline JSON500 *InternalServerError JSON503 *Unavailable } // Status returns HTTPResponse.Status func (r AgentCheckinResponse) Status() string { if r.HTTPResponse != nil { return r.HTTPResponse.Status } return http.StatusText(0) } // StatusCode returns HTTPResponse.StatusCode func (r AgentCheckinResponse) StatusCode() int { if r.HTTPResponse != nil { return r.HTTPResponse.StatusCode } return 0 } type ArtifactResponse struct { Body []byte HTTPResponse *http.Response JSON400 *BadRequest JSON401 *KeyNotEnabled JSON404 *AgentNotFound JSON408 *Deadline JSON428 *Throttle JSON500 *InternalServerError JSON503 *Unavailable } // Status returns HTTPResponse.Status func (r ArtifactResponse) Status() string { if r.HTTPResponse != nil { return r.HTTPResponse.Status } return http.StatusText(0) } // StatusCode returns HTTPResponse.StatusCode func (r ArtifactResponse) StatusCode() int { if r.HTTPResponse != nil { return r.HTTPResponse.StatusCode } return 0 } type GetFileResponse struct { Body []byte HTTPResponse *http.Response JSON400 *BadRequest JSON401 *KeyNotEnabled JSON403 *Error JSON500 *InternalServerError JSON503 *Unavailable } // Status returns HTTPResponse.Status func (r GetFileResponse) Status() string { if r.HTTPResponse != nil { return r.HTTPResponse.Status } return http.StatusText(0) } // StatusCode returns HTTPResponse.StatusCode func (r GetFileResponse) StatusCode() int { if r.HTTPResponse != nil { return r.HTTPResponse.StatusCode } return 0 } type UploadBeginResponse struct { Body []byte HTTPResponse *http.Response JSON200 *UploadBeginAPIResponse JSON400 *BadRequest JSON401 *KeyNotEnabled JSON403 *Forbidden JSON408 *Deadline JSON500 *InternalServerError JSON503 *Unavailable } // Status returns HTTPResponse.Status func (r UploadBeginResponse) Status() string { if r.HTTPResponse != nil { return r.HTTPResponse.Status } return http.StatusText(0) } // StatusCode returns HTTPResponse.StatusCode func (r UploadBeginResponse) StatusCode() int { if r.HTTPResponse != nil { return r.HTTPResponse.StatusCode } return 0 } type UploadCompleteResponse struct { Body []byte HTTPResponse *http.Response JSON200 *struct { Status *string `json:"status,omitempty"` } JSON400 *BadRequest JSON401 *KeyNotEnabled JSON403 *Forbidden JSON408 *Deadline JSON500 *InternalServerError JSON503 *Unavailable } // Status returns HTTPResponse.Status func (r UploadCompleteResponse) Status() string { if r.HTTPResponse != nil { return r.HTTPResponse.Status } return http.StatusText(0) } // StatusCode returns HTTPResponse.StatusCode func (r UploadCompleteResponse) StatusCode() int { if r.HTTPResponse != nil { return r.HTTPResponse.StatusCode } return 0 } type UploadChunkResponse struct { Body []byte HTTPResponse *http.Response JSON400 *BadRequest JSON401 *KeyNotEnabled JSON403 *Forbidden JSON408 *Deadline JSON500 *InternalServerError JSON503 *Unavailable } // Status returns HTTPResponse.Status func (r UploadChunkResponse) Status() string { if r.HTTPResponse != nil { return r.HTTPResponse.Status } return http.StatusText(0) } // StatusCode returns HTTPResponse.StatusCode func (r UploadChunkResponse) StatusCode() int { if r.HTTPResponse != nil { return r.HTTPResponse.StatusCode } return 0 } type StatusResponse struct { Body []byte HTTPResponse *http.Response JSON200 *StatusAPIResponse JSON400 *BadRequest JSON503 *StatusAPIResponse } // Status returns HTTPResponse.Status func (r StatusResponse) Status() string { if r.HTTPResponse != nil { return r.HTTPResponse.Status } return http.StatusText(0) } // StatusCode returns HTTPResponse.StatusCode func (r StatusResponse) StatusCode() int { if r.HTTPResponse != nil { return r.HTTPResponse.StatusCode } return 0 } // GetPGPKeyWithResponse request returning *GetPGPKeyResponse func (c *ClientWithResponses) GetPGPKeyWithResponse(ctx context.Context, major int, minor int, patch int, params *GetPGPKeyParams, reqEditors ...RequestEditorFn) (*GetPGPKeyResponse, error) { rsp, err := c.GetPGPKey(ctx, major, minor, patch, params, reqEditors...) if err != nil { return nil, err } return ParseGetPGPKeyResponse(rsp) } // AgentEnrollWithBodyWithResponse request with arbitrary body returning *AgentEnrollResponse func (c *ClientWithResponses) AgentEnrollWithBodyWithResponse(ctx context.Context, params *AgentEnrollParams, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*AgentEnrollResponse, error) { rsp, err := c.AgentEnrollWithBody(ctx, params, contentType, body, reqEditors...) if err != nil { return nil, err } return ParseAgentEnrollResponse(rsp) } func (c *ClientWithResponses) AgentEnrollWithResponse(ctx context.Context, params *AgentEnrollParams, body AgentEnrollJSONRequestBody, reqEditors ...RequestEditorFn) (*AgentEnrollResponse, error) { rsp, err := c.AgentEnroll(ctx, params, body, reqEditors...) if err != nil { return nil, err } return ParseAgentEnrollResponse(rsp) } // AgentAcksWithBodyWithResponse request with arbitrary body returning *AgentAcksResponse func (c *ClientWithResponses) AgentAcksWithBodyWithResponse(ctx context.Context, id string, params *AgentAcksParams, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*AgentAcksResponse, error) { rsp, err := c.AgentAcksWithBody(ctx, id, params, contentType, body, reqEditors...) if err != nil { return nil, err } return ParseAgentAcksResponse(rsp) } func (c *ClientWithResponses) AgentAcksWithResponse(ctx context.Context, id string, params *AgentAcksParams, body AgentAcksJSONRequestBody, reqEditors ...RequestEditorFn) (*AgentAcksResponse, error) { rsp, err := c.AgentAcks(ctx, id, params, body, reqEditors...) if err != nil { return nil, err } return ParseAgentAcksResponse(rsp) } // AuditUnenrollWithBodyWithResponse request with arbitrary body returning *AuditUnenrollResponse func (c *ClientWithResponses) AuditUnenrollWithBodyWithResponse(ctx context.Context, id string, params *AuditUnenrollParams, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*AuditUnenrollResponse, error) { rsp, err := c.AuditUnenrollWithBody(ctx, id, params, contentType, body, reqEditors...) if err != nil { return nil, err } return ParseAuditUnenrollResponse(rsp) } func (c *ClientWithResponses) AuditUnenrollWithResponse(ctx context.Context, id string, params *AuditUnenrollParams, body AuditUnenrollJSONRequestBody, reqEditors ...RequestEditorFn) (*AuditUnenrollResponse, error) { rsp, err := c.AuditUnenroll(ctx, id, params, body, reqEditors...) if err != nil { return nil, err } return ParseAuditUnenrollResponse(rsp) } // AgentCheckinWithBodyWithResponse request with arbitrary body returning *AgentCheckinResponse func (c *ClientWithResponses) AgentCheckinWithBodyWithResponse(ctx context.Context, id string, params *AgentCheckinParams, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*AgentCheckinResponse, error) { rsp, err := c.AgentCheckinWithBody(ctx, id, params, contentType, body, reqEditors...) if err != nil { return nil, err } return ParseAgentCheckinResponse(rsp) } func (c *ClientWithResponses) AgentCheckinWithResponse(ctx context.Context, id string, params *AgentCheckinParams, body AgentCheckinJSONRequestBody, reqEditors ...RequestEditorFn) (*AgentCheckinResponse, error) { rsp, err := c.AgentCheckin(ctx, id, params, body, reqEditors...) if err != nil { return nil, err } return ParseAgentCheckinResponse(rsp) } // ArtifactWithResponse request returning *ArtifactResponse func (c *ClientWithResponses) ArtifactWithResponse(ctx context.Context, id string, sha2 string, params *ArtifactParams, reqEditors ...RequestEditorFn) (*ArtifactResponse, error) { rsp, err := c.Artifact(ctx, id, sha2, params, reqEditors...) if err != nil { return nil, err } return ParseArtifactResponse(rsp) } // GetFileWithResponse request returning *GetFileResponse func (c *ClientWithResponses) GetFileWithResponse(ctx context.Context, id string, params *GetFileParams, reqEditors ...RequestEditorFn) (*GetFileResponse, error) { rsp, err := c.GetFile(ctx, id, params, reqEditors...) if err != nil { return nil, err } return ParseGetFileResponse(rsp) } // UploadBeginWithBodyWithResponse request with arbitrary body returning *UploadBeginResponse func (c *ClientWithResponses) UploadBeginWithBodyWithResponse(ctx context.Context, params *UploadBeginParams, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*UploadBeginResponse, error) { rsp, err := c.UploadBeginWithBody(ctx, params, contentType, body, reqEditors...) if err != nil { return nil, err } return ParseUploadBeginResponse(rsp) } func (c *ClientWithResponses) UploadBeginWithResponse(ctx context.Context, params *UploadBeginParams, body UploadBeginJSONRequestBody, reqEditors ...RequestEditorFn) (*UploadBeginResponse, error) { rsp, err := c.UploadBegin(ctx, params, body, reqEditors...) if err != nil { return nil, err } return ParseUploadBeginResponse(rsp) } // UploadCompleteWithBodyWithResponse request with arbitrary body returning *UploadCompleteResponse func (c *ClientWithResponses) UploadCompleteWithBodyWithResponse(ctx context.Context, id string, params *UploadCompleteParams, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*UploadCompleteResponse, error) { rsp, err := c.UploadCompleteWithBody(ctx, id, params, contentType, body, reqEditors...) if err != nil { return nil, err } return ParseUploadCompleteResponse(rsp) } func (c *ClientWithResponses) UploadCompleteWithResponse(ctx context.Context, id string, params *UploadCompleteParams, body UploadCompleteJSONRequestBody, reqEditors ...RequestEditorFn) (*UploadCompleteResponse, error) { rsp, err := c.UploadComplete(ctx, id, params, body, reqEditors...) if err != nil { return nil, err } return ParseUploadCompleteResponse(rsp) } // UploadChunkWithBodyWithResponse request with arbitrary body returning *UploadChunkResponse func (c *ClientWithResponses) UploadChunkWithBodyWithResponse(ctx context.Context, id string, chunkNum int, params *UploadChunkParams, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*UploadChunkResponse, error) { rsp, err := c.UploadChunkWithBody(ctx, id, chunkNum, params, contentType, body, reqEditors...) if err != nil { return nil, err } return ParseUploadChunkResponse(rsp) } // StatusWithResponse request returning *StatusResponse func (c *ClientWithResponses) StatusWithResponse(ctx context.Context, params *StatusParams, reqEditors ...RequestEditorFn) (*StatusResponse, error) { rsp, err := c.Status(ctx, params, reqEditors...) if err != nil { return nil, err } return ParseStatusResponse(rsp) } // ParseGetPGPKeyResponse parses an HTTP response from a GetPGPKeyWithResponse call func ParseGetPGPKeyResponse(rsp *http.Response) (*GetPGPKeyResponse, error) { bodyBytes, err := io.ReadAll(rsp.Body) defer func() { _ = rsp.Body.Close() }() if err != nil { return nil, err } response := &GetPGPKeyResponse{ 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 } return response, nil } // ParseAgentEnrollResponse parses an HTTP response from a AgentEnrollWithResponse call func ParseAgentEnrollResponse(rsp *http.Response) (*AgentEnrollResponse, error) { bodyBytes, err := io.ReadAll(rsp.Body) defer func() { _ = rsp.Body.Close() }() if err != nil { return nil, err } response := &AgentEnrollResponse{ Body: bodyBytes, HTTPResponse: rsp, } switch { case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: var dest EnrollResponse 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 KeyNotEnabled 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 == 408: var dest Deadline if err := json.Unmarshal(bodyBytes, &dest); err != nil { return nil, err } response.JSON408 = &dest case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: var dest InternalServerError if err := json.Unmarshal(bodyBytes, &dest); err != nil { return nil, err } response.JSON500 = &dest case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 503: var dest Unavailable if err := json.Unmarshal(bodyBytes, &dest); err != nil { return nil, err } response.JSON503 = &dest } return response, nil } // ParseAgentAcksResponse parses an HTTP response from a AgentAcksWithResponse call func ParseAgentAcksResponse(rsp *http.Response) (*AgentAcksResponse, error) { bodyBytes, err := io.ReadAll(rsp.Body) defer func() { _ = rsp.Body.Close() }() if err != nil { return nil, err } response := &AgentAcksResponse{ Body: bodyBytes, HTTPResponse: rsp, } switch { case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: var dest AckResponse 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 KeyNotEnabled 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 AgentNotFound 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 == 408: var dest Deadline if err := json.Unmarshal(bodyBytes, &dest); err != nil { return nil, err } response.JSON408 = &dest case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: var dest InternalServerError if err := json.Unmarshal(bodyBytes, &dest); err != nil { return nil, err } response.JSON500 = &dest case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 503: var dest Unavailable if err := json.Unmarshal(bodyBytes, &dest); err != nil { return nil, err } response.JSON503 = &dest } return response, nil } // ParseAuditUnenrollResponse parses an HTTP response from a AuditUnenrollWithResponse call func ParseAuditUnenrollResponse(rsp *http.Response) (*AuditUnenrollResponse, error) { bodyBytes, err := io.ReadAll(rsp.Body) defer func() { _ = rsp.Body.Close() }() if err != nil { return nil, err } response := &AuditUnenrollResponse{ 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 KeyNotEnabled 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 == 409: var dest Conflict if err := json.Unmarshal(bodyBytes, &dest); err != nil { return nil, err } response.JSON409 = &dest case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: var dest InternalServerError if err := json.Unmarshal(bodyBytes, &dest); err != nil { return nil, err } response.JSON500 = &dest case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 503: var dest Unavailable if err := json.Unmarshal(bodyBytes, &dest); err != nil { return nil, err } response.JSON503 = &dest } return response, nil } // ParseAgentCheckinResponse parses an HTTP response from a AgentCheckinWithResponse call func ParseAgentCheckinResponse(rsp *http.Response) (*AgentCheckinResponse, error) { bodyBytes, err := io.ReadAll(rsp.Body) defer func() { _ = rsp.Body.Close() }() if err != nil { return nil, err } response := &AgentCheckinResponse{ Body: bodyBytes, HTTPResponse: rsp, } switch { case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: var dest CheckinResponse 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 KeyNotEnabled 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 AgentNotFound 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 == 408: var dest Deadline if err := json.Unmarshal(bodyBytes, &dest); err != nil { return nil, err } response.JSON408 = &dest case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: var dest InternalServerError if err := json.Unmarshal(bodyBytes, &dest); err != nil { return nil, err } response.JSON500 = &dest case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 503: var dest Unavailable if err := json.Unmarshal(bodyBytes, &dest); err != nil { return nil, err } response.JSON503 = &dest } return response, nil } // ParseArtifactResponse parses an HTTP response from a ArtifactWithResponse call func ParseArtifactResponse(rsp *http.Response) (*ArtifactResponse, error) { bodyBytes, err := io.ReadAll(rsp.Body) defer func() { _ = rsp.Body.Close() }() if err != nil { return nil, err } response := &ArtifactResponse{ 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 KeyNotEnabled 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 == 404: var dest AgentNotFound 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 == 408: var dest Deadline if err := json.Unmarshal(bodyBytes, &dest); err != nil { return nil, err } response.JSON408 = &dest case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 428: var dest Throttle if err := json.Unmarshal(bodyBytes, &dest); err != nil { return nil, err } response.JSON428 = &dest case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: var dest InternalServerError if err := json.Unmarshal(bodyBytes, &dest); err != nil { return nil, err } response.JSON500 = &dest case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 503: var dest Unavailable if err := json.Unmarshal(bodyBytes, &dest); err != nil { return nil, err } response.JSON503 = &dest } return response, nil } // ParseGetFileResponse parses an HTTP response from a GetFileWithResponse call func ParseGetFileResponse(rsp *http.Response) (*GetFileResponse, error) { bodyBytes, err := io.ReadAll(rsp.Body) defer func() { _ = rsp.Body.Close() }() if err != nil { return nil, err } response := &GetFileResponse{ 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 KeyNotEnabled 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 Error 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 == 500: var dest InternalServerError if err := json.Unmarshal(bodyBytes, &dest); err != nil { return nil, err } response.JSON500 = &dest case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 503: var dest Unavailable if err := json.Unmarshal(bodyBytes, &dest); err != nil { return nil, err } response.JSON503 = &dest } return response, nil } // ParseUploadBeginResponse parses an HTTP response from a UploadBeginWithResponse call func ParseUploadBeginResponse(rsp *http.Response) (*UploadBeginResponse, error) { bodyBytes, err := io.ReadAll(rsp.Body) defer func() { _ = rsp.Body.Close() }() if err != nil { return nil, err } response := &UploadBeginResponse{ Body: bodyBytes, HTTPResponse: rsp, } switch { case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: var dest UploadBeginAPIResponse 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 KeyNotEnabled 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 == 408: var dest Deadline if err := json.Unmarshal(bodyBytes, &dest); err != nil { return nil, err } response.JSON408 = &dest case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: var dest InternalServerError if err := json.Unmarshal(bodyBytes, &dest); err != nil { return nil, err } response.JSON500 = &dest case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 503: var dest Unavailable if err := json.Unmarshal(bodyBytes, &dest); err != nil { return nil, err } response.JSON503 = &dest } return response, nil } // ParseUploadCompleteResponse parses an HTTP response from a UploadCompleteWithResponse call func ParseUploadCompleteResponse(rsp *http.Response) (*UploadCompleteResponse, error) { bodyBytes, err := io.ReadAll(rsp.Body) defer func() { _ = rsp.Body.Close() }() if err != nil { return nil, err } response := &UploadCompleteResponse{ Body: bodyBytes, HTTPResponse: rsp, } switch { case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: var dest struct { Status *string `json:"status,omitempty"` } 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 KeyNotEnabled 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 == 408: var dest Deadline if err := json.Unmarshal(bodyBytes, &dest); err != nil { return nil, err } response.JSON408 = &dest case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: var dest InternalServerError if err := json.Unmarshal(bodyBytes, &dest); err != nil { return nil, err } response.JSON500 = &dest case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 503: var dest Unavailable if err := json.Unmarshal(bodyBytes, &dest); err != nil { return nil, err } response.JSON503 = &dest } return response, nil } // ParseUploadChunkResponse parses an HTTP response from a UploadChunkWithResponse call func ParseUploadChunkResponse(rsp *http.Response) (*UploadChunkResponse, error) { bodyBytes, err := io.ReadAll(rsp.Body) defer func() { _ = rsp.Body.Close() }() if err != nil { return nil, err } response := &UploadChunkResponse{ 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 KeyNotEnabled 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 == 408: var dest Deadline if err := json.Unmarshal(bodyBytes, &dest); err != nil { return nil, err } response.JSON408 = &dest case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: var dest InternalServerError if err := json.Unmarshal(bodyBytes, &dest); err != nil { return nil, err } response.JSON500 = &dest case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 503: var dest Unavailable if err := json.Unmarshal(bodyBytes, &dest); err != nil { return nil, err } response.JSON503 = &dest } return response, nil } // ParseStatusResponse parses an HTTP response from a StatusWithResponse call func ParseStatusResponse(rsp *http.Response) (*StatusResponse, error) { bodyBytes, err := io.ReadAll(rsp.Body) defer func() { _ = rsp.Body.Close() }() if err != nil { return nil, err } response := &StatusResponse{ Body: bodyBytes, HTTPResponse: rsp, } switch { case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: var dest StatusAPIResponse 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 == 503: var dest StatusAPIResponse if err := json.Unmarshal(bodyBytes, &dest); err != nil { return nil, err } response.JSON503 = &dest case rsp.StatusCode == 503: // Content-type (text/plain) unsupported } return response, nil }