Merged in feature/apitidyup (pull request #24)

Export API Clean Up

* exportapi
This commit is contained in:
Michael McGuinness
2025-01-16 13:49:07 +00:00
parent 174644b63c
commit f5d2808c7a
7 changed files with 421 additions and 40 deletions
+174 -4
View File
@@ -16,21 +16,82 @@ import (
"github.com/oapi-codegen/runtime"
)
// Defines values for ExportStatus.
const (
Completed ExportStatus = "completed"
Failed ExportStatus = "failed"
InProgress ExportStatus = "in_progress"
)
// Defines values for FieldFilterCondition.
const (
ClosedInterval FieldFilterCondition = "closed_interval"
Exclude FieldFilterCondition = "exclude"
GreaterThan FieldFilterCondition = "greater_than"
Include FieldFilterCondition = "include"
LeftClosedInterval FieldFilterCondition = "left_closed_interval"
LessThan FieldFilterCondition = "less_than"
OpenInterval FieldFilterCondition = "open_interval"
RightClosedInterval FieldFilterCondition = "right_closed_interval"
)
// Defines values for QueryType.
const (
CONTEXTFULL QueryType = "CONTEXT_FULL"
JSONEXTRACTOR QueryType = "JSON_EXTRACTOR"
)
// ExportDetails Payload for export trigger response.
type ExportDetails struct {
// JobId The job id relative to the export.
JobId *string `json:"job_id,omitempty"`
// OutputLocation The location in which the export zip file will be found.
OutputLocation *string `json:"output_location,omitempty"`
// Status The possible export job states.
Status ExportStatus `json:"status"`
}
// ExportStatus The possible export job states.
type ExportStatus string
// ExportTrigger Payload for triggering an export.
type ExportTrigger struct {
// ExampleProperty Example property for ExportTrigger.
ExampleProperty *string `json:"example_property,omitempty"`
// FieldFilters Filter the scope based on field output values.
FieldFilters *[]FieldFilter `json:"field_filters,omitempty"`
// IngestionFilters Filter the scope based on ingestion parameters.
IngestionFilters *struct {
// EndDate The last date of ingestion.
EndDate *string `json:"end_date,omitempty"`
// StartDate This first date of ingestion.
StartDate *string `json:"start_date,omitempty"`
} `json:"ingestion_filters,omitempty"`
// JobId The job id of the query results to be exported.
JobId string `json:"job_id"`
}
// FieldFilter Filtering a column
type FieldFilter struct {
// Condition The possible field filtering conditions.
Condition FieldFilterCondition `json:"condition"`
// FieldName The name of the field in question.
FieldName string `json:"field_name"`
// Values The values useful to the filter.
Values []string `json:"values"`
}
// FieldFilterCondition The possible field filtering conditions.
type FieldFilterCondition string
// IdMessage defines model for IdMessage.
type IdMessage struct {
// Id Unique identifier.
// Id Unique identifier for entity.
Id string `json:"id"`
}
@@ -217,6 +278,9 @@ type ClientInterface interface {
TriggerExport(ctx context.Context, body TriggerExportJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)
// ExportState request
ExportState(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*http.Response, error)
// CreateJobCollectorWithBody request with any body
CreateJobCollectorWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)
@@ -279,6 +343,18 @@ func (c *Client) TriggerExport(ctx context.Context, body TriggerExportJSONReques
return c.Client.Do(req)
}
func (c *Client) ExportState(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*http.Response, error) {
req, err := NewExportStateRequest(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) CreateJobCollectorWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) {
req, err := NewCreateJobCollectorRequestWithBody(c.Server, contentType, body)
if err != nil {
@@ -467,7 +543,7 @@ func NewTriggerExportRequestWithBody(server string, contentType string, body io.
return nil, err
}
operationPath := fmt.Sprintf("/exports/trigger")
operationPath := fmt.Sprintf("/export")
if operationPath[0] == '/' {
operationPath = "." + operationPath
}
@@ -487,6 +563,40 @@ func NewTriggerExportRequestWithBody(server string, contentType string, body io.
return req, nil
}
// NewExportStateRequest generates requests for ExportState
func NewExportStateRequest(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("/export/%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
}
// NewCreateJobCollectorRequest calls the generic CreateJobCollector builder with application/json body
func NewCreateJobCollectorRequest(server string, body CreateJobCollectorJSONRequestBody) (*http.Request, error) {
var bodyReader io.Reader
@@ -885,6 +995,9 @@ type ClientWithResponsesInterface interface {
TriggerExportWithResponse(ctx context.Context, body TriggerExportJSONRequestBody, reqEditors ...RequestEditorFn) (*TriggerExportResponse, error)
// ExportStateWithResponse request
ExportStateWithResponse(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*ExportStateResponse, error)
// CreateJobCollectorWithBodyWithResponse request with any body
CreateJobCollectorWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*CreateJobCollectorResponse, error)
@@ -945,6 +1058,28 @@ func (r TriggerExportResponse) StatusCode() int {
return 0
}
type ExportStateResponse struct {
Body []byte
HTTPResponse *http.Response
JSON200 *ExportDetails
}
// Status returns HTTPResponse.Status
func (r ExportStateResponse) Status() string {
if r.HTTPResponse != nil {
return r.HTTPResponse.Status
}
return http.StatusText(0)
}
// StatusCode returns HTTPResponse.StatusCode
func (r ExportStateResponse) StatusCode() int {
if r.HTTPResponse != nil {
return r.HTTPResponse.StatusCode
}
return 0
}
type CreateJobCollectorResponse struct {
Body []byte
HTTPResponse *http.Response
@@ -1157,6 +1292,15 @@ func (c *ClientWithResponses) TriggerExportWithResponse(ctx context.Context, bod
return ParseTriggerExportResponse(rsp)
}
// ExportStateWithResponse request returning *ExportStateResponse
func (c *ClientWithResponses) ExportStateWithResponse(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*ExportStateResponse, error) {
rsp, err := c.ExportState(ctx, id, reqEditors...)
if err != nil {
return nil, err
}
return ParseExportStateResponse(rsp)
}
// CreateJobCollectorWithBodyWithResponse request with arbitrary body returning *CreateJobCollectorResponse
func (c *ClientWithResponses) CreateJobCollectorWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*CreateJobCollectorResponse, error) {
rsp, err := c.CreateJobCollectorWithBody(ctx, contentType, body, reqEditors...)
@@ -1304,6 +1448,32 @@ func ParseTriggerExportResponse(rsp *http.Response) (*TriggerExportResponse, err
return response, nil
}
// ParseExportStateResponse parses an HTTP response from a ExportStateWithResponse call
func ParseExportStateResponse(rsp *http.Response) (*ExportStateResponse, error) {
bodyBytes, err := io.ReadAll(rsp.Body)
defer func() { _ = rsp.Body.Close() }()
if err != nil {
return nil, err
}
response := &ExportStateResponse{
Body: bodyBytes,
HTTPResponse: rsp,
}
switch {
case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200:
var dest ExportDetails
if err := json.Unmarshal(bodyBytes, &dest); err != nil {
return nil, err
}
response.JSON200 = &dest
}
return response, nil
}
// ParseCreateJobCollectorResponse parses an HTTP response from a CreateJobCollectorWithResponse call
func ParseCreateJobCollectorResponse(rsp *http.Response) (*CreateJobCollectorResponse, error) {
bodyBytes, err := io.ReadAll(rsp.Body)