configuration

package
v0.0.0-...-50fc4dd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 28, 2024 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildArgumentPresetJSONPathKey

func BuildArgumentPresetJSONPathKey(operationName string, jsonPath *jsonpath.Path) string

BuildArgumentPresetKey builds the argument preset key.

func ConvertToNDCSchema

func ConvertToNDCSchema(config *ConvertConfig, logger *slog.Logger) (*schema.NDCHttpSchema, error)

ConvertToNDCSchema converts to NDC HTTP schema from config.

func NewHeaderForwardingResponseObjectType

func NewHeaderForwardingResponseObjectType(resultType schema.Type, settings *ForwardResponseHeadersSettings) rest.ObjectType

NewHeaderForwardingResponseObjectType creates a new type for header forwarding response.

func NewHeadersArgumentInfo

func NewHeadersArgumentInfo() rest.ArgumentInfo

NewHeadersArgumentInfo creates a new forwarding headers argument information.

func ResolveConvertConfigArguments

func ResolveConvertConfigArguments(config *ConvertConfig, configDir string, args *ConvertCommandArguments)

ResolveConvertConfigArguments resolves convert config arguments.

func UpdateHTTPConfiguration

func UpdateHTTPConfiguration(configurationDir string, logger *slog.Logger) (*Configuration, []NDCHttpRuntimeSchema, *schema.NDCHttpSchema, error)

UpdateHTTPConfiguration validates and updates the HTTP configuration.

func ValidateArgumentPreset

func ValidateArgumentPreset(httpSchema *rest.NDCHttpSchema, preset rest.ArgumentPresetConfig, isGlobal bool) (*jsonpath.Path, map[string]schema.TypeRepresentation, error)

ValidateArgumentPreset validates the argument preset.

Types

type ConcurrencySettings

type ConcurrencySettings struct {
	// Maximum number of concurrent executions if there are many query variables.
	Query uint `json:"query" yaml:"query"`
	// Maximum number of concurrent executions if there are many mutation operations.
	Mutation uint `json:"mutation" yaml:"mutation"`
	// Maximum number of concurrent requests to remote servers (distribution mode).
	HTTP uint `json:"http" yaml:"http"`
}

ConcurrencySettings represent settings for concurrent webhook executions to remote servers.

type ConfigItem

type ConfigItem struct {
	ConvertConfig `yaml:",inline"`

	// Distributed enables distributed schema
	Distributed *bool `json:"distributed,omitempty" yaml:"distributed,omitempty"`
	// configure the request timeout in seconds.
	Timeout *utils.EnvInt       `json:"timeout,omitempty" mapstructure:"timeout" yaml:"timeout,omitempty"`
	Retry   *RetryPolicySetting `json:"retry,omitempty"   mapstructure:"retry"   yaml:"retry,omitempty"`
}

ConfigItem extends the ConvertConfig with advanced options.

func (ConfigItem) GetRuntimeSettings

func (ci ConfigItem) GetRuntimeSettings() (*rest.RuntimeSettings, error)

GetRuntimeSettings validate and get runtime settings.

func (ConfigItem) IsDistributed

func (ci ConfigItem) IsDistributed() bool

IsDistributed checks if the distributed option is enabled.

type ConfigValidator

type ConfigValidator struct {
	// contains filtered or unexported fields
}

ConfigValidator manages the validation and status of upstreams.

func ValidateConfiguration

func ValidateConfiguration(config *Configuration, contextPath string, schemas []NDCHttpRuntimeSchema, mergedSchema *schema.NDCHttpSchema, logger *slog.Logger, noColor bool) (*ConfigValidator, error)

ValidateConfiguration evaluates, validates the configuration and suggests required actions to make the connector working.

func (*ConfigValidator) HasError

func (cv *ConfigValidator) HasError() bool

HasError checks if the configuration has error.

func (*ConfigValidator) IsOk

func (cv *ConfigValidator) IsOk() bool

