hcl

package
v0.0.0-...-3cc3ff2 Latest Latest
Warning

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

Go to latest
Published: May 17, 2021 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultOnError

func DefaultOnError(err *specs.OnError)

DefaultOnError sets the default values for not defined properties

func DependenciesExcept

func DependenciesExcept(dependencies specs.Dependencies, resource string) specs.Dependencies

DependenciesExcept copies the given dependencies except the given resource

func DependsOn

func DependsOn(dependency *specs.Node, nodes ...*specs.Node)

DependsOn sets the given dependency for the given nodes

func DiscoveryClientsResolver

func DiscoveryClientsResolver(path string) providers.ServiceDiscoveryClientsResolver

DiscoveryClientsResolver parses configuration.

func EndpointsResolver

func EndpointsResolver(path string) providers.EndpointsResolver

EndpointsResolver constructs a resource resolver for the given path

func FlowsResolver

func FlowsResolver(path string) providers.FlowsResolver

FlowsResolver constructs a resource resolver for the given path

func JoinPath

func JoinPath(values ...string) (result string)

JoinPath joins the given flow paths

func MergeOnError

func MergeOnError(left *specs.OnError, right *specs.OnError)

MergeOnError merges the right on error specs into the left on error

func ParseDiscoveryClients

func ParseDiscoveryClients(ctx *broker.Context, manifest Manifest) (specs.ServiceDiscoveryClients, error)

func ParseEndpoints

func ParseEndpoints(ctx *broker.Context, manifest Manifest) (specs.EndpointList, error)

ParseEndpoints parses the given intermediate manifest to a endpoints manifest

func ParseFlows

func ParseFlows(ctx *broker.Context, manifest Manifest) (errObject *specs.ParameterMap, _ specs.FlowListInterface, _ error)

ParseFlows parses the given intermediate manifest to a flows manifest

func ParseIntermediateBefore

func ParseIntermediateBefore(ctx *broker.Context, before *Before) (dependencies specs.Dependencies, references []Resources, resources []Resource)

ParseIntermediateBefore parses the given before into a collection of dependencies

func ParseIntermediateCall

func ParseIntermediateCall(ctx *broker.Context, call *Call) (*specs.Call, error)

ParseIntermediateCall parses the given intermediate call to a spec call

func ParseIntermediateCallParameterMap

func ParseIntermediateCallParameterMap(ctx *broker.Context, params *Call) (*specs.ParameterMap, error)

ParseIntermediateCallParameterMap parses the given intermediate parameter map to a spec parameter map

func ParseIntermediateCondition

func ParseIntermediateCondition(ctx *broker.Context, dependencies specs.Dependencies, condition Condition) (specs.NodeList, error)

ParseIntermediateCondition parses the given intermediate condition and returns the compiled nodes

func ParseIntermediateDefinitionOptions

func ParseIntermediateDefinitionOptions(options *BlockOptions) specs.Options

ParseIntermediateDefinitionOptions parses the given intermediate options to a definitions options

func ParseIntermediateEndpoint

func ParseIntermediateEndpoint(ctx *broker.Context, endpoint Endpoint) *specs.Endpoint

ParseIntermediateEndpoint parses the given intermediate endpoint to a specs endpoint

func ParseIntermediateFlow

func ParseIntermediateFlow(ctx *broker.Context, flow Flow) (*specs.Flow, error)

ParseIntermediateFlow parses the given intermediate flow to a specs flow

func ParseIntermediateHeader

func ParseIntermediateHeader(ctx *broker.Context, header *Header) (specs.Header, error)

ParseIntermediateHeader parses the given intermediate header to a spec header

func ParseIntermediateInputParameterMap

func ParseIntermediateInputParameterMap(ctx *broker.Context, params *InputParameterMap) (*specs.ParameterMap, error)

ParseIntermediateInputParameterMap parses the given input parameter map

func ParseIntermediateMethods

