-
Notifications
You must be signed in to change notification settings - Fork 14
/
request.go
66 lines (54 loc) · 2.91 KB
/
request.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package config
import (
"github.com/hashicorp/hcl/v2"
"github.com/hashicorp/hcl/v2/gohcl"
"github.com/hashicorp/hcl/v2/hclsyntax"
"github.com/zclconf/go-cty/cty"
)
var (
_ BackendReference = &Request{}
_ Body = &Request{}
_ Inline = &Request{}
)
// Request represents the <Request> object.
type Request struct {
BackendName string `hcl:"backend,optional" docs:"References a [backend](/configuration/block/backend) in [definitions](/configuration/block/definitions) for the request. Mutually exclusive with {backend} block."`
Name string `hcl:"name,label,optional"`
Remain hcl.Body `hcl:",remain"`
// Internally used
Backend *hclsyntax.Body
}
// Requests represents a list of <Requests> objects.
type Requests []*Request
// Reference implements the <BackendReference> interface.
func (r Request) Reference() string {
return r.BackendName
}
// HCLBody implements the <Body> interface.
func (r Request) HCLBody() *hclsyntax.Body {
return r.Remain.(*hclsyntax.Body)
}
// Inline implements the <Inline> interface.
func (r Request) Inline() interface{} {
type Inline struct {
Backend *Backend `hcl:"backend,block" docs:"Configures a [backend](/configuration/block/backend) for the request (zero or one). Mutually exclusive with {backend} attribute."`
Body string `hcl:"body,optional" docs:"Plain text request body, implicitly sets {Content-Type: text/plain} header field."`
ExpectedStatus []int `hcl:"expected_status,optional" docs:"If defined, the response status code will be verified against this list of codes. If the status code is not included in this list an [{unexpected_status} error](../error-handling#endpoint-error-types) will be thrown which can be handled with an [{error_handler}](../error-handling#endpoint-related-error_handler)."`
FormBody string `hcl:"form_body,optional" docs:"Form request body, implicitly sets {Content-Type: application/x-www-form-urlencoded} header field."`
Headers map[string]string `hcl:"headers,optional" docs:"Request HTTP header fields."`
JSONBody string `hcl:"json_body,optional" docs:"JSON request body, implicitly sets {Content-Type: application/json} header field."`
Method string `hcl:"method,optional" docs:"The request method." default:"GET"`
QueryParams map[string]cty.Value `hcl:"query_params,optional" docs:"Key/value pairs to set query parameters for this request."`
URL string `hcl:"url,optional" docs:"URL of the resource to request. May be relative to an origin specified in a referenced or nested {backend} block."`
}
return &Inline{}
}
// Schema implements the <Inline> interface.
func (r Request) Schema(inline bool) *hcl.BodySchema {
if !inline {
schema, _ := gohcl.ImpliedBodySchema(r)
return schema
}
schema, _ := gohcl.ImpliedBodySchema(r.Inline())
return schema
}