IsOk checks if the configuration has nothing to be complained.

func (*ConfigValidator) Render

func (cv *ConfigValidator) Render(w io.Writer)

Render renders the help text.

type Configuration

type Configuration struct {
	Output string `json:"output,omitempty" yaml:"output,omitempty"`
	// Require strict validation
	Strict         bool                   `json:"strict"                   yaml:"strict"`
	ForwardHeaders ForwardHeadersSettings `json:"forwardHeaders,omitempty" yaml:"forwardHeaders,omitempty"`
	Concurrency    ConcurrencySettings    `json:"concurrency,omitempty"    yaml:"concurrency,omitempty"`
	Files          []ConfigItem           `json:"files"                    yaml:"files"`
}

Configuration contains required settings for the connector.

func ReadConfigurationFile

func ReadConfigurationFile(configurationDir string) (*Configuration, error)

ReadConfigurationFile reads and decodes the configuration file from the configuration directory.

type ConvertCommandArguments

type ConvertCommandArguments struct {
	File                string            `help:"File path needs to be converted."                                                     short:"f"`
	Config              string            `help:"Path of the config file."                                                             short:"c"`
	Output              string            `help:"The location where the ndc schema file will be generated. Print to stdout if not set" short:"o"`
	Spec                string            `help:"The API specification of the file, is one of oas3 (openapi3), oas2 (openapi2)"`
	Format              string            `` /* 222-byte string literal not displayed */
	Strict              bool              `default:"false"                                                                             help:"Require strict validation"`
	NoDeprecation       bool              `default:"false"                                                                             help:"Ignore deprecated fields"`
	Pure                bool              `` /* 130-byte string literal not displayed */
	Prefix              string            `help:"Add a prefix to the function and procedure names"`
	TrimPrefix          string            `help:"Trim the prefix in URL, e.g. /v1"`
	EnvPrefix           string            `help:"The environment variable prefix for security values, e.g. PET_STORE"`
	MethodAlias         map[string]string `help:"Alias names for HTTP method. Used for prefix renaming, e.g. getUsers, postUser"`
	AllowedContentTypes []string          `help:"Allowed content types. All content types are allowed by default"`
	PatchBefore         []string          `help:"Patch files to be applied into the input file before converting"`
	PatchAfter          []string          `help:"Patch files to be applied into the input file after converting"`
}

ConvertCommandArguments represent available command arguments for the convert command.

type ConvertConfig

type ConvertConfig struct {
	// File path needs to be converted
	File string `json:"file" jsonschema:"required" yaml:"file"`
	// The API specification of the file, is one of oas3 (openapi3), oas2 (openapi2)
	Spec rest.SchemaSpecType `json:"spec,omitempty" jsonschema:"default=oas3" yaml:"spec"`
	// Alias names for HTTP method. Used for prefix renaming, e.g. getUsers, postUser
	MethodAlias map[string]string `json:"methodAlias,omitempty" yaml:"methodAlias"`
	// Add a prefix to the function and procedure names
	Prefix string `json:"prefix,omitempty" yaml:"prefix"`
	// Trim the prefix in URL, e.g. /v1
	TrimPrefix string `json:"trimPrefix,omitempty" yaml:"trimPrefix"`
	// The environment variable prefix for security values, e.g. PET_STORE
	EnvPrefix string `json:"envPrefix,omitempty" yaml:"envPrefix"`
	// Return the pure NDC schema only
	Pure bool `json:"pure,omitempty" yaml:"pure"`
	// Ignore deprecated fields.
	NoDeprecation bool `json:"noDeprecation,omitempty" yaml:"noDeprecation"`
	// Patch files to be applied into the input file before converting
	PatchBefore []restUtils.PatchConfig `json:"patchBefore,omitempty" yaml:"patchBefore"`
	// Patch files to be applied into the input file after converting
	PatchAfter []restUtils.PatchConfig `json:"patchAfter,omitempty" yaml:"patchAfter"`
	// Allowed content types. All content types are allowed by default
	AllowedContentTypes []string `json:"allowedContentTypes,omitempty" yaml:"allowedContentTypes"`
	// The location where the ndc schema file will be generated. Print to stdout if not set
	Output string `json:"output,omitempty" yaml:"output,omitempty"`
}

