Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor HCL provider #165

Merged
merged 6 commits into from
Nov 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
159 changes: 76 additions & 83 deletions pkg/providers/hcl/intermediate.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package hcl

import (
"github.com/hashicorp/hcl/v2"
)
import "github.com/hashicorp/hcl/v2"

// Manifest intermediate specs
type Manifest struct {
Expand All @@ -22,12 +20,12 @@ type Manifest struct {
ServiceSelector []Services `hcl:"services,block"`
}

// GraphQL represents the GraphQL option definitions
// GraphQL represents the GraphQL option definitions.
type GraphQL struct {
Address string `hcl:"address"`
}

// HTTP represent the HTTP option definitions
// HTTP represent the HTTP option definitions.
type HTTP struct {
Address string `hcl:"address"`
Origin []string `hcl:"origin,optional"`
Expand All @@ -37,108 +35,114 @@ type HTTP struct {
WriteTimeout string `hcl:"write_timeout,optional"`
}

// GRPC represent the gRPC option definitions
// GRPC represent the gRPC option definitions.
type GRPC struct {
Address string `hcl:"address"`
}

// Prometheus represent the prometheus option definitions
// Prometheus represent the prometheus option definitions.
type Prometheus struct {
Address string `hcl:"address"`
}

// Before intermediate specification
type Before struct {
// ResourceBlock contains resources and references.
type ResourceBlock struct {
References []Resources `hcl:"resources,block"`
Resources []Resource `hcl:"resource,block"`
}

// Condition represents a condition on which the scoped resources should be executed if true
// Before intermediate specification.
type Before ResourceBlock

// Condition represents a condition on which the scoped resources should be executed if true.
type Condition struct {
ResourceBlock `hcl:",remain"`

Expression string `hcl:"expression,label"`
Conditions []Condition `hcl:"if,block"`
References []Resources `hcl:"resources,block"`
Resources []Resource `hcl:"resource,block"`
}

// Flow intermediate specification
// Flow intermediate specification.
type Flow struct {
Name string `hcl:"name,label"`
Error *ParameterMap `hcl:"error,block"`
OnError *OnError `hcl:"on_error,block"`
Before *Before `hcl:"before,block"`
Input *InputParameterMap `hcl:"input,block"`
References []Resources `hcl:"resources,block"`
Resources []Resource `hcl:"resource,block"`
Conditions []Condition `hcl:"if,block"`
Output *ParameterMap `hcl:"output,block"`
}

// ParameterMap is the initial map of parameter names (keys) and their (templated) values (values)
type ParameterMap struct {
Schema string `hcl:"schema,label"`
Options *BlockOptions `hcl:"options,block"`
Header *Header `hcl:"header,block"`
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"`
}

// BaseParameterMap contains a set of generic fields.
type BaseParameterMap struct {
Nested []NestedParameterMap `hcl:"message,block"`
Repeated []RepeatedParameterMap `hcl:"repeated,block"`
Properties hcl.Body `hcl:",remain"`
}

// Resources represent a collection of resources which are references or custom defined functions
// ParameterMap is the initial map of parameter names (keys) and their (templated) values (values).
type ParameterMap struct {
BaseParameterMap `hcl:",remain"`

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

// Resources represent a collection of resources which are references or custom defined functions.
type Resources struct {
Properties hcl.Body `hcl:",remain"`
}

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

// Header represents a collection of key values
// Header represents a collection of key values.
type Header struct {
Body hcl.Body `hcl:",remain"`
}

// InputParameterMap is the initial map of parameter names (keys) and their (templated) values (values)
// InputParameterMap is the initial map of parameter names (keys) and their (templated) values (values).
type InputParameterMap struct {
Schema string `hcl:"schema,label"`
Options *BlockOptions `hcl:"options,block"`
Header []string `hcl:"header,optional"`
}

// BlockOptions holds the raw options
// BlockOptions holds the raw options.
type BlockOptions struct {
Body hcl.Body `hcl:",remain"`
}

// NestedParameterMap is a map of parameter names (keys) and their (templated) values (values)
// NestedParameterMap is a map of parameter names (keys) and their (templated) values (values).
type NestedParameterMap struct {
Name string `hcl:"name,label"`
Nested []NestedParameterMap `hcl:"message,block"`
Repeated []RepeatedParameterMap `hcl:"repeated,block"`
Properties hcl.Body `hcl:",remain"`
BaseParameterMap `hcl:",remain"`

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

// InputRepeatedParameterMap is a map of repeated message blocks/values
// InputRepeatedParameterMap is a map of repeated message blocks/values.
type InputRepeatedParameterMap struct {
Name string `hcl:"name,label"`
Nested []NestedParameterMap `hcl:"message,block"`
Repeated []InputRepeatedParameterMap `hcl:"repeated,block"`
Properties hcl.Body `hcl:",remain"`
}

// RepeatedParameterMap is a map of repeated message blocks/values
// RepeatedParameterMap is a map of repeated message blocks/values.
type RepeatedParameterMap struct {
Name string `hcl:"name,label"`
Template string `hcl:"template,label"`
Nested []NestedParameterMap `hcl:"message,block"`
Repeated []RepeatedParameterMap `hcl:"repeated,block"`
Properties hcl.Body `hcl:",remain"`
BaseParameterMap `hcl:",remain"`

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

// Resource intermediate specification
// Resource intermediate specification.
type Resource struct {
Name string `hcl:"name,label"`
DependsOn []string `hcl:"depends_on,optional"`
Expand All @@ -149,35 +153,25 @@ type Resource struct {
Error *ParameterMap `hcl:"error,block"`
}

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

// Function intermediate specification
type Function struct {
Name string `hcl:"name,label"`
Input *ParameterMap `hcl:"input,block"`
References []Resources `hcl:"resources,block"`
Resources []Resource `hcl:"resource,block"`
Output *ParameterMap `hcl:"output,block"`
}

// Call intermediate specification
// Call intermediate specification.
type Call struct {
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"`
Nested []NestedParameterMap `hcl:"message,block"`
Repeated []RepeatedParameterMap `hcl:"repeated,block"`
Properties hcl.Body `hcl:",remain"`
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"`
}

// Service specification
// Service specification.
type Service struct {
Package string `hcl:"package,label"`
Name string `hcl:"name,label"`
Expand All @@ -188,7 +182,7 @@ type Service struct {
Options *BlockOptions `hcl:"options,block"`
}

// ServiceSelector targets any service matchine the given service selector
// ServiceSelector targets any service matchine the given service selector.
type ServiceSelector struct {
Pattern string `hcl:"pattern,label"`
Host string `hcl:"host,optional"`
Expand All @@ -199,7 +193,7 @@ type ServiceSelector struct {
Options hcl.Body `hcl:",remain"`
}

// Services specification
// Services specification.
type Services struct {
Selectors []ServiceSelector `hcl:"select,block"`
}
Expand All @@ -212,27 +206,26 @@ type Method struct {
Options *BlockOptions `hcl:"options,block"`
}

// Proxy specification
// Proxy specification.
type Proxy struct {
Name string `hcl:"name,label"`
Input *ProxyInput `hcl:"input,block"`
OnError *OnError `hcl:"on_error,block"`
Before *Before `hcl:"before,block"`
Error *ParameterMap `hcl:"error,block"`
References []Resources `hcl:"resources,block"`
Resources []Resource `hcl:"resource,block"`
Conditions []Condition `hcl:"if,block"`
Forward ProxyForward `hcl:"forward,block"`
}

// ProxyInput represents the proxy input block
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"`
}

// ProxyInput represents the proxy input block.
type ProxyInput struct {
Options *BlockOptions `hcl:"options,block"`
Header []string `hcl:"header,optional"`
Params string `hcl:"params,optional"`
}

// ProxyForward specification
// ProxyForward specification.
type ProxyForward struct {
Service string `hcl:"service,label"`
Header *Header `hcl:"header,block"`
Expand Down
Loading