func ParseIntermediateMethods(ctx *broker.Context, methods []Method) ([]*specs.Method, error)

ParseIntermediateMethods parses the given methods for the given service

func ParseIntermediateNestedParameterMap

func ParseIntermediateNestedParameterMap(ctx *broker.Context, params NestedParameterMap, path string) (*specs.Property, error)

ParseIntermediateNestedParameterMap parses the given intermediate parameter map to a spec parameter map

func ParseIntermediateNode

func ParseIntermediateNode(ctx *broker.Context, dependencies specs.Dependencies, node Resource) (*specs.Node, error)

ParseIntermediateNode parses the given intermediate call to a spec call

func ParseIntermediateOnError

func ParseIntermediateOnError(ctx *broker.Context, onError *OnError) (*specs.OnError, error)

ParseIntermediateOnError returns a specs on error

func ParseIntermediateParameterMap

func ParseIntermediateParameterMap(ctx *broker.Context, params *ParameterMap) (*specs.ParameterMap, error)

ParseIntermediateParameterMap parses the given intermediate parameter map to a spec parameter map

func ParseIntermediateParameters

func ParseIntermediateParameters(ctx *broker.Context, options hcl.Body) (map[string]*specs.Property, error)

ParseIntermediateParameters parses the given intermediate parameters

func ParseIntermediateProperty

func ParseIntermediateProperty(ctx *broker.Context, path string, property *hcl.Attribute, value cty.Value) (*specs.Property, error)

ParseIntermediateProperty parses the given intermediate property to a spec property

func ParseIntermediateProxy

func ParseIntermediateProxy(ctx *broker.Context, proxy Proxy) (*specs.Proxy, error)

ParseIntermediateProxy parses the given intermediate proxy to a specs proxy

func ParseIntermediateProxyForward

func ParseIntermediateProxyForward(ctx *broker.Context, proxy ProxyForward) (*specs.Call, error)

ParseIntermediateProxyForward parses the given intermediate proxy forward to a specs proxy forward

func ParseIntermediateRepeatedParameterMap

func ParseIntermediateRepeatedParameterMap(ctx *broker.Context, params RepeatedParameterMap, path string) (*specs.Property, error)

ParseIntermediateRepeatedParameterMap parses the given intermediate repeated parameter map to a spec repeated parameter map

func ParseIntermediateResources

func ParseIntermediateResources(ctx *broker.Context, dependencies specs.Dependencies, resources Resources) (specs.NodeList, error)

ParseIntermediateResources parses the given resources to nodes

func ParseIntermediateRewriteRules

func ParseIntermediateRewriteRules(ctx *broker.Context, rewrite []ProxyRewrite) ([]specs.Rewrite, error)

func ParseIntermediateService

func ParseIntermediateService(parent *broker.Context, manifest Service) (*specs.Service, error)

ParseIntermediateService parses the given intermediate service to a specs service

func ParseIntermediateSpecOptions

func ParseIntermediateSpecOptions(options hcl.Body) specs.Options

ParseIntermediateSpecOptions parses the given intermediate options to a spec options

func ParseServices

func ParseServices(ctx *broker.Context, manifest Manifest) (specs.ServiceList, error)

ParseServices parses the given intermediate manifest to a schema

func ResolveErrors

func ResolveErrors(flows specs.FlowListInterface, err *specs.ParameterMap)

ResolveErrors clones any previously defined error objects or error handles

func ServicesResolver

func ServicesResolver(path string) providers.ServicesResolver

ServicesResolver constructs a schema resolver for the given path. The HCL schema resolver relies on other schema registries. Those need to be resolved before the HCL schemas are resolved.

func SetScalar

func SetScalar(ctx *broker.Context, tmpl *specs.Template, value cty.Value) error

SetScalar sets the given value as default value inside the given property

Types

type BaseParameterMap

type BaseParameterMap struct {
	Nested     []NestedParameterMap   `hcl:"message,block"`
	Repeated   []RepeatedParameterMap `hcl:"repeated,block"`
	Properties hcl.Body               `hcl:",remain"`
}