ConvertConfig represents the content of convert config file.

type ForwardHeadersSettings

type ForwardHeadersSettings struct {
	// Enable headers forwarding.
	Enabled bool `json:"enabled" yaml:"enabled"`
	// The argument field name to be added for headers forwarding.
	ArgumentField *string `json:"argumentField" jsonschema:"oneof_type=string;null,pattern=^[a-zA-Z_]\\w+$" yaml:"argumentField"`
	// HTTP response headers to be forwarded from a data connector to the client.
	ResponseHeaders *ForwardResponseHeadersSettings `json:"responseHeaders" jsonschema:"nullable" yaml:"responseHeaders"`
}

ForwardHeadersSettings hold settings of header forwarding from and to Hasura engine.

func (*ForwardHeadersSettings) UnmarshalJSON

func (j *ForwardHeadersSettings) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler.

type ForwardResponseHeadersSettings

type ForwardResponseHeadersSettings struct {
	// Name of the field in the NDC function/procedure's result which contains the response headers.
	HeadersField string `json:"headersField" jsonschema:"pattern=^[a-zA-Z_]\\w+$" yaml:"headersField"`
	// Name of the field in the NDC function/procedure's result which contains the result.
	ResultField string `json:"resultField" jsonschema:"pattern=^[a-zA-Z_]\\w+$" yaml:"resultField"`
	// List of actual HTTP response headers from the data connector to be set as response headers. Returns all headers if empty.
	ForwardHeaders []string `json:"forwardHeaders" yaml:"forwardHeaders"`
}

ForwardHeadersSettings hold settings of header forwarding from http response to Hasura engine.

func (ForwardResponseHeadersSettings) Validate

Validate checks if the setting is valid.

type NDCHttpRuntimeSchema

type NDCHttpRuntimeSchema struct {
	Name    string               `json:"name" yaml:"name"`
	Runtime rest.RuntimeSettings `json:"-"    yaml:"-"`
	*rest.NDCHttpSchema
}

NDCHttpRuntimeSchema wraps NDCHttpSchema with runtime settings.

func BuildSchemaFromConfig

func BuildSchemaFromConfig(config *Configuration, configDir string, logger *slog.Logger) ([]NDCHttpRuntimeSchema, map[string][]string)

BuildSchemaFromConfig build NDC HTTP schema from the configuration.

func MergeNDCHttpSchemas

func MergeNDCHttpSchemas(config *Configuration, schemas []NDCHttpRuntimeSchema) (*rest.NDCHttpSchema, []NDCHttpRuntimeSchema, map[string][]string)

MergeNDCHttpSchemas merge HTTP schemas into a single schema object.

func ReadSchemaOutputFile

func ReadSchemaOutputFile(configDir string, filePath string, logger *slog.Logger) ([]NDCHttpRuntimeSchema, error)

ReadSchemaOutputFile reads the schema output file in disk.

type RetryPolicySetting

type RetryPolicySetting struct {
	// Number of retry times
	Times utils.EnvInt `json:"times,omitempty" mapstructure:"times" yaml:"times,omitempty"`
	// Delay retry delay in milliseconds
	Delay utils.EnvInt `json:"delay,omitempty" mapstructure:"delay" yaml:"delay,omitempty"`
	// HTTPStatus retries if the remote service returns one of these http status
	HTTPStatus []int `json:"httpStatus,omitempty" mapstructure:"httpStatus" yaml:"httpStatus,omitempty"`
}

RetryPolicySetting represents retry policy settings.

func (RetryPolicySetting) Validate

func (rs RetryPolicySetting) Validate() (*rest.RetryPolicy, error)

Validate if the current instance is valid.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL