From d4c3a5df0aace0b59d7e091c42c21085421ef9b4 Mon Sep 17 00:00:00 2001 From: Alex Sch Date: Thu, 5 Nov 2020 16:26:10 +0200 Subject: [PATCH 1/3] refactor HCL provider --- pkg/providers/hcl/intermediate.go | 122 +++++----- pkg/providers/hcl/parameter_map.go | 200 ++++++++++++++++ pkg/providers/hcl/specs.go | 357 ++++------------------------- 3 files changed, 302 insertions(+), 377 deletions(-) create mode 100644 pkg/providers/hcl/parameter_map.go diff --git a/pkg/providers/hcl/intermediate.go b/pkg/providers/hcl/intermediate.go index a23a64e8..d229783a 100644 --- a/pkg/providers/hcl/intermediate.go +++ b/pkg/providers/hcl/intermediate.go @@ -1,8 +1,6 @@ package hcl -import ( - "github.com/hashicorp/hcl/v2" -) +import "github.com/hashicorp/hcl/v2" // Manifest intermediate specs type Manifest struct { @@ -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"` @@ -37,54 +35,62 @@ 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 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 basic 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"` } @@ -115,10 +121,9 @@ type BlockOptions struct { // 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 @@ -131,11 +136,10 @@ type InputRepeatedParameterMap struct { // 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 @@ -158,23 +162,22 @@ type OnError struct { // 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"` + Resources `hcl:",remain"` + + Name string `hcl:"name,label"` + Input *ParameterMap `hcl:"input,block"` + Output *ParameterMap `hcl:"output,block"` } // 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 @@ -214,15 +217,14 @@ type Method struct { // 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"` + 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 diff --git a/pkg/providers/hcl/parameter_map.go b/pkg/providers/hcl/parameter_map.go new file mode 100644 index 00000000..ea0668c1 --- /dev/null +++ b/pkg/providers/hcl/parameter_map.go @@ -0,0 +1,200 @@ +package hcl + +import ( + "github.com/jexia/semaphore/pkg/broker" + "github.com/jexia/semaphore/pkg/specs" + "github.com/jexia/semaphore/pkg/specs/labels" + "github.com/jexia/semaphore/pkg/specs/template" + "github.com/jexia/semaphore/pkg/specs/types" +) + +// ParseIntermediateNestedParameterMap parses the given intermediate parameter map to a spec parameter map +func ParseIntermediateNestedParameterMap(ctx *broker.Context, params NestedParameterMap, path string) (*specs.Property, error) { + message, err := parseBaseParameterMap(ctx, params.BaseParameterMap, path) + if err != nil { + return nil, err + } + + return &specs.Property{ + Name: params.Name, + Path: path, + Label: labels.Optional, + Template: specs.Template{ + Message: message, + }, + }, nil +} + +// ParseIntermediateRepeatedParameterMap parses the given intermediate repeated parameter map to a spec repeated parameter map +func ParseIntermediateRepeatedParameterMap(ctx *broker.Context, params RepeatedParameterMap, path string) (*specs.Property, error) { + message, err := parseBaseParameterMap(ctx, params.BaseParameterMap, path) + if err != nil { + return nil, err + } + + return &specs.Property{ + Name: params.Name, + Path: path, + Label: labels.Optional, + Template: specs.Template{ + Reference: template.ParsePropertyReference(params.Template), + Repeated: specs.Repeated{ + specs.Template{ + Message: message, + }, + }, + }, + }, nil +} + +// ParseIntermediateParameterMap parses the given intermediate parameter map to a spec parameter map +func ParseIntermediateParameterMap(ctx *broker.Context, params *ParameterMap) (*specs.ParameterMap, error) { + if params == nil { + return nil, nil + } + + result := specs.ParameterMap{ + Schema: params.Schema, + Options: make(specs.Options), + Property: &specs.Property{ + Label: labels.Optional, + Template: specs.Template{ + Message: make(specs.Message), + }, + }, + } + + if params.Header != nil { + header, err := ParseIntermediateHeader(ctx, params.Header) + if err != nil { + return nil, err + } + + result.Header = header + } + + if params.Options != nil { + result.Options = ParseIntermediateSpecOptions(params.Options.Body) + } + + var err error + result.Property.Message, err = parseBaseParameterMap(ctx, params.BaseParameterMap, "") + if err != nil { + return nil, err + } + + return &result, nil +} + +// ParseIntermediateCallParameterMap parses the given intermediate parameter map to a spec parameter map +func ParseIntermediateCallParameterMap(ctx *broker.Context, params *Call) (*specs.ParameterMap, error) { + if params == nil { + return nil, nil + } + + result := specs.ParameterMap{ + Options: make(specs.Options), + Property: &specs.Property{ + Label: labels.Optional, + }, + } + + if params.Parameters != nil { + params, err := ParseIntermediateParameters(ctx, params.Parameters.Body) + if err != nil { + return nil, err + } + + result.Params = params + } + + if params.Options != nil { + result.Options = ParseIntermediateSpecOptions(params.Options.Body) + } + + if params.Header != nil { + header, err := ParseIntermediateHeader(ctx, params.Header) + if err != nil { + return nil, err + } + + result.Header = header + } + + var err error + result.Property.Message, err = parseBaseParameterMap(ctx, params.BaseParameterMap, "") + if err != nil { + return nil, err + } + + return &result, nil +} + +// ParseIntermediateInputParameterMap parses the given input parameter map +func ParseIntermediateInputParameterMap(ctx *broker.Context, params *InputParameterMap) (*specs.ParameterMap, error) { + if params == nil { + return nil, nil + } + + result := &specs.ParameterMap{ + Schema: params.Schema, + Options: make(specs.Options), + Header: make(specs.Header, len(params.Header)), + } + + for _, key := range params.Header { + result.Header[key] = &specs.Property{ + Path: key, + Name: key, + Label: labels.Optional, + Template: specs.Template{ + Scalar: &specs.Scalar{ + Type: types.String, + }, + }, + } + } + + if params.Options != nil { + result.Options = ParseIntermediateSpecOptions(params.Options.Body) + } + + return result, nil +} + +func parseBaseParameterMap(ctx *broker.Context, params BaseParameterMap, path string) (specs.Message, error) { + var ( + message = make(specs.Message) + properties, _ = params.Properties.JustAttributes() + ) + + for _, attr := range properties { + val, _ := attr.Expr.Value(nil) + returns, err := ParseIntermediateProperty(ctx, path, attr, val) + if err != nil { + return nil, err + } + + message[attr.Name] = returns + } + + for _, nested := range params.Nested { + returns, err := ParseIntermediateNestedParameterMap(ctx, nested, template.JoinPath(path, nested.Name)) + if err != nil { + return nil, err + } + + message[nested.Name] = returns + } + + for _, repeated := range params.Repeated { + returns, err := ParseIntermediateRepeatedParameterMap(ctx, repeated, template.JoinPath(path, repeated.Name)) + if err != nil { + return nil, err + } + + message[repeated.Name] = returns + } + + return message, nil +} diff --git a/pkg/providers/hcl/specs.go b/pkg/providers/hcl/specs.go index 3c129bf5..f1f1e8a6 100644 --- a/pkg/providers/hcl/specs.go +++ b/pkg/providers/hcl/specs.go @@ -13,12 +13,6 @@ import ( "go.uber.org/zap" ) -/** - * TODO: this file has to be refactored to avoid code duplication and - * type casting. A lot of code duplication is aroundnested and repeated parameter - * maps. Interfaces have to be created for these types to allow to reuse implementations. - */ - // ParseFlows parses the given intermediate manifest to a flows manifest func ParseFlows(ctx *broker.Context, manifest Manifest) (errObject *specs.ParameterMap, _ specs.FlowListInterface, _ error) { logger.Info(ctx, "parsing intermediate manifest to flows manifest") @@ -71,13 +65,11 @@ func ParseEndpoints(ctx *broker.Context, manifest Manifest) (specs.EndpointList, func ParseIntermediateEndpoint(ctx *broker.Context, endpoint Endpoint) *specs.Endpoint { logger.Debug(ctx, "parsing intermediate endpoint to specs") - result := specs.Endpoint{ + return &specs.Endpoint{ Options: ParseIntermediateSpecOptions(endpoint.Options), Flow: endpoint.Flow, Listener: endpoint.Listener, } - - return &result } // ParseIntermediateFlow parses the given intermediate flow to a specs flow @@ -97,7 +89,6 @@ func ParseIntermediateFlow(ctx *broker.Context, flow Flow) (*specs.Flow, error) result := specs.Flow{ Name: flow.Name, Input: input, - Nodes: specs.NodeList{}, Output: output, OnError: &specs.OnError{}, } @@ -129,31 +120,9 @@ func ParseIntermediateFlow(ctx *broker.Context, flow Flow) (*specs.Flow, error) flow.Resources = append(flow.Resources, resources...) } - for _, references := range flow.References { - nodes, err := ParseIntermediateResources(ctx, before, references) - if err != nil { - return nil, err - } - - result.Nodes = append(result.Nodes, nodes...) - } - - for _, intermediate := range flow.Resources { - node, err := ParseIntermediateNode(ctx, before, intermediate) - if err != nil { - return nil, err - } - - result.Nodes = append(result.Nodes, node) - } - - for _, condition := range flow.Conditions { - nodes, err := ParseIntermediateCondition(ctx, before, condition) - if err != nil { - return nil, err - } - - result.Nodes = append(result.Nodes, nodes...) + result.Nodes, err = parseIntermediateCondition(ctx, flow.Condition, before) + if err != nil { + return nil, err } return &result, nil @@ -180,38 +149,6 @@ func DependsOn(dependency *specs.Node, nodes ...*specs.Node) { } } -// ParseIntermediateInputParameterMap parses the given input parameter map -func ParseIntermediateInputParameterMap(ctx *broker.Context, params *InputParameterMap) (*specs.ParameterMap, error) { - if params == nil { - return nil, nil - } - - result := &specs.ParameterMap{ - Schema: params.Schema, - Options: make(specs.Options), - Header: make(specs.Header, len(params.Header)), - } - - for _, key := range params.Header { - result.Header[key] = &specs.Property{ - Path: key, - Name: key, - Label: labels.Optional, - Template: specs.Template{ - Scalar: &specs.Scalar{ - Type: types.String, - }, - }, - } - } - - if params.Options != nil { - result.Options = ParseIntermediateSpecOptions(params.Options.Body) - } - - return result, nil -} - // ParseIntermediateProxy parses the given intermediate proxy to a specs proxy func ParseIntermediateProxy(ctx *broker.Context, proxy Proxy) (*specs.Proxy, error) { forward, err := ParseIntermediateProxyForward(ctx, proxy.Forward) @@ -278,31 +215,9 @@ func ParseIntermediateProxy(ctx *broker.Context, proxy Proxy) (*specs.Proxy, err proxy.Resources = append(proxy.Resources, resources...) } - for _, references := range proxy.References { - nodes, err := ParseIntermediateResources(ctx, before, references) - if err != nil { - return nil, err - } - - result.Nodes = append(result.Nodes, nodes...) - } - - for _, node := range proxy.Resources { - node, err := ParseIntermediateNode(ctx, before, node) - if err != nil { - return nil, err - } - - result.Nodes = append(result.Nodes, node) - } - - for _, condition := range proxy.Conditions { - nodes, err := ParseIntermediateCondition(ctx, before, condition) - if err != nil { - return nil, err - } - - result.Nodes = append(result.Nodes, nodes...) + result.Nodes, err = parseIntermediateCondition(ctx, proxy.Condition, before) + if err != nil { + return nil, err } return &result, nil @@ -327,160 +242,6 @@ func ParseIntermediateProxyForward(ctx *broker.Context, proxy ProxyForward) (*sp return &result, nil } -// ParseIntermediateParameterMap parses the given intermediate parameter map to a spec parameter map -func ParseIntermediateParameterMap(ctx *broker.Context, params *ParameterMap) (*specs.ParameterMap, error) { - if params == nil { - return nil, nil - } - - properties, _ := params.Properties.JustAttributes() - - result := specs.ParameterMap{ - Schema: params.Schema, - Options: make(specs.Options), - Property: &specs.Property{ - Label: labels.Optional, - Template: specs.Template{ - Message: make(specs.Message), - }, - }, - } - - if params.Header != nil { - header, err := ParseIntermediateHeader(ctx, params.Header) - if err != nil { - return nil, err - } - - result.Header = header - } - - if params.Options != nil { - result.Options = ParseIntermediateSpecOptions(params.Options.Body) - } - - for _, attr := range properties { - val, _ := attr.Expr.Value(nil) - results, err := ParseIntermediateProperty(ctx, "", attr, val) - if err != nil { - return nil, err - } - - result.Property.Message[attr.Name] = results - } - - for _, nested := range params.Nested { - results, err := ParseIntermediateNestedParameterMap(ctx, nested, nested.Name) - if err != nil { - return nil, err - } - - result.Property.Message[nested.Name] = results - } - - for _, repeated := range params.Repeated { - results, err := ParseIntermediateRepeatedParameterMap(ctx, repeated, repeated.Name) - if err != nil { - return nil, err - } - - result.Property.Message[repeated.Name] = results - } - - return &result, nil -} - -// ParseIntermediateNestedParameterMap parses the given intermediate parameter map to a spec parameter map -func ParseIntermediateNestedParameterMap(ctx *broker.Context, params NestedParameterMap, path string) (*specs.Property, error) { - properties, _ := params.Properties.JustAttributes() - result := specs.Property{ - Name: params.Name, - Path: path, - Label: labels.Optional, - Template: specs.Template{ - Message: make(specs.Message), - }, - } - - for _, nested := range params.Nested { - returns, err := ParseIntermediateNestedParameterMap(ctx, nested, template.JoinPath(path, nested.Name)) - if err != nil { - return nil, err - } - - result.Message[nested.Name] = returns - } - - for _, repeated := range params.Repeated { - returns, err := ParseIntermediateRepeatedParameterMap(ctx, repeated, template.JoinPath(path, repeated.Name)) - if err != nil { - return nil, err - } - - result.Message[repeated.Name] = returns - } - - for _, attr := range properties { - val, _ := attr.Expr.Value(nil) - returns, err := ParseIntermediateProperty(ctx, path, attr, val) - if err != nil { - return nil, err - } - - result.Message[attr.Name] = returns - } - - return &result, nil -} - -// ParseIntermediateRepeatedParameterMap parses the given intermediate repeated parameter map to a spec repeated parameter map -func ParseIntermediateRepeatedParameterMap(ctx *broker.Context, params RepeatedParameterMap, path string) (*specs.Property, error) { - properties, _ := params.Properties.JustAttributes() - msg := specs.Template{ - Message: make(specs.Message), - } - - for _, nested := range params.Nested { - returns, err := ParseIntermediateNestedParameterMap(ctx, nested, template.JoinPath(path, nested.Name)) - if err != nil { - return nil, err - } - - msg.Message[nested.Name] = returns - } - - for _, repeated := range params.Repeated { - returns, err := ParseIntermediateRepeatedParameterMap(ctx, repeated, template.JoinPath(path, repeated.Name)) - if err != nil { - return nil, err - } - - msg.Message[repeated.Name] = returns - } - - for _, attr := range properties { - val, _ := attr.Expr.Value(nil) - returns, err := ParseIntermediateProperty(ctx, path, attr, val) - if err != nil { - return nil, err - } - - msg.Message[attr.Name] = returns - } - - result := specs.Property{ - Name: params.Name, - Path: path, - Label: labels.Optional, - Template: specs.Template{ - Reference: template.ParsePropertyReference(params.Template), - Repeated: specs.Repeated{msg}, - }, - } - - return &result, nil -} - // ParseIntermediateHeader parses the given intermediate header to a spec header func ParseIntermediateHeader(ctx *broker.Context, header *Header) (specs.Header, error) { attributes, _ := header.Body.JustAttributes() @@ -618,77 +379,6 @@ func ParseIntermediateCall(ctx *broker.Context, call *Call) (*specs.Call, error) return &result, nil } -// ParseIntermediateCallParameterMap parses the given intermediate parameter map to a spec parameter map -func ParseIntermediateCallParameterMap(ctx *broker.Context, params *Call) (*specs.ParameterMap, error) { - if params == nil { - return nil, nil - } - - result := specs.ParameterMap{ - Options: make(specs.Options), - Property: &specs.Property{ - Label: labels.Optional, - Template: specs.Template{ - Message: make(specs.Message), - }, - }, - } - - if params.Parameters != nil { - params, err := ParseIntermediateParameters(ctx, params.Parameters.Body) - if err != nil { - return nil, err - } - - result.Params = params - } - - if params.Options != nil { - result.Options = ParseIntermediateSpecOptions(params.Options.Body) - } - - properties, _ := params.Properties.JustAttributes() - - if params.Header != nil { - header, err := ParseIntermediateHeader(ctx, params.Header) - if err != nil { - return nil, err - } - - result.Header = header - } - - for _, attr := range properties { - val, _ := attr.Expr.Value(nil) - results, err := ParseIntermediateProperty(ctx, "", attr, val) - if err != nil { - return nil, err - } - - result.Property.Message[results.Name] = results - } - - for _, nested := range params.Nested { - results, err := ParseIntermediateNestedParameterMap(ctx, nested, nested.Name) - if err != nil { - return nil, err - } - - result.Property.Message[results.Name] = results - } - - for _, repeated := range params.Repeated { - results, err := ParseIntermediateRepeatedParameterMap(ctx, repeated, repeated.Name) - if err != nil { - return nil, err - } - - result.Property.Message[repeated.Name] = results - } - - return &result, nil -} - // ParseIntermediateProperty parses the given intermediate property to a spec property func ParseIntermediateProperty(ctx *broker.Context, path string, property *hcl.Attribute, value cty.Value) (*specs.Property, error) { if property == nil { @@ -893,3 +583,36 @@ func ParseIntermediateOnError(ctx *broker.Context, onError *OnError) (*specs.OnE return result, nil } + +func parseIntermediateCondition(ctx *broker.Context, condition Condition, before specs.Dependencies) (specs.NodeList, error) { + var nodeList specs.NodeList + + for _, references := range condition.References { + nodes, err := ParseIntermediateResources(ctx, before, references) + if err != nil { + return nil, err + } + + nodeList = append(nodeList, nodes...) + } + + for _, intermediate := range condition.Resources { + node, err := ParseIntermediateNode(ctx, before, intermediate) + if err != nil { + return nil, err + } + + nodeList = append(nodeList, node) + } + + for _, condition := range condition.Conditions { + nodes, err := ParseIntermediateCondition(ctx, before, condition) + if err != nil { + return nil, err + } + + nodeList = append(nodeList, nodes...) + } + + return nodeList, nil +} From 297045eb80ee23fea08a60dbc02117b7038a717c Mon Sep 17 00:00:00 2001 From: Alex Sch Date: Thu, 5 Nov 2020 16:30:43 +0200 Subject: [PATCH 2/3] add dots --- pkg/providers/hcl/intermediate.go | 40 +++++++++++++++---------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/pkg/providers/hcl/intermediate.go b/pkg/providers/hcl/intermediate.go index d229783a..5c614491 100644 --- a/pkg/providers/hcl/intermediate.go +++ b/pkg/providers/hcl/intermediate.go @@ -51,7 +51,7 @@ type ResourceBlock struct { Resources []Resource `hcl:"resource,block"` } -// Before intermediate specification +// Before intermediate specification. type Before ResourceBlock // Condition represents a condition on which the scoped resources should be executed if true. @@ -62,7 +62,7 @@ type Condition struct { Conditions []Condition `hcl:"if,block"` } -// Flow intermediate specification +// Flow intermediate specification. type Flow struct { Condition `hcl:",remain"` @@ -74,7 +74,7 @@ type Flow struct { Output *ParameterMap `hcl:"output,block"` } -// BaseParameterMap contains a set of basic fields. +// BaseParameterMap contains a set of generic fields. type BaseParameterMap struct { Nested []NestedParameterMap `hcl:"message,block"` Repeated []RepeatedParameterMap `hcl:"repeated,block"` @@ -95,38 +95,38 @@ 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 { 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"` @@ -134,7 +134,7 @@ type InputRepeatedParameterMap struct { 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 { BaseParameterMap `hcl:",remain"` @@ -142,7 +142,7 @@ type RepeatedParameterMap struct { 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"` @@ -153,14 +153,14 @@ 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 +// Function intermediate specification. type Function struct { Resources `hcl:",remain"` @@ -169,7 +169,7 @@ type Function struct { Output *ParameterMap `hcl:"output,block"` } -// Call intermediate specification +// Call intermediate specification. type Call struct { BaseParameterMap `hcl:",remain"` @@ -180,7 +180,7 @@ type Call struct { Header *Header `hcl:"header,block"` } -// Service specification +// Service specification. type Service struct { Package string `hcl:"package,label"` Name string `hcl:"name,label"` @@ -191,7 +191,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"` @@ -202,7 +202,7 @@ type ServiceSelector struct { Options hcl.Body `hcl:",remain"` } -// Services specification +// Services specification. type Services struct { Selectors []ServiceSelector `hcl:"select,block"` } @@ -215,7 +215,7 @@ type Method struct { Options *BlockOptions `hcl:"options,block"` } -// Proxy specification +// Proxy specification. type Proxy struct { Condition `hcl:",remain"` @@ -227,14 +227,14 @@ type Proxy struct { Forward ProxyForward `hcl:"forward,block"` } -// ProxyInput represents the proxy input 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"` From c4dc40ecca9173e049c84a729ba148f4855f1483 Mon Sep 17 00:00:00 2001 From: Alex Sch Date: Fri, 6 Nov 2020 09:21:46 +0200 Subject: [PATCH 3/3] remove unused struct --- pkg/providers/hcl/intermediate.go | 9 --------- 1 file changed, 9 deletions(-) diff --git a/pkg/providers/hcl/intermediate.go b/pkg/providers/hcl/intermediate.go index 5c614491..6a42ad87 100644 --- a/pkg/providers/hcl/intermediate.go +++ b/pkg/providers/hcl/intermediate.go @@ -160,15 +160,6 @@ type OnError struct { Body hcl.Body `hcl:",remain"` } -// Function intermediate specification. -type Function struct { - Resources `hcl:",remain"` - - Name string `hcl:"name,label"` - Input *ParameterMap `hcl:"input,block"` - Output *ParameterMap `hcl:"output,block"` -} - // Call intermediate specification. type Call struct { BaseParameterMap `hcl:",remain"`