BaseParameterMap contains a set of generic fields.

type Before

type Before ResourceBlock

Before intermediate specification.

type BlockOptions

type BlockOptions struct {
	Body hcl.Body `hcl:",remain"`
}

BlockOptions holds the raw options.

type Call

type Call struct {
	BaseParameterMap `hcl:",remain"`

	Service    string        `hcl:"service,label"`
	Method     string        `hcl:"method,label"`
	Parameters *BlockOptions `hcl:"params,block"`
	Options    *BlockOptions `hcl:"options,block"`
	Header     *Header       `hcl:"header,block"`
}

Call intermediate specification.

type Condition

type Condition struct {
	ResourceBlock `hcl:",remain"`

	Expression string      `hcl:"expression,label"`
	Conditions []Condition `hcl:"if,block"`
}

Condition represents a condition on which the scoped resources should be executed if true.

type Discovery

type Discovery struct {
	Name     string `hcl:"name,label"`
	Provider string `hcl:"provider,optional"`
	Address  string `hcl:"address"`
}

Discovery describes a service discovery client configuration

Examples:

discovery "consul" {
	address = "http://localhost:8500"
}

discovery "foobar" {
	provider = "consul"
	address = "http://localhost:8500"
}

type Endpoint

type Endpoint struct {
	Flow     string   `hcl:"flow,label"`
	Listener string   `hcl:"listener,label"`
	Options  hcl.Body `hcl:",remain"`
}

Endpoint intermediate specification.

type ErrPathNotFound

type ErrPathNotFound struct {
	Path string
	// contains filtered or unexported fields
}

ErrPathNotFound occurs when path cannot be resolved

func (ErrPathNotFound) Error

func (e ErrPathNotFound) Error() string

Error returns a description of the given error as a string

func (ErrPathNotFound) Prettify

func (e ErrPathNotFound) Prettify() prettyerr.Error

Prettify returns the prettified version of the given error

func (ErrPathNotFound) Unwrap

func (i ErrPathNotFound) Unwrap() error

type ErrUnkownPropertyType

type ErrUnkownPropertyType string

ErrUnkownPropertyType is thrown when the given property type is unkown

func (ErrUnkownPropertyType) Error

func (e ErrUnkownPropertyType) Error() string

type Expression

type Expression struct{ hcl.Expression }

Expression is a wrapper over hcl.Expression providing extra functionality.

func (Expression) Position

func (expr Expression) Position() string

Position returns the position for tracer.

type Flow

type Flow struct {
	Condition `hcl:",remain"`

	Name    string             `hcl:"name,label"`
	Error   *ParameterMap      `hcl:"error,block"`
	Input   *InputParameterMap `hcl:"input,block"`
	OnError *OnError           `hcl:"on_error,block"`
	Before  *Before            `hcl:"before,block"`
	Output  *ParameterMap      `hcl:"output,block"`
}

Flow intermediate specification.

type GRPC

type GRPC struct {
	Address string `hcl:"address"`
}

GRPC represent the gRPC option definitions.

type GraphQL

type GraphQL struct {
	Address string `hcl:"address"`
}

GraphQL represents the GraphQL option definitions

type HTTP

type HTTP struct {
	Address      string   `hcl:"address"`
	Origin       []string `hcl:"origin,optional"`
	CertFile     string   `hcl:"cert_file,optional"`
	KeyFile      string   `hcl:"key_file,optional"`
	ReadTimeout  string   `hcl:"read_timeout,optional"`
	WriteTimeout string   `hcl:"write_timeout,optional"`
}

HTTP represent the HTTP option definitions.

type Header struct {
	Body hcl.Body `hcl:",remain"`
}

Header represents a collection of key values.

type InputParameterMap

type InputParameterMap struct {
	Schema  string        `hcl:"schema,label"`
	Options *BlockOptions `hcl:"options,block"`
	Header  []string      `hcl:"header,optional"`
}

