github.com/avenga/couper@v1.12.2/config/meta/attributes.go (about)

     1  package meta
     2  
     3  import (
     4  	"github.com/hashicorp/hcl/v2"
     5  	"github.com/hashicorp/hcl/v2/gohcl"
     6  	"github.com/zclconf/go-cty/cty"
     7  )
     8  
     9  var RequestHeadersAttributesSchema, _ = gohcl.ImpliedBodySchema(&RequestHeadersAttributes{})
    10  var ResponseHeadersAttributesSchema, _ = gohcl.ImpliedBodySchema(&ResponseHeadersAttributes{})
    11  var FormParamsAttributesSchema, _ = gohcl.ImpliedBodySchema(&FormParamsAttributes{})
    12  var QueryParamsAttributesSchema, _ = gohcl.ImpliedBodySchema(&QueryParamsAttributes{})
    13  var LogFieldsAttributeSchema, _ = gohcl.ImpliedBodySchema(&LogFieldsAttribute{})
    14  
    15  var ModifierAttributesSchema = MergeSchemas(
    16  	RequestHeadersAttributesSchema,
    17  	ResponseHeadersAttributesSchema,
    18  	FormParamsAttributesSchema,
    19  	QueryParamsAttributesSchema,
    20  )
    21  
    22  // Attributes are commonly shared attributes which gets evaluated during runtime.
    23  
    24  type FormParamsAttributes struct {
    25  	// Form Params
    26  	AddFormParams map[string]cty.Value `hcl:"add_form_params,optional" docs:"Key/value pairs to add form parameters to the upstream request body."`
    27  	DelFormParams map[string]cty.Value `hcl:"remove_form_params,optional" docs:"List of names to remove form parameters from the upstream request body."`
    28  	SetFormParams map[string]cty.Value `hcl:"set_form_params,optional" docs:"Key/value pairs to set query parameters in the upstream request URL."`
    29  }
    30  
    31  type QueryParamsAttributes struct {
    32  	// Query Params
    33  	AddQueryParams map[string]cty.Value `hcl:"add_query_params,optional" docs:"Key/value pairs to add query parameters to the upstream request URL."`
    34  	DelQueryParams []string             `hcl:"remove_query_params,optional" docs:"List of names to remove query parameters from the upstream request URL."`
    35  	SetQueryParams map[string]cty.Value `hcl:"set_query_params,optional" docs:"Key/value pairs to set query parameters in the upstream request URL."`
    36  }
    37  
    38  type RequestHeadersAttributes struct {
    39  	// Request Header Modifiers
    40  	AddRequestHeaders map[string]string `hcl:"add_request_headers,optional" docs:"Key/value pairs to add as request headers in the upstream request."`
    41  	DelRequestHeaders []string          `hcl:"remove_request_headers,optional" docs:"List of names to remove headers from the upstream request."`
    42  	SetRequestHeaders map[string]string `hcl:"set_request_headers,optional" docs:"Key/value pairs to set as request headers in the upstream request."`
    43  }
    44  
    45  type ResponseHeadersAttributes struct {
    46  	// Response Header Modifiers
    47  	AddResponseHeaders map[string]string `hcl:"add_response_headers,optional" docs:"Key/value pairs to add as response headers in the client response."`
    48  	DelResponseHeaders []string          `hcl:"remove_response_headers,optional" docs:"List of names to remove headers from the client response."`
    49  	SetResponseHeaders map[string]string `hcl:"set_response_headers,optional" docs:"Key/value pairs to set as response headers in the client response."`
    50  }
    51  
    52  type LogFieldsAttribute struct {
    53  	LogFields map[string]hcl.Expression `hcl:"custom_log_fields,optional" docs:"Log fields for [custom logging](/observation/logging#custom-logging). Inherited by nested blocks."`
    54  }
    55  
    56  func MergeSchemas(schema *hcl.BodySchema, schemas ...*hcl.BodySchema) *hcl.BodySchema {
    57  	for _, s := range schemas {
    58  		schema.Attributes = append(schema.Attributes, s.Attributes...)
    59  		schema.Blocks = append(schema.Blocks, s.Blocks...)
    60  	}
    61  	return schema
    62  }