mirror of
https://github.com/hashicorp/packer.git
synced 2026-06-09 08:42:33 -04:00
Merge pull request #11784 from hashicorp/fix_generated_code
Run make generate
This commit is contained in:
commit
66d4c2dc44
6 changed files with 25 additions and 23 deletions
|
|
@ -21,10 +21,10 @@ import (
|
|||
|
||||
type Config struct {
|
||||
common.PackerConfig `mapstructure:",squash"`
|
||||
// The URL to request data from. This URL must respond with a `200 OK` response and a `text/*` or `application/json` Content-Type
|
||||
// The URL to request data from. This URL must respond with a `200 OK` response and a `text/*` or `application/json` Content-Type.
|
||||
Url string `mapstructure:"url" required:"true"`
|
||||
// A map of strings representing additional HTTP headers to include in the request.
|
||||
Request_headers map[string]string `mapstructure:"request_headers" required:"false"`
|
||||
RequestHeaders map[string]string `mapstructure:"request_headers" required:"false"`
|
||||
}
|
||||
|
||||
type Datasource struct {
|
||||
|
|
@ -32,13 +32,13 @@ type Datasource struct {
|
|||
}
|
||||
|
||||
type DatasourceOutput struct {
|
||||
// The URL the data was requested from.
|
||||
Url string `mapstructure:"url"`
|
||||
// The URL the data was requested from.
|
||||
Url string `mapstructure:"url"`
|
||||
// The raw body of the HTTP response.
|
||||
Response_body string `mapstructure:"body"`
|
||||
// A map of strings representing the response HTTP headers.
|
||||
// Duplicate headers are contatenated with , according to [RFC2616](https://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2)
|
||||
Response_headers map[string]string `mapstructure:"request_headers"`
|
||||
ResponseBody string `mapstructure:"body"`
|
||||
// A map of strings representing the response HTTP headers.
|
||||
// Duplicate headers are concatenated with, according to [RFC2616](https://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2).
|
||||
ResponseHeaders map[string]string `mapstructure:"request_headers"`
|
||||
}
|
||||
|
||||
func (d *Datasource) ConfigSpec() hcldec.ObjectSpec {
|
||||
|
|
@ -99,7 +99,7 @@ func isContentTypeText(contentType string) bool {
|
|||
// https://github.com/hashicorp/terraform-provider-http/blob/main/internal/provider/data_source.go
|
||||
func (d *Datasource) Execute() (cty.Value, error) {
|
||||
ctx := context.TODO()
|
||||
url, headers := d.config.Url, d.config.Request_headers
|
||||
url, headers := d.config.Url, d.config.RequestHeaders
|
||||
client := &http.Client{}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
||||
|
|
@ -149,9 +149,9 @@ func (d *Datasource) Execute() (cty.Value, error) {
|
|||
}
|
||||
|
||||
output := DatasourceOutput{
|
||||
Url: d.config.Url,
|
||||
Response_headers: responseHeaders,
|
||||
Response_body: string(bytes),
|
||||
Url: d.config.Url,
|
||||
ResponseHeaders: responseHeaders,
|
||||
ResponseBody: string(bytes),
|
||||
}
|
||||
return hcl2helper.HCL2ValueFromConfig(output, d.OutputSpec()), nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ type FlatConfig struct {
|
|||
PackerUserVars map[string]string `mapstructure:"packer_user_variables" cty:"packer_user_variables" hcl:"packer_user_variables"`
|
||||
PackerSensitiveVars []string `mapstructure:"packer_sensitive_variables" cty:"packer_sensitive_variables" hcl:"packer_sensitive_variables"`
|
||||
Url *string `mapstructure:"url" required:"true" cty:"url" hcl:"url"`
|
||||
Request_headers map[string]string `mapstructure:"request_headers" required:"false" cty:"request_headers" hcl:"request_headers"`
|
||||
RequestHeaders map[string]string `mapstructure:"request_headers" required:"false" cty:"request_headers" hcl:"request_headers"`
|
||||
}
|
||||
|
||||
// FlatMapstructure returns a new FlatConfig.
|
||||
|
|
@ -51,9 +51,9 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec {
|
|||
// FlatDatasourceOutput is an auto-generated flat version of DatasourceOutput.
|
||||
// Where the contents of a field with a `mapstructure:,squash` tag are bubbled up.
|
||||
type FlatDatasourceOutput struct {
|
||||
Url *string `mapstructure:"url" cty:"url" hcl:"url"`
|
||||
Response_body *string `mapstructure:"body" cty:"body" hcl:"body"`
|
||||
Response_headers map[string]string `mapstructure:"request_headers" cty:"request_headers" hcl:"request_headers"`
|
||||
Url *string `mapstructure:"url" cty:"url" hcl:"url"`
|
||||
ResponseBody *string `mapstructure:"body" cty:"body" hcl:"body"`
|
||||
ResponseHeaders map[string]string `mapstructure:"request_headers" cty:"request_headers" hcl:"request_headers"`
|
||||
}
|
||||
|
||||
// FlatMapstructure returns a new FlatDatasourceOutput.
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
---
|
||||
description: |
|
||||
The http Data Source retrieves information from an http endpoint to be used
|
||||
The HTTP Data Source retrieves information from an http endpoint to be used
|
||||
during Packer builds
|
||||
page_title: Http - Data Sources
|
||||
---
|
||||
|
|
@ -19,7 +19,7 @@ The `http` data source makes an HTTP GET request to the given URL and exports in
|
|||
|
||||
## Basic Example
|
||||
|
||||
```hcl
|
||||
```hcl
|
||||
data "http" "example" {
|
||||
url = "https://checkpoint-api.hashicorp.com/v1/check/terraform"
|
||||
|
||||
|
|
@ -28,6 +28,7 @@ data "http" "example" {
|
|||
Accept = "application/json"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Configuration Reference
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
<!-- Code generated from the comments of the Config struct in datasource/http/data.go; DO NOT EDIT MANUALLY -->
|
||||
|
||||
- `request_headers` (map[string]string) - Request headers for call
|
||||
- `request_headers` (map[string]string) - A map of strings representing additional HTTP headers to include in the request.
|
||||
|
||||
<!-- End of code generated from the comments of the Config struct in datasource/http/data.go; -->
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
<!-- Code generated from the comments of the Config struct in datasource/http/data.go; DO NOT EDIT MANUALLY -->
|
||||
|
||||
- `url` (string) - Url where should be getting things from
|
||||
- `url` (string) - The URL to request data from. This URL must respond with a `200 OK` response and a `text/*` or `application/json` Content-Type.
|
||||
|
||||
<!-- End of code generated from the comments of the Config struct in datasource/http/data.go; -->
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
<!-- Code generated from the comments of the DatasourceOutput struct in datasource/http/data.go; DO NOT EDIT MANUALLY -->
|
||||
|
||||
- `url` (string) - Url
|
||||
- `url` (string) - The URL the data was requested from.
|
||||
|
||||
- `body` (string) - Response _ body
|
||||
- `body` (string) - The raw body of the HTTP response.
|
||||
|
||||
- `request_headers` (map[string]string) - Response _ headers
|
||||
- `request_headers` (map[string]string) - A map of strings representing the response HTTP headers.
|
||||
Duplicate headers are concatenated with, according to [RFC2616](https://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2).
|
||||
|
||||
<!-- End of code generated from the comments of the DatasourceOutput struct in datasource/http/data.go; -->
|
||||
|
|
|
|||
Loading…
Reference in a new issue