InputParameterMap is the initial map of parameter names (keys) and their (templated) values (values).

type InputRepeatedParameterMap

type InputRepeatedParameterMap struct {
	Name       string                      `hcl:"name,label"`
	Nested     []NestedParameterMap        `hcl:"message,block"`
	Repeated   []InputRepeatedParameterMap `hcl:"repeated,block"`
	Properties hcl.Body                    `hcl:",remain"`
}

InputRepeatedParameterMap is a map of repeated message blocks/values.

type Manifest

type Manifest struct {
	LogLevel         string        `hcl:"log_level,optional"`
	GraphQL          *GraphQL      `hcl:"graphql,block"`
	HTTP             *HTTP         `hcl:"http,block"`
	GRPC             *GRPC         `hcl:"grpc,block"`
	Prometheus       *Prometheus   `hcl:"prometheus,block"`
	Protobuffers     []string      `hcl:"protobuffers,optional"`
	Avro             []string      `hcl:"avro,optional"`
	Openapi3         []string      `hcl:"openapi3,optional"`
	Include          []string      `hcl:"include,optional"`
	Error            *ParameterMap `hcl:"error,block"`
	Flows            []Flow        `hcl:"flow,block"`
	Proxy            []Proxy       `hcl:"proxy,block"`
	Endpoints        []Endpoint    `hcl:"endpoint,block"`
	Services         []Service     `hcl:"service,block"`
	ServiceSelector  []Services    `hcl:"services,block"`
	DiscoveryServers []Discovery   `hcl:"discovery,block"`
}

Manifest intermediate specs

func ResolvePath

func ResolvePath(ctx *broker.Context, ignore []string, path string) ([]Manifest, error)

ResolvePath resolves the given path and returns the available manifests. All defined includes are followed and their manifests are included

func UnmarshalHCL

func UnmarshalHCL(parent *broker.Context, filename string, reader io.Reader) (manifest Manifest, _ error)

UnmarshalHCL unmarshals the given HCL stream into a intermediate resource. All environment variables found inside the given file are replaced.

type Method

type Method struct {
	Name    string        `hcl:"name,label"`
	Input   string        `hcl:"request,optional"`
	Output  string        `hcl:"response,optional"`
	Options *BlockOptions `hcl:"options,block"`
}

Method represents a service method

type NestedParameterMap

type NestedParameterMap struct {
	BaseParameterMap `hcl:",remain"`

	Name string `hcl:"name,label"`
}

NestedParameterMap is a map of parameter names (keys) and their (templated) values (values).

type OnError

type OnError struct {
	Schema string        `hcl:"schema,optional"`
	Params *BlockOptions `hcl:"params,block"`
	Body   hcl.Body      `hcl:",remain"`
}

OnError intermediate specification.

type Options

type Options struct {
	LogLevel     string
	Includes     []string
	Protobuffers []string
	Avro         []string
	Openapi3     []string
	GraphQL      *GraphQL
	HTTP         *HTTP
	GRPC         *GRPC
	Prometheus   *Prometheus
	Discovery    *Discovery
}

Options represents the available options that could be defined inside a HCL definition

func GetOptions

func GetOptions(ctx *broker.Context, path string) (*Options, error)

GetOptions returns the defined options inside the given path

type ParameterMap

type ParameterMap struct {
	BaseParameterMap `hcl:",remain"`

	Schema  string        `hcl:"schema,label"`
	Options *BlockOptions `hcl:"options,block"`
	Header  *Header       `hcl:"header,block"`
}

ParameterMap is the initial map of parameter names (keys) and their (templated) values (values).

type Prometheus

type Prometheus struct {
	Address string `hcl:"address"`
}

Prometheus represent the prometheus option definitions.

type Proxy

type Proxy struct {
	Condition `hcl:",remain"`

	Name    string         `hcl:"name,label"`
	Error   *ParameterMap  `hcl:"error,block"`
	Input   *ProxyInput    `hcl:"input,block"`
	OnError *OnError       `hcl:"on_error,block"`
	Before  *Before        `hcl:"before,block"`
	Forward ProxyForward   `hcl:"forward,block"`
	Rewrite []ProxyRewrite `hcl:"rewrite,block"`
}

Proxy specification.

type ProxyForward

type ProxyForward struct {
	Service string  `hcl:"service,label"`
	Header  *Header `hcl:"header,block"`
}

ProxyForward specification.

type ProxyInput

type ProxyInput struct {
	Options *BlockOptions `hcl:"options,block"`
	Header  []string      `hcl:"header,optional"`
	Params  string        `hcl:"params,optional"`
}

ProxyInput represents the proxy input block.

type ProxyRewrite

type ProxyRewrite struct {
	Pattern  string   `hcl:"pattern,label"`
	Template string   `hcl:"template,label"`
	Options  hcl.Body `hcl:",remain"`
}

ProxyRewrite describes rewrite rules. Allows rewriting/replacement URL segments

Example:

endpoint "test" "http" {
	method = "GET"
	endpoint = "/prefix/*tail"
}

proxy "test" {
	forward "com.semaphore.TestService" {}
	rewrite "/prefix/(?P<first>\w+)/(?P<second>\w+)" "/<second>/<first>" {} // swap URL segments
	rewrite "/prefix/(?P<tail>.*)" "/<tail>" {} // strip static `/prefix`
}

NOTE: multiple rewrite rules can be specified but only one can be applied (the first one which matches the pattern) so put strict rules first (by priority) and keep wildcards in the bottom

type RepeatedParameterMap

type RepeatedParameterMap struct {
	BaseParameterMap `hcl:",remain"`

	Name     string `hcl:"name,label"`
	Template string `hcl:"template,label"`
}

RepeatedParameterMap is a map of repeated message blocks/values.

type Resource

type Resource struct {
	Name         string        `hcl:"name,label"`
	DependsOn    []string      `hcl:"depends_on,optional"`
	Request      *Call         `hcl:"request,block"`
	Rollback     *Call         `hcl:"rollback,block"`
	OnError      *OnError      `hcl:"on_error,block"`
	ExpectStatus []int         `hcl:"expect_status,optional"`
	Error        *ParameterMap `hcl:"error,block"`
}

Resource intermediate specification.

type ResourceBlock

type ResourceBlock struct {
	References []Resources `hcl:"resources,block"`
	Resources  []Resource  `hcl:"resource,block"`
}

ResourceBlock contains resources and references.

type Resources

type Resources struct {
	Properties hcl.Body `hcl:",remain"`
}

Resources represent a collection of resources which are references or custom defined functions.

type Service

type Service struct {
	Package   string        `hcl:"package,label"`
	Name      string        `hcl:"name,label"`
	Transport string        `hcl:"transport,optional"`
	Codec     string        `hcl:"codec,optional"`
	Host      string        `hcl:"host,optional"`
	Methods   []Method      `hcl:"method,block"`
	Options   *BlockOptions `hcl:"options,block"`
	Resolver  string        `hcl:"resolver,optional"`
}

Service specification.

type ServiceSelector

type ServiceSelector struct {
	Pattern       string   `hcl:"pattern,label"`
	Host          string   `hcl:"host,optional"`
	Transport     string   `hcl:"transport,optional"`
	Codec         string   `hcl:"codec,optional"`
	RequestCodec  string   `hcl:"request_codec,optional"`
	ResponseCodec string   `hcl:"response_codec,optional"`
	Resolver      string   `hcl:"resolver,optional"`
	Options       hcl.Body `hcl:",remain"`
}

ServiceSelector targets any service match in the given service selector.

type Services

type Services struct {
	Selectors []ServiceSelector `hcl:"select,block"`
}

Services specification.

Jump to

Keyboard shortcuts

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