From 1f5f16e91f22dae6b60dd43e3b77a26b133a3435 Mon Sep 17 00:00:00 2001 From: teddylear Date: Sat, 12 Mar 2022 20:40:06 -0500 Subject: [PATCH 01/11] feat: add http datasource --- command/plugin.go | 2 + datasource/http/data.go | 150 ++++++++++++++++++ datasource/http/data.hcl2spec.go | 76 +++++++++ datasource/http/data_acc_test.go | 109 +++++++++++++ datasource/http/test-fixtures/404_url.pkr.hcl | 24 +++ datasource/http/test-fixtures/basic.pkr.hcl | 25 +++ .../http/test-fixtures/empty_url.pkr.hcl | 23 +++ .../datasource/http/Config-not-required.mdx | 5 + .../datasource/http/Config-required.mdx | 5 + .../partials/datasource/http/Config.mdx | 5 + .../datasource/http/DatasourceOutput.mdx | 9 ++ 11 files changed, 433 insertions(+) create mode 100644 datasource/http/data.go create mode 100644 datasource/http/data.hcl2spec.go create mode 100644 datasource/http/data_acc_test.go create mode 100644 datasource/http/test-fixtures/404_url.pkr.hcl create mode 100644 datasource/http/test-fixtures/basic.pkr.hcl create mode 100644 datasource/http/test-fixtures/empty_url.pkr.hcl create mode 100644 website/content/partials/datasource/http/Config-not-required.mdx create mode 100644 website/content/partials/datasource/http/Config-required.mdx create mode 100644 website/content/partials/datasource/http/Config.mdx create mode 100644 website/content/partials/datasource/http/DatasourceOutput.mdx diff --git a/command/plugin.go b/command/plugin.go index 8f8b0903df0..50699654918 100644 --- a/command/plugin.go +++ b/command/plugin.go @@ -17,6 +17,7 @@ import ( nullbuilder "github.com/hashicorp/packer/builder/null" hcppackerimagedatasource "github.com/hashicorp/packer/datasource/hcp-packer-image" hcppackeriterationdatasource "github.com/hashicorp/packer/datasource/hcp-packer-iteration" + httpdatasource "github.com/hashicorp/packer/datasource/http" nulldatasource "github.com/hashicorp/packer/datasource/null" artificepostprocessor "github.com/hashicorp/packer/post-processor/artifice" checksumpostprocessor "github.com/hashicorp/packer/post-processor/checksum" @@ -64,6 +65,7 @@ var PostProcessors = map[string]packersdk.PostProcessor{ var Datasources = map[string]packersdk.Datasource{ "hcp-packer-image": new(hcppackerimagedatasource.Datasource), "hcp-packer-iteration": new(hcppackeriterationdatasource.Datasource), + "http": new(httpdatasource.Datasource), "null": new(nulldatasource.Datasource), } diff --git a/datasource/http/data.go b/datasource/http/data.go new file mode 100644 index 00000000000..a20e8be011d --- /dev/null +++ b/datasource/http/data.go @@ -0,0 +1,150 @@ +//go:generate packer-sdc struct-markdown +//go:generate packer-sdc mapstructure-to-hcl2 -type DatasourceOutput,Config +package http + +import ( + "context" + "fmt" + "io/ioutil" + "mime" + "net/http" + "regexp" + "strings" + + "github.com/hashicorp/hcl/v2/hcldec" + "github.com/hashicorp/packer-plugin-sdk/common" + "github.com/hashicorp/packer-plugin-sdk/hcl2helper" + packersdk "github.com/hashicorp/packer-plugin-sdk/packer" + "github.com/hashicorp/packer-plugin-sdk/template/config" + "github.com/zclconf/go-cty/cty" +) + +type Config struct { + common.PackerConfig `mapstructure:",squash"` + // Url where should be getting things from + Url string `mapstructure:"url" required:"true"` + // Request headers for call + Request_headers map[string]string `mapstructure:"request_headers" required:"false"` +} + +type Datasource struct { + config Config +} + +type DatasourceOutput struct { + Url string `mapstructure:"url"` + Response_body string `mapstructure:"body"` + Response_headers map[string]string `mapstructure:"request_headers"` +} + +func (d *Datasource) ConfigSpec() hcldec.ObjectSpec { + return d.config.FlatMapstructure().HCL2Spec() +} + +func (d *Datasource) Configure(raws ...interface{}) error { + err := config.Decode(&d.config, nil, raws...) + if err != nil { + return err + } + + var errs *packersdk.MultiError + + if d.config.Url == "" { + errs = packersdk.MultiErrorAppend( + errs, + fmt.Errorf("the `url` must be specified")) + } + + if errs != nil && len(errs.Errors) > 0 { + return errs + } + return nil +} + +func (d *Datasource) OutputSpec() hcldec.ObjectSpec { + return (&DatasourceOutput{}).FlatMapstructure().HCL2Spec() +} + +// This is to prevent potential issues w/ binary files +// and generally unprintable characters +// See https://github.com/hashicorp/terraform/pull/3858#issuecomment-156856738 +func isContentTypeText(contentType string) bool { + + parsedType, params, err := mime.ParseMediaType(contentType) + if err != nil { + return false + } + + allowedContentTypes := []*regexp.Regexp{ + regexp.MustCompile("^text/.+"), + regexp.MustCompile("^application/json$"), + regexp.MustCompile("^application/samlmetadata\\+xml"), + } + + for _, r := range allowedContentTypes { + if r.MatchString(parsedType) { + charset := strings.ToLower(params["charset"]) + return charset == "" || charset == "utf-8" || charset == "us-ascii" + } + } + + return false +} + +// Most of this code comes from http terraform provider data source +// 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 + client := &http.Client{} + + req, err := http.NewRequestWithContext(ctx, "GET", url, nil) + // TODO: How to make a test case for this? + if err != nil { + return cty.NullVal(cty.EmptyObject), err + } + + for name, value := range headers { + req.Header.Set(name, value) + } + + resp, err := client.Do(req) + // TODO: How to make test case for this + if err != nil { + return cty.NullVal(cty.EmptyObject), err + } + + defer resp.Body.Close() + + if resp.StatusCode != 200 { + return cty.NullVal(cty.EmptyObject), err + } + + contentType := resp.Header.Get("Content-Type") + if contentType == "" || isContentTypeText(contentType) == false { + fmt.Println(fmt.Sprintf( + "Content-Type is not recognized as a text type, got %q", + contentType)) + fmt.Println("If the content is binary data, Packer may not properly handle the contents of the response.") + } + + bytes, err := ioutil.ReadAll(resp.Body) + // TODO: How to make test case for this? + if err != nil { + return cty.NullVal(cty.EmptyObject), err + } + + responseHeaders := make(map[string]string) + for k, v := range resp.Header { + // Concatenate according to RFC2616 + // cf. https://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2 + responseHeaders[k] = strings.Join(v, ", ") + } + + output := DatasourceOutput{ + Url: d.config.Url, + Response_headers: responseHeaders, + Response_body: string(bytes), + } + return hcl2helper.HCL2ValueFromConfig(output, d.OutputSpec()), nil +} diff --git a/datasource/http/data.hcl2spec.go b/datasource/http/data.hcl2spec.go new file mode 100644 index 00000000000..07d3b6b81dd --- /dev/null +++ b/datasource/http/data.hcl2spec.go @@ -0,0 +1,76 @@ +// Code generated by "packer-sdc mapstructure-to-hcl2"; DO NOT EDIT. + +package http + +import ( + "github.com/hashicorp/hcl/v2/hcldec" + "github.com/zclconf/go-cty/cty" +) + +// FlatConfig is an auto-generated flat version of Config. +// Where the contents of a field with a `mapstructure:,squash` tag are bubbled up. +type FlatConfig struct { + PackerBuildName *string `mapstructure:"packer_build_name" cty:"packer_build_name" hcl:"packer_build_name"` + PackerBuilderType *string `mapstructure:"packer_builder_type" cty:"packer_builder_type" hcl:"packer_builder_type"` + PackerCoreVersion *string `mapstructure:"packer_core_version" cty:"packer_core_version" hcl:"packer_core_version"` + PackerDebug *bool `mapstructure:"packer_debug" cty:"packer_debug" hcl:"packer_debug"` + PackerForce *bool `mapstructure:"packer_force" cty:"packer_force" hcl:"packer_force"` + PackerOnError *string `mapstructure:"packer_on_error" cty:"packer_on_error" hcl:"packer_on_error"` + 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"` +} + +// FlatMapstructure returns a new FlatConfig. +// FlatConfig is an auto-generated flat version of Config. +// Where the contents a fields with a `mapstructure:,squash` tag are bubbled up. +func (*Config) FlatMapstructure() interface{ HCL2Spec() map[string]hcldec.Spec } { + return new(FlatConfig) +} + +// HCL2Spec returns the hcl spec of a Config. +// This spec is used by HCL to read the fields of Config. +// The decoded values from this spec will then be applied to a FlatConfig. +func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { + s := map[string]hcldec.Spec{ + "packer_build_name": &hcldec.AttrSpec{Name: "packer_build_name", Type: cty.String, Required: false}, + "packer_builder_type": &hcldec.AttrSpec{Name: "packer_builder_type", Type: cty.String, Required: false}, + "packer_core_version": &hcldec.AttrSpec{Name: "packer_core_version", Type: cty.String, Required: false}, + "packer_debug": &hcldec.AttrSpec{Name: "packer_debug", Type: cty.Bool, Required: false}, + "packer_force": &hcldec.AttrSpec{Name: "packer_force", Type: cty.Bool, Required: false}, + "packer_on_error": &hcldec.AttrSpec{Name: "packer_on_error", Type: cty.String, Required: false}, + "packer_user_variables": &hcldec.AttrSpec{Name: "packer_user_variables", Type: cty.Map(cty.String), Required: false}, + "packer_sensitive_variables": &hcldec.AttrSpec{Name: "packer_sensitive_variables", Type: cty.List(cty.String), Required: false}, + "url": &hcldec.AttrSpec{Name: "url", Type: cty.String, Required: false}, + "request_headers": &hcldec.AttrSpec{Name: "request_headers", Type: cty.Map(cty.String), Required: false}, + } + return s +} + +// 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"` +} + +// FlatMapstructure returns a new FlatDatasourceOutput. +// FlatDatasourceOutput is an auto-generated flat version of DatasourceOutput. +// Where the contents a fields with a `mapstructure:,squash` tag are bubbled up. +func (*DatasourceOutput) FlatMapstructure() interface{ HCL2Spec() map[string]hcldec.Spec } { + return new(FlatDatasourceOutput) +} + +// HCL2Spec returns the hcl spec of a DatasourceOutput. +// This spec is used by HCL to read the fields of DatasourceOutput. +// The decoded values from this spec will then be applied to a FlatDatasourceOutput. +func (*FlatDatasourceOutput) HCL2Spec() map[string]hcldec.Spec { + s := map[string]hcldec.Spec{ + "url": &hcldec.AttrSpec{Name: "url", Type: cty.String, Required: false}, + "body": &hcldec.AttrSpec{Name: "body", Type: cty.String, Required: false}, + "request_headers": &hcldec.AttrSpec{Name: "request_headers", Type: cty.Map(cty.String), Required: false}, + } + return s +} diff --git a/datasource/http/data_acc_test.go b/datasource/http/data_acc_test.go new file mode 100644 index 00000000000..b6b1f83ac27 --- /dev/null +++ b/datasource/http/data_acc_test.go @@ -0,0 +1,109 @@ +package http + +import ( + _ "embed" + "fmt" + "io/ioutil" + "os" + "os/exec" + "regexp" + "testing" + + "github.com/hashicorp/packer-plugin-sdk/acctest" +) + +//go:embed test-fixtures/basic.pkr.hcl +var testDatasourceBasic string + +//go:embed test-fixtures/empty_url.pkr.hcl +var testDatasourceEmptyUrl string + +//go:embed test-fixtures/404_url.pkr.hcl +var testDatasource404Url string + +func TestHttpDataSource(t *testing.T) { + tests := []struct { + Name string + Path string + Error bool + Outputs map[string]string + }{ + { + Name: "basic_test", + Path: testDatasourceBasic, + Error: false, + Outputs: map[string]string{ + "url": "url is https://www.packer.io/", + // Check that body is not empty + "body": "body is true", + }, + }, + { + Name: "url_is_empty", + Path: testDatasourceEmptyUrl, + Error: true, + Outputs: map[string]string{ + "error": "the `url` must be specified", + }, + }, + { + Name: "404_url", + Path: testDatasource404Url, + Error: true, + }, + } + for _, tt := range tests { + t.Run(tt.Name, func(t *testing.T) { + testCase := &acctest.PluginTestCase{ + Name: tt.Name, + Setup: func() error { + return nil + }, + Teardown: func() error { + return nil + }, + Template: tt.Path, + Type: "http", + Check: func(buildCommand *exec.Cmd, logfile string) error { + if buildCommand.ProcessState != nil { + if buildCommand.ProcessState.ExitCode() != 0 && !tt.Error { + return fmt.Errorf("Bad exit code. Logfile: %s", logfile) + } + if tt.Error && buildCommand.ProcessState.ExitCode() == 0 { + return fmt.Errorf("Expected Bad exit code.") + } + } + + if tt.Outputs != nil { + logs, err := os.Open(logfile) + if err != nil { + return fmt.Errorf("Unable find %s", logfile) + } + defer logs.Close() + + logsBytes, err := ioutil.ReadAll(logs) + if err != nil { + return fmt.Errorf("Unable to read %s", logfile) + } + logsString := string(logsBytes) + + for key, val := range tt.Outputs { + if matched, _ := regexp.MatchString(val+".*", logsString); !matched { + t.Fatalf( + "logs doesn't contain expected log %v with value %v in %q", + key, + val, + logsString) + } + } + + } + + return nil + }, + } + acctest.TestPlugin(t, testCase) + }) + } + +} diff --git a/datasource/http/test-fixtures/404_url.pkr.hcl b/datasource/http/test-fixtures/404_url.pkr.hcl new file mode 100644 index 00000000000..398af371d30 --- /dev/null +++ b/datasource/http/test-fixtures/404_url.pkr.hcl @@ -0,0 +1,24 @@ + +source "null" "example" { + communicator = "none" +} + +data "http" "basic" { + url = "https://www.packer.io/thisWillFail" +} + +locals { + url = "${data.http.basic.url}" +} + +build { + name = "mybuild" + sources = [ + "source.null.example" + ] + provisioner "shell-local" { + inline = [ + "echo data is ${local.url}", + ] + } +} diff --git a/datasource/http/test-fixtures/basic.pkr.hcl b/datasource/http/test-fixtures/basic.pkr.hcl new file mode 100644 index 00000000000..1e7e4a46db3 --- /dev/null +++ b/datasource/http/test-fixtures/basic.pkr.hcl @@ -0,0 +1,25 @@ +source "null" "example" { + communicator = "none" +} + +data "http" "basic" { + url = "https://www.packer.io/" +} + +locals { + url = "${data.http.basic.url}" + body = "${data.http.basic.body}" != "" +} + +build { + name = "mybuild" + sources = [ + "source.null.example" + ] + provisioner "shell-local" { + inline = [ + "echo url is ${local.url}", + "echo body is ${local.body}" + ] + } +} diff --git a/datasource/http/test-fixtures/empty_url.pkr.hcl b/datasource/http/test-fixtures/empty_url.pkr.hcl new file mode 100644 index 00000000000..7810218beda --- /dev/null +++ b/datasource/http/test-fixtures/empty_url.pkr.hcl @@ -0,0 +1,23 @@ +source "null" "example" { + communicator = "none" +} + +data "http" "basic" { + url = "" +} + +locals { + url = "${data.http.basic.url}" +} + +build { + name = "mybuild" + sources = [ + "source.null.example" + ] + provisioner "shell-local" { + inline = [ + "echo data is ${local.url}", + ] + } +} diff --git a/website/content/partials/datasource/http/Config-not-required.mdx b/website/content/partials/datasource/http/Config-not-required.mdx new file mode 100644 index 00000000000..1344f2aae9c --- /dev/null +++ b/website/content/partials/datasource/http/Config-not-required.mdx @@ -0,0 +1,5 @@ + + +- `request_headers` (map[string]string) - Request headers for call + + diff --git a/website/content/partials/datasource/http/Config-required.mdx b/website/content/partials/datasource/http/Config-required.mdx new file mode 100644 index 00000000000..f40d0df69dc --- /dev/null +++ b/website/content/partials/datasource/http/Config-required.mdx @@ -0,0 +1,5 @@ + + +- `url` (string) - Url where should be getting things from + + diff --git a/website/content/partials/datasource/http/Config.mdx b/website/content/partials/datasource/http/Config.mdx new file mode 100644 index 00000000000..ad1fb4f1bb0 --- /dev/null +++ b/website/content/partials/datasource/http/Config.mdx @@ -0,0 +1,5 @@ + + +TODO: Update comments + + diff --git a/website/content/partials/datasource/http/DatasourceOutput.mdx b/website/content/partials/datasource/http/DatasourceOutput.mdx new file mode 100644 index 00000000000..bdafc1249f8 --- /dev/null +++ b/website/content/partials/datasource/http/DatasourceOutput.mdx @@ -0,0 +1,9 @@ + + +- `url` (string) - Url + +- `body` (string) - Response _ body + +- `request_headers` (map[string]string) - Response _ headers + + From 9dfa1c0e7691d1f9d6b2f1d8b66084d9797ae280 Mon Sep 17 00:00:00 2001 From: teddylear Date: Fri, 6 May 2022 20:04:30 -0400 Subject: [PATCH 02/11] Update datasource/http/data.go Co-authored-by: Sylvia Moss --- datasource/http/data.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datasource/http/data.go b/datasource/http/data.go index a20e8be011d..253368ebe8a 100644 --- a/datasource/http/data.go +++ b/datasource/http/data.go @@ -117,7 +117,7 @@ func (d *Datasource) Execute() (cty.Value, error) { defer resp.Body.Close() if resp.StatusCode != 200 { - return cty.NullVal(cty.EmptyObject), err + return cty.NullVal(cty.EmptyObject), fmt.Errorf("HTTP request error. Response code: %d", resp.StatusCode) } contentType := resp.Header.Get("Content-Type") From db79495397e4dcb557f678df4e4ac8492dc73502 Mon Sep 17 00:00:00 2001 From: teddylear Date: Fri, 6 May 2022 20:55:46 -0400 Subject: [PATCH 03/11] fix: add http datasource docs and add print statements to make errors more traceable --- datasource/http/data.go | 3 ++ website/content/docs/datasources/http/http.md | 49 +++++++++++++++++++ website/data/docs-nav-data.json | 4 ++ 3 files changed, 56 insertions(+) create mode 100644 website/content/docs/datasources/http/http.md diff --git a/datasource/http/data.go b/datasource/http/data.go index 253368ebe8a..5c51a398007 100644 --- a/datasource/http/data.go +++ b/datasource/http/data.go @@ -101,6 +101,7 @@ func (d *Datasource) Execute() (cty.Value, error) { req, err := http.NewRequestWithContext(ctx, "GET", url, nil) // TODO: How to make a test case for this? if err != nil { + fmt.Println("Error creating http request") return cty.NullVal(cty.EmptyObject), err } @@ -111,6 +112,7 @@ func (d *Datasource) Execute() (cty.Value, error) { resp, err := client.Do(req) // TODO: How to make test case for this if err != nil { + fmt.Println("Error making performing http request") return cty.NullVal(cty.EmptyObject), err } @@ -131,6 +133,7 @@ func (d *Datasource) Execute() (cty.Value, error) { bytes, err := ioutil.ReadAll(resp.Body) // TODO: How to make test case for this? if err != nil { + fmt.Println("Error processing response body of call") return cty.NullVal(cty.EmptyObject), err } diff --git a/website/content/docs/datasources/http/http.md b/website/content/docs/datasources/http/http.md new file mode 100644 index 00000000000..e80b0a48009 --- /dev/null +++ b/website/content/docs/datasources/http/http.md @@ -0,0 +1,49 @@ +--- +description: | + The http Data Source retrieves information from an http endpoint to be used + during Packer builds +page_title: Http - Data Sources +--- + + + + + + +# Http Data Source + +Type: `http` + +The `http` Data Source retrieves information from an http endpoint to be used +during packer builds + + +## Basic Example + +Below is a fully functioning example. It stores information about an image +iteration, which can then be parsed and accessed using HCL tools. + +```hcl +data "packer-image-iteration" "hardened-source" { + bucket = "hardened-ubuntu-16-04" + channel = "production-stable" +} +``` + +## Configuration Reference + +Configuration options are organized below into two categories: required and +optional. Within each category, the available options are alphabetized and +described. + +### Required: + +@include 'datasource/http/Config-required.mdx' + +@include 'datasource/http/Config-not-required.mdx' + +## Datasource outputs + +The outputs for this datasource are as follows: + +@include 'datasource/http/DatasourceOutput.mdx' diff --git a/website/data/docs-nav-data.json b/website/data/docs-nav-data.json index 1e4b0fbae37..2f07954b1c9 100644 --- a/website/data/docs-nav-data.json +++ b/website/data/docs-nav-data.json @@ -712,6 +712,10 @@ "title": "Image", "path": "datasources/hcp/hcp-packer-image" }, + { + "title": "Http", + "path": "datasources/http/http" + }, { "title": "Image-Deprecated", "path": "datasources/hcp/packer-image-iteration", From 095f3870c09a8511f63ce4f89fc9e06d8f6ac6e0 Mon Sep 17 00:00:00 2001 From: teddylear Date: Tue, 10 May 2022 17:28:50 -0400 Subject: [PATCH 04/11] Update website/content/docs/datasources/http/http.md Co-authored-by: Sylvia Moss --- website/content/docs/datasources/http/http.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/website/content/docs/datasources/http/http.md b/website/content/docs/datasources/http/http.md index e80b0a48009..e3a763bb626 100644 --- a/website/content/docs/datasources/http/http.md +++ b/website/content/docs/datasources/http/http.md @@ -14,8 +14,7 @@ page_title: Http - Data Sources Type: `http` -The `http` Data Source retrieves information from an http endpoint to be used -during packer builds +The `http` data source makes an HTTP GET request to the given URL and exports information about the response. ## Basic Example From 8405a29f4ec9adfa746758e3155a3421773b992c Mon Sep 17 00:00:00 2001 From: teddylear Date: Tue, 10 May 2022 17:29:14 -0400 Subject: [PATCH 05/11] Update website/content/docs/datasources/http/http.md Co-authored-by: Sylvia Moss --- website/content/docs/datasources/http/http.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/website/content/docs/datasources/http/http.md b/website/content/docs/datasources/http/http.md index e3a763bb626..45424ada354 100644 --- a/website/content/docs/datasources/http/http.md +++ b/website/content/docs/datasources/http/http.md @@ -19,15 +19,15 @@ The `http` data source makes an HTTP GET request to the given URL and exports in ## Basic Example -Below is a fully functioning example. It stores information about an image -iteration, which can then be parsed and accessed using HCL tools. - -```hcl -data "packer-image-iteration" "hardened-source" { - bucket = "hardened-ubuntu-16-04" - channel = "production-stable" +```hcl +data "http" "example" { + url = "https://checkpoint-api.hashicorp.com/v1/check/terraform" + + # Optional request headers + request_headers = { + Accept = "application/json" + } } -``` ## Configuration Reference From 74ca0419e3ed9e9257f1ea94e5e7e804180a2cce Mon Sep 17 00:00:00 2001 From: teddylear Date: Tue, 10 May 2022 17:29:38 -0400 Subject: [PATCH 06/11] Update website/content/docs/datasources/http/http.md Co-authored-by: Sylvia Moss --- website/content/docs/datasources/http/http.md | 1 + 1 file changed, 1 insertion(+) diff --git a/website/content/docs/datasources/http/http.md b/website/content/docs/datasources/http/http.md index 45424ada354..e5140f9fb55 100644 --- a/website/content/docs/datasources/http/http.md +++ b/website/content/docs/datasources/http/http.md @@ -39,6 +39,7 @@ described. @include 'datasource/http/Config-required.mdx' +### Not Required: @include 'datasource/http/Config-not-required.mdx' ## Datasource outputs From 7462a54bc002aeb6dee6e623d91c4820b6a9ae7c Mon Sep 17 00:00:00 2001 From: teddylear Date: Tue, 10 May 2022 17:30:11 -0400 Subject: [PATCH 07/11] Update datasource/http/data.go Co-authored-by: Sylvia Moss --- datasource/http/data.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datasource/http/data.go b/datasource/http/data.go index 5c51a398007..dca680aac7f 100644 --- a/datasource/http/data.go +++ b/datasource/http/data.go @@ -21,7 +21,7 @@ import ( type Config struct { common.PackerConfig `mapstructure:",squash"` - // Url where should be getting things from + // 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"` // Request headers for call Request_headers map[string]string `mapstructure:"request_headers" required:"false"` From 3774f57dd728594237f56ae911c1516509b8e669 Mon Sep 17 00:00:00 2001 From: teddylear Date: Tue, 10 May 2022 17:30:19 -0400 Subject: [PATCH 08/11] Update datasource/http/data.go Co-authored-by: Sylvia Moss --- datasource/http/data.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/datasource/http/data.go b/datasource/http/data.go index dca680aac7f..6151a3ec37f 100644 --- a/datasource/http/data.go +++ b/datasource/http/data.go @@ -32,8 +32,12 @@ type Datasource struct { } type DatasourceOutput struct { + // 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"` } From b2b6a78bcad775df185580a38b60146f8121512e Mon Sep 17 00:00:00 2001 From: teddylear Date: Tue, 10 May 2022 17:30:25 -0400 Subject: [PATCH 09/11] Update datasource/http/data.go Co-authored-by: Sylvia Moss --- datasource/http/data.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datasource/http/data.go b/datasource/http/data.go index 6151a3ec37f..f31172148c3 100644 --- a/datasource/http/data.go +++ b/datasource/http/data.go @@ -23,7 +23,7 @@ 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 Url string `mapstructure:"url" required:"true"` - // Request headers for call + // A map of strings representing additional HTTP headers to include in the request. Request_headers map[string]string `mapstructure:"request_headers" required:"false"` } From 8caa5ac9074c666396bbc8ce1d5c38de14d640bd Mon Sep 17 00:00:00 2001 From: teddylear Date: Tue, 10 May 2022 17:32:01 -0400 Subject: [PATCH 10/11] remove config.mdx for http datasource --- website/content/partials/datasource/http/Config.mdx | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 website/content/partials/datasource/http/Config.mdx diff --git a/website/content/partials/datasource/http/Config.mdx b/website/content/partials/datasource/http/Config.mdx deleted file mode 100644 index ad1fb4f1bb0..00000000000 --- a/website/content/partials/datasource/http/Config.mdx +++ /dev/null @@ -1,5 +0,0 @@ - - -TODO: Update comments - - From 6f201d7c374d874ec959e8790daf0b8e97dd2029 Mon Sep 17 00:00:00 2001 From: teddylear Date: Mon, 16 May 2022 17:41:29 -0400 Subject: [PATCH 11/11] fix: Update http website content --- .../content/docs/datasources/{http/http.md => http.mdx} | 0 website/data/docs-nav-data.json | 8 ++++---- 2 files changed, 4 insertions(+), 4 deletions(-) rename website/content/docs/datasources/{http/http.md => http.mdx} (100%) diff --git a/website/content/docs/datasources/http/http.md b/website/content/docs/datasources/http.mdx similarity index 100% rename from website/content/docs/datasources/http/http.md rename to website/content/docs/datasources/http.mdx diff --git a/website/data/docs-nav-data.json b/website/data/docs-nav-data.json index 2f07954b1c9..f116a27fe8a 100644 --- a/website/data/docs-nav-data.json +++ b/website/data/docs-nav-data.json @@ -712,16 +712,16 @@ "title": "Image", "path": "datasources/hcp/hcp-packer-image" }, - { - "title": "Http", - "path": "datasources/http/http" - }, { "title": "Image-Deprecated", "path": "datasources/hcp/packer-image-iteration", "hidden": true } ] + }, + { + "title": "Http", + "path": "datasources/http" } ] },