955 lines
34 KiB
Go
955 lines
34 KiB
Go
// Package queryapi provides primitives to interact with the openapi HTTP API.
|
|
//
|
|
// Code generated by github.com/oapi-codegen/oapi-codegen/v2 version 2.4.1 DO NOT EDIT.
|
|
package queryapi
|
|
|
|
import (
|
|
"bytes"
|
|
"compress/gzip"
|
|
"encoding/base64"
|
|
"fmt"
|
|
"net/http"
|
|
"net/url"
|
|
"path"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/getkin/kin-openapi/openapi3"
|
|
"github.com/labstack/echo/v4"
|
|
"github.com/oapi-codegen/runtime"
|
|
openapi_types "github.com/oapi-codegen/runtime/types"
|
|
)
|
|
|
|
const (
|
|
CognitoAuthScopes = "cognitoAuth.Scopes"
|
|
PlaceholderAuthScopes = "placeholderAuth.Scopes"
|
|
)
|
|
|
|
// Defines values for ClientStatus.
|
|
const (
|
|
INSYNC ClientStatus = "IN_SYNC"
|
|
NOTSYNCED ClientStatus = "NOT_SYNCED"
|
|
NOTSYNCING ClientStatus = "NOT_SYNCING"
|
|
)
|
|
|
|
// 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"
|
|
)
|
|
|
|
// ClientCanSync If the client is allowing active syncs
|
|
type ClientCanSync = bool
|
|
|
|
// ClientCreate The properties for creation.
|
|
type ClientCreate struct {
|
|
// Id The client external id
|
|
Id ClientID `json:"id"`
|
|
|
|
// Name The client name
|
|
Name ClientName `json:"name"`
|
|
}
|
|
|
|
// ClientID The client external id
|
|
type ClientID = string
|
|
|
|
// ClientIDBody The client id.
|
|
type ClientIDBody struct {
|
|
// Id The client external id
|
|
Id ClientID `json:"id"`
|
|
}
|
|
|
|
// ClientName The client name
|
|
type ClientName = string
|
|
|
|
// ClientStatus Specifies the status of a client.
|
|
type ClientStatus string
|
|
|
|
// ClientStatusBody A client status information object.
|
|
type ClientStatusBody struct {
|
|
// Status Specifies the status of a client.
|
|
Status ClientStatus `json:"status"`
|
|
}
|
|
|
|
// ClientUpdate The properties that may be updated.
|
|
type ClientUpdate struct {
|
|
// CanSync If the client is allowing active syncs
|
|
CanSync *ClientCanSync `json:"can_sync,omitempty"`
|
|
|
|
// Name The client name
|
|
Name *ClientName `json:"name,omitempty"`
|
|
}
|
|
|
|
// CodeVersion The desired code version.
|
|
type CodeVersion = int64
|
|
|
|
// Collector Collector model.
|
|
type Collector struct {
|
|
// ActiveVersion The desired version.
|
|
ActiveVersion Version `json:"active_version"`
|
|
|
|
// ClientId The client external id
|
|
ClientId ClientID `json:"client_id"`
|
|
|
|
// Fields The fields in the collector.
|
|
Fields CollectorFields `json:"fields"`
|
|
|
|
// LatestVersion The desired version.
|
|
LatestVersion Version `json:"latest_version"`
|
|
|
|
// MinimumCleanerVersion The desired code version.
|
|
MinimumCleanerVersion CodeVersion `json:"minimum_cleaner_version"`
|
|
|
|
// MinimumTextVersion The desired code version.
|
|
MinimumTextVersion CodeVersion `json:"minimum_text_version"`
|
|
}
|
|
|
|
// CollectorField The field properties for the collector.
|
|
type CollectorField struct {
|
|
// Name The output field name.
|
|
Name CollectorFieldName `json:"name"`
|
|
|
|
// QueryId The query id.
|
|
QueryId QueryID `json:"query_id"`
|
|
}
|
|
|
|
// CollectorFieldName The output field name.
|
|
type CollectorFieldName = string
|
|
|
|
// CollectorFields The fields in the collector.
|
|
type CollectorFields = []CollectorField
|
|
|
|
// CollectorSet Payload for updating a Collector.
|
|
type CollectorSet struct {
|
|
// ActiveVersion The desired version.
|
|
ActiveVersion *Version `json:"active_version,omitempty"`
|
|
|
|
// Fields The fields in the collector.
|
|
Fields *CollectorFields `json:"fields,omitempty"`
|
|
|
|
// MinimumCleanerVersion The desired code version.
|
|
MinimumCleanerVersion *CodeVersion `json:"minimum_cleaner_version,omitempty"`
|
|
|
|
// MinimumTextVersion The desired code version.
|
|
MinimumTextVersion *CodeVersion `json:"minimum_text_version,omitempty"`
|
|
}
|
|
|
|
// DocClient The properties of a client.
|
|
type DocClient struct {
|
|
// CanSync If the client is allowing active syncs
|
|
CanSync ClientCanSync `json:"can_sync"`
|
|
|
|
// Id The client external id
|
|
Id ClientID `json:"id"`
|
|
|
|
// Name The client name
|
|
Name ClientName `json:"name"`
|
|
}
|
|
|
|
// Document The document properties.
|
|
type Document struct {
|
|
// ClientId The client external id
|
|
ClientId ClientID `json:"client_id"`
|
|
|
|
// Fields The fields and the value for the document
|
|
Fields map[string]interface{} `json:"fields"`
|
|
|
|
// Hash The document hash
|
|
Hash Hash `json:"hash"`
|
|
|
|
// Id The document id.
|
|
Id DocumentID `json:"id"`
|
|
}
|
|
|
|
// DocumentID The document id.
|
|
type DocumentID = openapi_types.UUID
|
|
|
|
// DocumentSummary The document summary properties.
|
|
type DocumentSummary struct {
|
|
// Hash The document hash
|
|
Hash Hash `json:"hash"`
|
|
|
|
// Id The document id.
|
|
Id DocumentID `json:"id"`
|
|
}
|
|
|
|
// ErrorMessage Description of error
|
|
type ErrorMessage struct {
|
|
// Message Message describing the cause.
|
|
Message string `json:"message"`
|
|
}
|
|
|
|
// ExportDetails Payload for export trigger response.
|
|
type ExportDetails struct {
|
|
// ClientId The client external id
|
|
ClientId ClientID `json:"client_id"`
|
|
|
|
// OutputLocation The location in which the export zip file will be found.
|
|
OutputLocation *string `json:"output_location,omitempty"`
|
|
|
|
// Status The possible export states.
|
|
Status ExportStatus `json:"status"`
|
|
}
|
|
|
|
// ExportID The export id.
|
|
type ExportID = openapi_types.UUID
|
|
|
|
// ExportStatus The possible export states.
|
|
type ExportStatus string
|
|
|
|
// ExportTrigger Payload for triggering an export.
|
|
type ExportTrigger struct {
|
|
// 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 *time.Time `json:"end_date,omitempty"`
|
|
|
|
// StartDate This first date of ingestion.
|
|
StartDate *time.Time `json:"start_date,omitempty"`
|
|
} `json:"ingestion_filters,omitempty"`
|
|
}
|
|
|
|
// FieldFilter Filtering a column
|
|
type FieldFilter struct {
|
|
// Condition The possible field filtering conditions.
|
|
Condition FieldFilterCondition `json:"condition"`
|
|
|
|
// FieldName The output field name.
|
|
FieldName CollectorFieldName `json:"field_name"`
|
|
|
|
// Values The values useful to the filter.
|
|
Values []string `json:"values"`
|
|
}
|
|
|
|
// FieldFilterCondition The possible field filtering conditions.
|
|
type FieldFilterCondition string
|
|
|
|
// Hash The document hash
|
|
type Hash = string
|
|
|
|
// IdMessage A single uuid.
|
|
type IdMessage struct {
|
|
// Id Unique identifier for entity.
|
|
Id openapi_types.UUID `json:"id"`
|
|
}
|
|
|
|
// ListDocuments The documents in the client.
|
|
type ListDocuments = []DocumentSummary
|
|
|
|
// ListQueries A set of queries.
|
|
type ListQueries struct {
|
|
// Queries List of queries.
|
|
Queries []Query `json:"queries"`
|
|
}
|
|
|
|
// Query A logic unit of execution.
|
|
type Query struct {
|
|
// ActiveVersion The desired version.
|
|
ActiveVersion Version `json:"active_version"`
|
|
|
|
// Config Configuration for the query.
|
|
Config *QueryConfig `json:"config,omitempty"`
|
|
|
|
// Id The query id.
|
|
Id QueryID `json:"id"`
|
|
|
|
// LatestVersion The desired version.
|
|
LatestVersion Version `json:"latest_version"`
|
|
|
|
// RequiredQueries List of required query IDs.
|
|
RequiredQueries *RequiredQueryIDs `json:"required_queries,omitempty"`
|
|
|
|
// Type Specifies the type of the query.
|
|
Type QueryType `json:"type"`
|
|
}
|
|
|
|
// QueryConfig Configuration for the query.
|
|
type QueryConfig = string
|
|
|
|
// QueryCreate The parameters required to create a query.
|
|
type QueryCreate struct {
|
|
// Config Configuration for the query.
|
|
Config *QueryConfig `json:"config,omitempty"`
|
|
|
|
// RequiredQueries List of required query IDs.
|
|
RequiredQueries *RequiredQueryIDs `json:"required_queries,omitempty"`
|
|
|
|
// Type Specifies the type of the query.
|
|
Type QueryType `json:"type"`
|
|
}
|
|
|
|
// QueryID The query id.
|
|
type QueryID = openapi_types.UUID
|
|
|
|
// QueryTestRequest The properties for a query test request.
|
|
type QueryTestRequest struct {
|
|
// DocumentId The document id.
|
|
DocumentId DocumentID `json:"document_id"`
|
|
|
|
// QueryVersion The desired version.
|
|
QueryVersion Version `json:"query_version"`
|
|
}
|
|
|
|
// QueryTestResponse The response from a query test.
|
|
type QueryTestResponse struct {
|
|
// Value Result of the query test.
|
|
Value string `json:"value"`
|
|
}
|
|
|
|
// QueryType Specifies the type of the query.
|
|
type QueryType string
|
|
|
|
// QueryUpdate The properties that may be updated for a query.
|
|
type QueryUpdate struct {
|
|
// ActiveVersion The desired version.
|
|
ActiveVersion *Version `json:"active_version,omitempty"`
|
|
|
|
// Config Configuration for the query.
|
|
Config *QueryConfig `json:"config,omitempty"`
|
|
|
|
// RequiredQueries List of required query IDs.
|
|
RequiredQueries *RequiredQueryIDs `json:"required_queries,omitempty"`
|
|
}
|
|
|
|
// RequiredQueryIDs List of required query IDs.
|
|
type RequiredQueryIDs = []QueryID
|
|
|
|
// Version The desired version.
|
|
type Version = int32
|
|
|
|
// InternalError Description of error
|
|
type InternalError = ErrorMessage
|
|
|
|
// InvalidRequest Description of error
|
|
type InvalidRequest = ErrorMessage
|
|
|
|
// TooManyRequests Description of error
|
|
type TooManyRequests = ErrorMessage
|
|
|
|
// Unauthorized Description of error
|
|
type Unauthorized = ErrorMessage
|
|
|
|
// LoginCallbackParams defines parameters for LoginCallback.
|
|
type LoginCallbackParams struct {
|
|
// Code Authorization code from Cognito
|
|
Code string `form:"code" json:"code"`
|
|
|
|
// State State parameter for CSRF protection
|
|
State string `form:"state" json:"state"`
|
|
}
|
|
|
|
// CreateClientJSONRequestBody defines body for CreateClient for application/json ContentType.
|
|
type CreateClientJSONRequestBody = ClientCreate
|
|
|
|
// UpdateClientJSONRequestBody defines body for UpdateClient for application/json ContentType.
|
|
type UpdateClientJSONRequestBody = ClientUpdate
|
|
|
|
// SetCollectorByClientIdJSONRequestBody defines body for SetCollectorByClientId for application/json ContentType.
|
|
type SetCollectorByClientIdJSONRequestBody = CollectorSet
|
|
|
|
// TriggerExportJSONRequestBody defines body for TriggerExport for application/json ContentType.
|
|
type TriggerExportJSONRequestBody = ExportTrigger
|
|
|
|
// CreateQueryJSONRequestBody defines body for CreateQuery for application/json ContentType.
|
|
type CreateQueryJSONRequestBody = QueryCreate
|
|
|
|
// UpdateQueryJSONRequestBody defines body for UpdateQuery for application/json ContentType.
|
|
type UpdateQueryJSONRequestBody = QueryUpdate
|
|
|
|
// TestQueryJSONRequestBody defines body for TestQuery for application/json ContentType.
|
|
type TestQueryJSONRequestBody = QueryTestRequest
|
|
|
|
// ServerInterface represents all server handlers.
|
|
type ServerInterface interface {
|
|
// Create a new client
|
|
// (POST /client)
|
|
CreateClient(ctx echo.Context) error
|
|
// Get a client by ID
|
|
// (GET /client/{id})
|
|
GetClient(ctx echo.Context, id ClientID) error
|
|
// Update a client
|
|
// (PATCH /client/{id})
|
|
UpdateClient(ctx echo.Context, id ClientID) error
|
|
// Get a collector by client ID
|
|
// (GET /client/{id}/collector)
|
|
GetCollectorByClientId(ctx echo.Context, id ClientID) error
|
|
// Set a collector
|
|
// (PATCH /client/{id}/collector)
|
|
SetCollectorByClientId(ctx echo.Context, id ClientID) error
|
|
// List the documents for a client
|
|
// (GET /client/{id}/documents)
|
|
ListDocumentsByClientId(ctx echo.Context, id ClientID) error
|
|
// Trigger an export
|
|
// (POST /client/{id}/export)
|
|
TriggerExport(ctx echo.Context, id ClientID) error
|
|
// Get client sync status
|
|
// (GET /client/{id}/status)
|
|
GetStatusByClientId(ctx echo.Context, id ClientID) error
|
|
// Get document details by its id
|
|
// (GET /document/{id})
|
|
GetDocument(ctx echo.Context, id DocumentID) error
|
|
// Check export state.
|
|
// (GET /export/{id})
|
|
ExportState(ctx echo.Context, id ExportID) error
|
|
// Get the home page menu
|
|
// (GET /home)
|
|
GetHomePage(ctx echo.Context) error
|
|
// Login to the application
|
|
// (GET /login)
|
|
Login(ctx echo.Context) error
|
|
// OAuth2 callback endpoint
|
|
// (GET /login-callback)
|
|
LoginCallback(ctx echo.Context, params LoginCallbackParams) error
|
|
// Logout from the application
|
|
// (GET /logout)
|
|
Logout(ctx echo.Context) error
|
|
// List queries
|
|
// (GET /query)
|
|
ListQueries(ctx echo.Context) error
|
|
// Create a new query
|
|
// (POST /query)
|
|
CreateQuery(ctx echo.Context) error
|
|
// Get a query by ID
|
|
// (GET /query/{id})
|
|
GetQuery(ctx echo.Context, id QueryID) error
|
|
// Update a query
|
|
// (PATCH /query/{id})
|
|
UpdateQuery(ctx echo.Context, id QueryID) error
|
|
// Test a query
|
|
// (POST /query/{id}/test)
|
|
TestQuery(ctx echo.Context, id QueryID) error
|
|
}
|
|
|
|
// ServerInterfaceWrapper converts echo contexts to parameters.
|
|
type ServerInterfaceWrapper struct {
|
|
Handler ServerInterface
|
|
}
|
|
|
|
// CreateClient converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) CreateClient(ctx echo.Context) error {
|
|
var err error
|
|
|
|
ctx.Set(PlaceholderAuthScopes, []string{})
|
|
|
|
// Invoke the callback with all the unmarshaled arguments
|
|
err = w.Handler.CreateClient(ctx)
|
|
return err
|
|
}
|
|
|
|
// GetClient converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) GetClient(ctx echo.Context) error {
|
|
var err error
|
|
// ------------- Path parameter "id" -------------
|
|
var id ClientID
|
|
|
|
err = runtime.BindStyledParameterWithOptions("simple", "id", ctx.Param("id"), &id, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true})
|
|
if err != nil {
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter id: %s", err))
|
|
}
|
|
|
|
ctx.Set(PlaceholderAuthScopes, []string{})
|
|
|
|
// Invoke the callback with all the unmarshaled arguments
|
|
err = w.Handler.GetClient(ctx, id)
|
|
return err
|
|
}
|
|
|
|
// UpdateClient converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) UpdateClient(ctx echo.Context) error {
|
|
var err error
|
|
// ------------- Path parameter "id" -------------
|
|
var id ClientID
|
|
|
|
err = runtime.BindStyledParameterWithOptions("simple", "id", ctx.Param("id"), &id, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true})
|
|
if err != nil {
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter id: %s", err))
|
|
}
|
|
|
|
ctx.Set(PlaceholderAuthScopes, []string{})
|
|
|
|
// Invoke the callback with all the unmarshaled arguments
|
|
err = w.Handler.UpdateClient(ctx, id)
|
|
return err
|
|
}
|
|
|
|
// GetCollectorByClientId converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) GetCollectorByClientId(ctx echo.Context) error {
|
|
var err error
|
|
// ------------- Path parameter "id" -------------
|
|
var id ClientID
|
|
|
|
err = runtime.BindStyledParameterWithOptions("simple", "id", ctx.Param("id"), &id, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true})
|
|
if err != nil {
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter id: %s", err))
|
|
}
|
|
|
|
ctx.Set(PlaceholderAuthScopes, []string{})
|
|
|
|
// Invoke the callback with all the unmarshaled arguments
|
|
err = w.Handler.GetCollectorByClientId(ctx, id)
|
|
return err
|
|
}
|
|
|
|
// SetCollectorByClientId converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) SetCollectorByClientId(ctx echo.Context) error {
|
|
var err error
|
|
// ------------- Path parameter "id" -------------
|
|
var id ClientID
|
|
|
|
err = runtime.BindStyledParameterWithOptions("simple", "id", ctx.Param("id"), &id, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true})
|
|
if err != nil {
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter id: %s", err))
|
|
}
|
|
|
|
ctx.Set(PlaceholderAuthScopes, []string{})
|
|
|
|
// Invoke the callback with all the unmarshaled arguments
|
|
err = w.Handler.SetCollectorByClientId(ctx, id)
|
|
return err
|
|
}
|
|
|
|
// ListDocumentsByClientId converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) ListDocumentsByClientId(ctx echo.Context) error {
|
|
var err error
|
|
// ------------- Path parameter "id" -------------
|
|
var id ClientID
|
|
|
|
err = runtime.BindStyledParameterWithOptions("simple", "id", ctx.Param("id"), &id, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true})
|
|
if err != nil {
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter id: %s", err))
|
|
}
|
|
|
|
ctx.Set(PlaceholderAuthScopes, []string{})
|
|
|
|
// Invoke the callback with all the unmarshaled arguments
|
|
err = w.Handler.ListDocumentsByClientId(ctx, id)
|
|
return err
|
|
}
|
|
|
|
// TriggerExport converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) TriggerExport(ctx echo.Context) error {
|
|
var err error
|
|
// ------------- Path parameter "id" -------------
|
|
var id ClientID
|
|
|
|
err = runtime.BindStyledParameterWithOptions("simple", "id", ctx.Param("id"), &id, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true})
|
|
if err != nil {
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter id: %s", err))
|
|
}
|
|
|
|
ctx.Set(PlaceholderAuthScopes, []string{})
|
|
|
|
// Invoke the callback with all the unmarshaled arguments
|
|
err = w.Handler.TriggerExport(ctx, id)
|
|
return err
|
|
}
|
|
|
|
// GetStatusByClientId converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) GetStatusByClientId(ctx echo.Context) error {
|
|
var err error
|
|
// ------------- Path parameter "id" -------------
|
|
var id ClientID
|
|
|
|
err = runtime.BindStyledParameterWithOptions("simple", "id", ctx.Param("id"), &id, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true})
|
|
if err != nil {
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter id: %s", err))
|
|
}
|
|
|
|
ctx.Set(PlaceholderAuthScopes, []string{})
|
|
|
|
// Invoke the callback with all the unmarshaled arguments
|
|
err = w.Handler.GetStatusByClientId(ctx, id)
|
|
return err
|
|
}
|
|
|
|
// GetDocument converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) GetDocument(ctx echo.Context) error {
|
|
var err error
|
|
// ------------- Path parameter "id" -------------
|
|
var id DocumentID
|
|
|
|
err = runtime.BindStyledParameterWithOptions("simple", "id", ctx.Param("id"), &id, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true})
|
|
if err != nil {
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter id: %s", err))
|
|
}
|
|
|
|
ctx.Set(PlaceholderAuthScopes, []string{})
|
|
|
|
// Invoke the callback with all the unmarshaled arguments
|
|
err = w.Handler.GetDocument(ctx, id)
|
|
return err
|
|
}
|
|
|
|
// ExportState converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) ExportState(ctx echo.Context) error {
|
|
var err error
|
|
// ------------- Path parameter "id" -------------
|
|
var id ExportID
|
|
|
|
err = runtime.BindStyledParameterWithOptions("simple", "id", ctx.Param("id"), &id, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true})
|
|
if err != nil {
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter id: %s", err))
|
|
}
|
|
|
|
ctx.Set(PlaceholderAuthScopes, []string{})
|
|
|
|
// Invoke the callback with all the unmarshaled arguments
|
|
err = w.Handler.ExportState(ctx, id)
|
|
return err
|
|
}
|
|
|
|
// GetHomePage converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) GetHomePage(ctx echo.Context) error {
|
|
var err error
|
|
|
|
ctx.Set(PlaceholderAuthScopes, []string{})
|
|
|
|
// Invoke the callback with all the unmarshaled arguments
|
|
err = w.Handler.GetHomePage(ctx)
|
|
return err
|
|
}
|
|
|
|
// Login converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) Login(ctx echo.Context) error {
|
|
var err error
|
|
|
|
ctx.Set(CognitoAuthScopes, []string{"openid", "email", "profile"})
|
|
|
|
// Invoke the callback with all the unmarshaled arguments
|
|
err = w.Handler.Login(ctx)
|
|
return err
|
|
}
|
|
|
|
// LoginCallback converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) LoginCallback(ctx echo.Context) error {
|
|
var err error
|
|
|
|
// Parameter object where we will unmarshal all parameters from the context
|
|
var params LoginCallbackParams
|
|
// ------------- Required query parameter "code" -------------
|
|
|
|
err = runtime.BindQueryParameter("form", true, true, "code", ctx.QueryParams(), ¶ms.Code)
|
|
if err != nil {
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter code: %s", err))
|
|
}
|
|
|
|
// ------------- Required query parameter "state" -------------
|
|
|
|
err = runtime.BindQueryParameter("form", true, true, "state", ctx.QueryParams(), ¶ms.State)
|
|
if err != nil {
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter state: %s", err))
|
|
}
|
|
|
|
// Invoke the callback with all the unmarshaled arguments
|
|
err = w.Handler.LoginCallback(ctx, params)
|
|
return err
|
|
}
|
|
|
|
// Logout converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) Logout(ctx echo.Context) error {
|
|
var err error
|
|
|
|
ctx.Set(PlaceholderAuthScopes, []string{})
|
|
|
|
// Invoke the callback with all the unmarshaled arguments
|
|
err = w.Handler.Logout(ctx)
|
|
return err
|
|
}
|
|
|
|
// ListQueries converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) ListQueries(ctx echo.Context) error {
|
|
var err error
|
|
|
|
ctx.Set(PlaceholderAuthScopes, []string{})
|
|
|
|
// Invoke the callback with all the unmarshaled arguments
|
|
err = w.Handler.ListQueries(ctx)
|
|
return err
|
|
}
|
|
|
|
// CreateQuery converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) CreateQuery(ctx echo.Context) error {
|
|
var err error
|
|
|
|
ctx.Set(PlaceholderAuthScopes, []string{})
|
|
|
|
// Invoke the callback with all the unmarshaled arguments
|
|
err = w.Handler.CreateQuery(ctx)
|
|
return err
|
|
}
|
|
|
|
// GetQuery converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) GetQuery(ctx echo.Context) error {
|
|
var err error
|
|
// ------------- Path parameter "id" -------------
|
|
var id QueryID
|
|
|
|
err = runtime.BindStyledParameterWithOptions("simple", "id", ctx.Param("id"), &id, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true})
|
|
if err != nil {
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter id: %s", err))
|
|
}
|
|
|
|
ctx.Set(PlaceholderAuthScopes, []string{})
|
|
|
|
// Invoke the callback with all the unmarshaled arguments
|
|
err = w.Handler.GetQuery(ctx, id)
|
|
return err
|
|
}
|
|
|
|
// UpdateQuery converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) UpdateQuery(ctx echo.Context) error {
|
|
var err error
|
|
// ------------- Path parameter "id" -------------
|
|
var id QueryID
|
|
|
|
err = runtime.BindStyledParameterWithOptions("simple", "id", ctx.Param("id"), &id, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true})
|
|
if err != nil {
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter id: %s", err))
|
|
}
|
|
|
|
ctx.Set(PlaceholderAuthScopes, []string{})
|
|
|
|
// Invoke the callback with all the unmarshaled arguments
|
|
err = w.Handler.UpdateQuery(ctx, id)
|
|
return err
|
|
}
|
|
|
|
// TestQuery converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) TestQuery(ctx echo.Context) error {
|
|
var err error
|
|
// ------------- Path parameter "id" -------------
|
|
var id QueryID
|
|
|
|
err = runtime.BindStyledParameterWithOptions("simple", "id", ctx.Param("id"), &id, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true})
|
|
if err != nil {
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter id: %s", err))
|
|
}
|
|
|
|
ctx.Set(PlaceholderAuthScopes, []string{})
|
|
|
|
// Invoke the callback with all the unmarshaled arguments
|
|
err = w.Handler.TestQuery(ctx, id)
|
|
return err
|
|
}
|
|
|
|
// This is a simple interface which specifies echo.Route addition functions which
|
|
// are present on both echo.Echo and echo.Group, since we want to allow using
|
|
// either of them for path registration
|
|
type EchoRouter interface {
|
|
CONNECT(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
|
|
DELETE(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
|
|
GET(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
|
|
HEAD(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
|
|
OPTIONS(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
|
|
PATCH(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
|
|
POST(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
|
|
PUT(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
|
|
TRACE(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
|
|
}
|
|
|
|
// RegisterHandlers adds each server route to the EchoRouter.
|
|
func RegisterHandlers(router EchoRouter, si ServerInterface) {
|
|
RegisterHandlersWithBaseURL(router, si, "")
|
|
}
|
|
|
|
// Registers handlers, and prepends BaseURL to the paths, so that the paths
|
|
// can be served under a prefix.
|
|
func RegisterHandlersWithBaseURL(router EchoRouter, si ServerInterface, baseURL string) {
|
|
|
|
wrapper := ServerInterfaceWrapper{
|
|
Handler: si,
|
|
}
|
|
|
|
router.POST(baseURL+"/client", wrapper.CreateClient)
|
|
router.GET(baseURL+"/client/:id", wrapper.GetClient)
|
|
router.PATCH(baseURL+"/client/:id", wrapper.UpdateClient)
|
|
router.GET(baseURL+"/client/:id/collector", wrapper.GetCollectorByClientId)
|
|
router.PATCH(baseURL+"/client/:id/collector", wrapper.SetCollectorByClientId)
|
|
router.GET(baseURL+"/client/:id/documents", wrapper.ListDocumentsByClientId)
|
|
router.POST(baseURL+"/client/:id/export", wrapper.TriggerExport)
|
|
router.GET(baseURL+"/client/:id/status", wrapper.GetStatusByClientId)
|
|
router.GET(baseURL+"/document/:id", wrapper.GetDocument)
|
|
router.GET(baseURL+"/export/:id", wrapper.ExportState)
|
|
router.GET(baseURL+"/home", wrapper.GetHomePage)
|
|
router.GET(baseURL+"/login", wrapper.Login)
|
|
router.GET(baseURL+"/login-callback", wrapper.LoginCallback)
|
|
router.GET(baseURL+"/logout", wrapper.Logout)
|
|
router.GET(baseURL+"/query", wrapper.ListQueries)
|
|
router.POST(baseURL+"/query", wrapper.CreateQuery)
|
|
router.GET(baseURL+"/query/:id", wrapper.GetQuery)
|
|
router.PATCH(baseURL+"/query/:id", wrapper.UpdateQuery)
|
|
router.POST(baseURL+"/query/:id/test", wrapper.TestQuery)
|
|
|
|
}
|
|
|
|
// Base64 encoded, gzipped, json marshaled Swagger object
|
|
var swaggerSpec = []string{
|
|
|
|
"H4sIAAAAAAAC/+xceW8juXL/KkTnAQF2dUs+gyDRs2d39DKH1/Ykm9iOQHWXJL7tbsok27Zm4O8e8OqT",
|
|
"rcOWvA+IAf9hqdlksVj1q2LxR/3wfBotaAyx4N7pD28OOACm/r3EAj6RiAj5IQDuM7IQhMbeqXqEQvkM",
|
|
"kXhKWYTlA0RipD+gW089/ZdHEgf08V8FiaCp/7/1vIYHTzhahOCdet1OxzbqdryGx/05RFiO6GxzKNtE",
|
|
"+OkTxDMx9077vYa3wEIAk2L9702neXL3s22sP/3Fa3hiuZAdccFIPPOen5/lWwxHIMxcz0ICsRidV6d6",
|
|
"PQfkq6dodN7yGh6R3y6wmHsNL8aR7JcEXsNjcJ8QBoF3KlgC+Zn8hcHUO/X+qZ2puq2f8nY6sJTpnPpJ",
|
|
"tEKOwDzfiyS5waUsH54WlNVKAurpXuRIB5ZS/JYAW9YJMTpHdIrEHNC9bLZ7UezoymAY8AWNOSh7GcXS",
|
|
"5HD4gTHK5Bc+jQXEylXwYhESX3lE++9cSvtj06nL3j4D53gGetDipO2oiAN7AIZAtpfTrvNa12CmbTtr",
|
|
"qEYaxQ84JMEl3CfAxRtOSQ2LmB4XTWiw3NGMrin9jOOlmRF/syldGkNByYLGSFCKIhwv7Qz5DmbX8C5B",
|
|
"sGVzOBXAqr7xJYkmwKRvcPBpHHA0gSllgARbkniG8AyTuJWH4W6vk/cJDeLSd2LR72nEJVESeafHh4NO",
|
|
"p+FFJNafOym2kljADJhUyHPD+xbjRMwpI9+lz7214h/nEKMkJ8JOLOrZqigXMc5wfLWM/eoajDQwmchB",
|
|
"OMJhSB+V9n1BHgDxZezzLDRNKA0Bx3JtTc8MsAA38C0YXQATBLiMt8iXTQlVS5o9kq+SYPP4YwFzk/Zf",
|
|
"ZEsNihZXbzTQqj7u0mnRyd/BF9ms1kRYeDIA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
|
|
"Ywok6BJ8IDatLlC29I+SKP5m3jlwHCB48uc4ngFHxCAw/QNiXuMtZ1bySqiqstVWjG7ZTYrVl1GQZLuV",
|
|
"PzO3yhFuhs3/wc3vnebJ7W1z7P7Fwkbl6EElbelUlALOri5/kUoVElEyJlZJVi5cp641wnY7vcHWwt5t",
|
|
"i0w5I0R4KqeTlXq0rWyJVBZX63t7OWT9Wx1m/X9CnwKglB0d4mBBSaGy6wQUmohaIPlEZxoOZEaHaKI3",
|
|
"1lpx+nc/VDEJOFdGEwd1sVSPk8rkhAcpyCuiqexfZQoyHc2ZcppCvM56Qyvgu83u+aBCL6XC+21i4729",
|
|
"lrWW4xAWb5Ll7y+rK8M+IwIYwe7TM3u3bc8nZnYYx85jWJ7B+7Z7D2dl9+k6W5tTlOHhxUhvtTcg++pb",
|
|
"B1tzfX8zqcI+TqTy981ewvS9z8n2D3A6pVnc7yTfNyb5WitweEYKxS9g92p/WU3uzZxjT+Br7gvX2dp7",
|
|
"yX6PlLLUAAo8siLublXiTG9xbcfnzQH3BnTeveP1ajKvpt/aH7RIf5/MXDxL7wG+gN+rLf6d3vuG9N6N",
|
|
"kbUtzN3jVziEM4X5oH63QAGzvq2cxPpwtS6bKf6ITolkA1zs3T3yl7FrfKR0+3obnk1nH8KaC9MuabWM",
|
|
"PAnfKXC7ZtdI1a52MdUne3BXJS8YDRI/vYmo7lUmjluhPo3aD13lYmaMck9frZPILDtU6CqTbMWG4FmR",
|
|
"sEivqJYfa7qxTNN8T2X26aadZZzUtK/KofmmfWU7KtNTqvlNe9Anobkeikegm3aDC5ehs97yRYXnu+f/",
|
|
"CwAA///aY3I0l2cAAA==",
|
|
}
|
|
|
|
// GetSwagger returns the content of the embedded swagger specification file
|
|
// or error if failed to decode
|
|
func decodeSpec() ([]byte, error) {
|
|
zipped, err := base64.StdEncoding.DecodeString(strings.Join(swaggerSpec, ""))
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error base64 decoding spec: %w", err)
|
|
}
|
|
zr, err := gzip.NewReader(bytes.NewReader(zipped))
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error decompressing spec: %w", err)
|
|
}
|
|
var buf bytes.Buffer
|
|
_, err = buf.ReadFrom(zr)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error decompressing spec: %w", err)
|
|
}
|
|
|
|
return buf.Bytes(), nil
|
|
}
|
|
|
|
var rawSpec = decodeSpecCached()
|
|
|
|
// a naive cached of a decoded swagger spec
|
|
func decodeSpecCached() func() ([]byte, error) {
|
|
data, err := decodeSpec()
|
|
return func() ([]byte, error) {
|
|
return data, err
|
|
}
|
|
}
|
|
|
|
// Constructs a synthetic filesystem for resolving external references when loading openapi specifications.
|
|
func PathToRawSpec(pathToFile string) map[string]func() ([]byte, error) {
|
|
res := make(map[string]func() ([]byte, error))
|
|
if len(pathToFile) > 0 {
|
|
res[pathToFile] = rawSpec
|
|
}
|
|
|
|
return res
|
|
}
|
|
|
|
// GetSwagger returns the Swagger specification corresponding to the generated code
|
|
// in this file. The external references of Swagger specification are resolved.
|
|
// The logic of resolving external references is tightly connected to "import-mapping" feature.
|
|
// Externally referenced files must be embedded in the corresponding golang packages.
|
|
// Urls can be supported but this task was out of the scope.
|
|
func GetSwagger() (swagger *openapi3.T, err error) {
|
|
resolvePath := PathToRawSpec("")
|
|
|
|
loader := openapi3.NewLoader()
|
|
loader.IsExternalRefsAllowed = true
|
|
loader.ReadFromURIFunc = func(loader *openapi3.Loader, url *url.URL) ([]byte, error) {
|
|
pathToFile := url.String()
|
|
pathToFile = path.Clean(pathToFile)
|
|
getSpec, ok := resolvePath[pathToFile]
|
|
if !ok {
|
|
err1 := fmt.Errorf("path not found: %s", pathToFile)
|
|
return nil, err1
|
|
}
|
|
return getSpec()
|
|
}
|
|
var specData []byte
|
|
specData, err = rawSpec()
|
|
if err != nil {
|
|
return
|
|
}
|
|
swagger, err = loader.LoadFromData(specData)
|
|
if err != nil {
|
|
return
|
|
}
|
|
return
|
|
}
|