From 6e507a68063497f09b4c5724829c7ecf6f7dd7c4 Mon Sep 17 00:00:00 2001 From: Ross Gustafson Date: Mon, 22 Jan 2024 21:16:17 +0000 Subject: [PATCH 1/4] fix: github_rest_api data source always returns header and body as null (#2110) * Enhance tests * Marshal body and headers to JSON string * Update documentation to reference JSON string --------- Co-authored-by: Keegan Campbell --- github/data_source_github_rest_api.go | 19 +++++++++++++++---- github/data_source_github_rest_api_test.go | 10 ++++++++++ website/docs/d/rest_api.html.markdown | 5 +++-- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/github/data_source_github_rest_api.go b/github/data_source_github_rest_api.go index 1bbd22f023..bc1b5f1a50 100644 --- a/github/data_source_github_rest_api.go +++ b/github/data_source_github_rest_api.go @@ -2,6 +2,7 @@ package github import ( "context" + "encoding/json" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) @@ -25,11 +26,11 @@ func dataSourceGithubRestApi() *schema.Resource { Computed: true, }, "headers": { - Type: schema.TypeMap, + Type: schema.TypeString, Computed: true, }, "body": { - Type: schema.TypeMap, + Type: schema.TypeString, Computed: true, }, }, @@ -51,11 +52,21 @@ func dataSourceGithubRestApiRead(d *schema.ResourceData, meta interface{}) error resp, _ := client.Do(ctx, req, &body) + h, err := json.Marshal(resp.Header) + if err != nil { + return err + } + + b, err := json.Marshal(body) + if err != nil { + return err + } + d.SetId(resp.Header.Get("x-github-request-id")) d.Set("code", resp.StatusCode) d.Set("status", resp.Status) - d.Set("headers", resp.Header) - d.Set("body", body) + d.Set("headers", string(h)) + d.Set("body", string(b)) return nil } diff --git a/github/data_source_github_rest_api_test.go b/github/data_source_github_rest_api_test.go index b69bc6b398..d309323cd4 100644 --- a/github/data_source_github_rest_api_test.go +++ b/github/data_source_github_rest_api_test.go @@ -30,6 +30,11 @@ func TestAccGithubRestApiDataSource(t *testing.T) { resource.TestMatchResourceAttr( "data.github_rest_api.test", "code", regexp.MustCompile("200"), ), + resource.TestMatchResourceAttr( + "data.github_rest_api.test", "status", regexp.MustCompile("200 OK"), + ), + resource.TestCheckResourceAttrSet("data.github_rest_api.test", "body"), + resource.TestCheckResourceAttrSet("data.github_rest_api.test", "headers"), ) testCase := func(t *testing.T, mode string) { @@ -76,6 +81,11 @@ func TestAccGithubRestApiDataSource(t *testing.T) { resource.TestMatchResourceAttr( "data.github_rest_api.test", "code", regexp.MustCompile("404"), ), + resource.TestMatchResourceAttr( + "data.github_rest_api.test", "status", regexp.MustCompile("404 Not Found"), + ), + resource.TestCheckResourceAttrSet("data.github_rest_api.test", "body"), + resource.TestCheckResourceAttrSet("data.github_rest_api.test", "headers"), ) testCase := func(t *testing.T, mode string) { diff --git a/website/docs/d/rest_api.html.markdown b/website/docs/d/rest_api.html.markdown index 4535d79508..de628acef6 100644 --- a/website/docs/d/rest_api.html.markdown +++ b/website/docs/d/rest_api.html.markdown @@ -23,7 +23,8 @@ data "github_rest_api" "example" { ## Attributes Reference + * `id` - The GitHub API Request ID * `code` - A response status code. * `status` - A response status string. - * `headers` - A map of response headers. - * `body` - A map of response body. + * `headers` - A JSON string containing response headers. + * `body` - A JSON string containing response body. From 8e61a74f6e7f5fb1487658cd9ef6bf5d01548b62 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 29 Jan 2024 03:15:21 +0000 Subject: [PATCH 2/4] build(deps): bump github.com/google/uuid from 1.5.0 to 1.6.0 Bumps [github.com/google/uuid](https://github.com/google/uuid) from 1.5.0 to 1.6.0. - [Release notes](https://github.com/google/uuid/releases) - [Changelog](https://github.com/google/uuid/blob/master/CHANGELOG.md) - [Commits](https://github.com/google/uuid/compare/v1.5.0...v1.6.0) --- updated-dependencies: - dependency-name: github.com/google/uuid dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 +-- vendor/github.com/google/uuid/CHANGELOG.md | 13 ++++++++ vendor/github.com/google/uuid/hash.go | 6 ++++ vendor/github.com/google/uuid/version7.go | 39 +++++++++++++++++++--- vendor/modules.txt | 2 +- 6 files changed, 57 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index fa189f6e17..c45e36236b 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/client9/misspell v0.3.4 github.com/golangci/golangci-lint v1.41.1 github.com/google/go-github/v57 v57.0.0 - github.com/google/uuid v1.5.0 + github.com/google/uuid v1.6.0 github.com/hashicorp/terraform-plugin-sdk v1.17.2 github.com/shurcooL/githubv4 v0.0.0-20221126192849-0b5c4c7994eb github.com/stretchr/testify v1.8.4 diff --git a/go.sum b/go.sum index b3dd3f3ba0..405481ef09 100644 --- a/go.sum +++ b/go.sum @@ -1026,8 +1026,8 @@ github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+ github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU= -github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/enterprise-certificate-proxy v0.0.0-20220520183353-fd19c99a87aa/go.mod h1:17drOmN3MwGY7t0e+Ei9b45FFGA3fBs3x36SsCg1hq8= github.com/googleapis/enterprise-certificate-proxy v0.1.0/go.mod h1:17drOmN3MwGY7t0e+Ei9b45FFGA3fBs3x36SsCg1hq8= github.com/googleapis/enterprise-certificate-proxy v0.2.0/go.mod h1:8C0jb7/mgJe/9KK8Lm7X9ctZC2t60YyIpYEI16jx0Qg= diff --git a/vendor/github.com/google/uuid/CHANGELOG.md b/vendor/github.com/google/uuid/CHANGELOG.md index c9fb829dc6..7ec5ac7ea9 100644 --- a/vendor/github.com/google/uuid/CHANGELOG.md +++ b/vendor/github.com/google/uuid/CHANGELOG.md @@ -1,5 +1,18 @@ # Changelog +## [1.6.0](https://github.com/google/uuid/compare/v1.5.0...v1.6.0) (2024-01-16) + + +### Features + +* add Max UUID constant ([#149](https://github.com/google/uuid/issues/149)) ([c58770e](https://github.com/google/uuid/commit/c58770eb495f55fe2ced6284f93c5158a62e53e3)) + + +### Bug Fixes + +* fix typo in version 7 uuid documentation ([#153](https://github.com/google/uuid/issues/153)) ([016b199](https://github.com/google/uuid/commit/016b199544692f745ffc8867b914129ecb47ef06)) +* Monotonicity in UUIDv7 ([#150](https://github.com/google/uuid/issues/150)) ([a2b2b32](https://github.com/google/uuid/commit/a2b2b32373ff0b1a312b7fdf6d38a977099698a6)) + ## [1.5.0](https://github.com/google/uuid/compare/v1.4.0...v1.5.0) (2023-12-12) diff --git a/vendor/github.com/google/uuid/hash.go b/vendor/github.com/google/uuid/hash.go index b404f4bec2..dc60082d3b 100644 --- a/vendor/github.com/google/uuid/hash.go +++ b/vendor/github.com/google/uuid/hash.go @@ -17,6 +17,12 @@ var ( NameSpaceOID = Must(Parse("6ba7b812-9dad-11d1-80b4-00c04fd430c8")) NameSpaceX500 = Must(Parse("6ba7b814-9dad-11d1-80b4-00c04fd430c8")) Nil UUID // empty UUID, all zeros + + // The Max UUID is special form of UUID that is specified to have all 128 bits set to 1. + Max = UUID{ + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + } ) // NewHash returns a new UUID derived from the hash of space concatenated with diff --git a/vendor/github.com/google/uuid/version7.go b/vendor/github.com/google/uuid/version7.go index ba9dd5eb68..3167b643d4 100644 --- a/vendor/github.com/google/uuid/version7.go +++ b/vendor/github.com/google/uuid/version7.go @@ -44,7 +44,7 @@ func NewV7FromReader(r io.Reader) (UUID, error) { // makeV7 fill 48 bits time (uuid[0] - uuid[5]), set version b0111 (uuid[6]) // uuid[8] already has the right version number (Variant is 10) -// see function NewV7 and NewV7FromReader +// see function NewV7 and NewV7FromReader func makeV7(uuid []byte) { /* 0 1 2 3 @@ -52,7 +52,7 @@ func makeV7(uuid []byte) { +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | unix_ts_ms | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | unix_ts_ms | ver | rand_a | + | unix_ts_ms | ver | rand_a (12 bit seq) | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |var| rand_b | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ @@ -61,7 +61,7 @@ func makeV7(uuid []byte) { */ _ = uuid[15] // bounds check - t := timeNow().UnixMilli() + t, s := getV7Time() uuid[0] = byte(t >> 40) uuid[1] = byte(t >> 32) @@ -70,6 +70,35 @@ func makeV7(uuid []byte) { uuid[4] = byte(t >> 8) uuid[5] = byte(t) - uuid[6] = 0x70 | (uuid[6] & 0x0F) - // uuid[8] has already has right version + uuid[6] = 0x70 | (0x0F & byte(s>>8)) + uuid[7] = byte(s) +} + +// lastV7time is the last time we returned stored as: +// +// 52 bits of time in milliseconds since epoch +// 12 bits of (fractional nanoseconds) >> 8 +var lastV7time int64 + +const nanoPerMilli = 1000000 + +// getV7Time returns the time in milliseconds and nanoseconds / 256. +// The returned (milli << 12 + seq) is guarenteed to be greater than +// (milli << 12 + seq) returned by any previous call to getV7Time. +func getV7Time() (milli, seq int64) { + timeMu.Lock() + defer timeMu.Unlock() + + nano := timeNow().UnixNano() + milli = nano / nanoPerMilli + // Sequence number is between 0 and 3906 (nanoPerMilli>>8) + seq = (nano - milli*nanoPerMilli) >> 8 + now := milli<<12 + seq + if now <= lastV7time { + now = lastV7time + 1 + milli = now >> 12 + seq = now & 0xfff + } + lastV7time = now + return milli, seq } diff --git a/vendor/modules.txt b/vendor/modules.txt index c08d551a36..a0a0cb5d08 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -327,7 +327,7 @@ github.com/google/s2a-go/internal/v2/certverifier github.com/google/s2a-go/internal/v2/remotesigner github.com/google/s2a-go/internal/v2/tlsconfigstore github.com/google/s2a-go/stream -# github.com/google/uuid v1.5.0 +# github.com/google/uuid v1.6.0 ## explicit github.com/google/uuid # github.com/googleapis/enterprise-certificate-proxy v0.2.3 From 86b20f28d2ee854f3e4d4414313e23d3c5d712a9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 29 Jan 2024 03:47:54 +0000 Subject: [PATCH 3/4] build(deps): bump peter-evans/create-or-update-comment from 3 to 4 Bumps [peter-evans/create-or-update-comment](https://github.com/peter-evans/create-or-update-comment) from 3 to 4. - [Release notes](https://github.com/peter-evans/create-or-update-comment/releases) - [Commits](https://github.com/peter-evans/create-or-update-comment/compare/v3...v4) --- updated-dependencies: - dependency-name: peter-evans/create-or-update-comment dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/immediate-response.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/immediate-response.yml b/.github/workflows/immediate-response.yml index 4bb10f5ef3..e8bb8ee5b8 100644 --- a/.github/workflows/immediate-response.yml +++ b/.github/workflows/immediate-response.yml @@ -19,7 +19,7 @@ jobs: run: echo "NUMBER=${{ github.event.issue.number || github.event.pull_request.number }}" >> "$GITHUB_OUTPUT" - name: Respond to issue or PR - uses: peter-evans/create-or-update-comment@v3 + uses: peter-evans/create-or-update-comment@v4 with: issue-number: ${{ steps.extract.outputs.NUMBER }} body: > From 970dd207659ecbf37b581b5a564cf273a3cc1259 Mon Sep 17 00:00:00 2001 From: Nikolai Mishin Date: Fri, 2 Feb 2024 22:39:25 +0100 Subject: [PATCH 4/4] Add support for packages IP ranges in github_ip_ranges (#1958) * Add support for packages IP ranges in github_ip_ranges * Update docks for packages IP ranges in github_ip_ranges * gofmt * Add tests for packages IP ranges in github_ip_ranges * Update tests for packages IP ranges in github_ip_ranges --------- Co-authored-by: Keegan Campbell --- github/data_source_github_ip_ranges.go | 25 +++++++++++++++++++++ github/data_source_github_ip_ranges_test.go | 3 +++ website/docs/d/ip_ranges.html.markdown | 3 +++ 3 files changed, 31 insertions(+) diff --git a/github/data_source_github_ip_ranges.go b/github/data_source_github_ip_ranges.go index a5115300b2..3a6d53ea9c 100644 --- a/github/data_source_github_ip_ranges.go +++ b/github/data_source_github_ip_ranges.go @@ -32,6 +32,11 @@ func dataSourceGithubIpRanges() *schema.Resource { Computed: true, Elem: &schema.Schema{Type: schema.TypeString}, }, + "packages": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, "pages": { Type: schema.TypeList, Computed: true, @@ -72,6 +77,11 @@ func dataSourceGithubIpRanges() *schema.Resource { Computed: true, Elem: &schema.Schema{Type: schema.TypeString}, }, + "packages_ipv4": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, "pages_ipv4": { Type: schema.TypeList, Computed: true, @@ -112,6 +122,11 @@ func dataSourceGithubIpRanges() *schema.Resource { Computed: true, Elem: &schema.Schema{Type: schema.TypeString}, }, + "packages_ipv6": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, "pages_ipv6": { Type: schema.TypeList, Computed: true, @@ -154,6 +169,11 @@ func dataSourceGithubIpRangesRead(d *schema.ResourceData, meta interface{}) erro return err } + cidrPackagesIpv4, cidrPackagesIpv6, err := splitIpv4Ipv6Cidrs(&api.Packages) + if err != nil { + return err + } + cidrPagesIpv4, cidrPagesIpv6, err := splitIpv4Ipv6Cidrs(&api.Pages) if err != nil { return err @@ -197,6 +217,11 @@ func dataSourceGithubIpRangesRead(d *schema.ResourceData, meta interface{}) erro d.Set("git_ipv4", cidrGitIpv4) d.Set("git_ipv6", cidrGitIpv6) } + if len(api.Packages) > 0 { + d.Set("packages", api.Packages) + d.Set("packages_ipv4", cidrPackagesIpv4) + d.Set("packages_ipv6", cidrPackagesIpv6) + } if len(api.Pages) > 0 { d.Set("pages", api.Pages) d.Set("pages_ipv4", cidrPagesIpv4) diff --git a/github/data_source_github_ip_ranges_test.go b/github/data_source_github_ip_ranges_test.go index 27a1658bfc..3c017ff5ff 100644 --- a/github/data_source_github_ip_ranges_test.go +++ b/github/data_source_github_ip_ranges_test.go @@ -17,6 +17,7 @@ func TestAccGithubIpRangesDataSource(t *testing.T) { resource.TestCheckResourceAttrSet("data.github_ip_ranges.test", "git.#"), resource.TestCheckResourceAttrSet("data.github_ip_ranges.test", "api.#"), resource.TestCheckResourceAttrSet("data.github_ip_ranges.test", "web.#"), + resource.TestCheckResourceAttrSet("data.github_ip_ranges.test", "packages.#"), resource.TestCheckResourceAttrSet("data.github_ip_ranges.test", "pages.#"), resource.TestCheckResourceAttrSet("data.github_ip_ranges.test", "importer.#"), resource.TestCheckResourceAttrSet("data.github_ip_ranges.test", "actions.#"), @@ -25,6 +26,7 @@ func TestAccGithubIpRangesDataSource(t *testing.T) { resource.TestCheckResourceAttrSet("data.github_ip_ranges.test", "git_ipv4.#"), resource.TestCheckResourceAttrSet("data.github_ip_ranges.test", "api_ipv4.#"), resource.TestCheckResourceAttrSet("data.github_ip_ranges.test", "web_ipv4.#"), + resource.TestCheckResourceAttrSet("data.github_ip_ranges.test", "packages_ipv4.#"), resource.TestCheckResourceAttrSet("data.github_ip_ranges.test", "pages_ipv4.#"), resource.TestCheckResourceAttrSet("data.github_ip_ranges.test", "importer_ipv4.#"), resource.TestCheckResourceAttrSet("data.github_ip_ranges.test", "actions_ipv4.#"), @@ -33,6 +35,7 @@ func TestAccGithubIpRangesDataSource(t *testing.T) { resource.TestCheckResourceAttrSet("data.github_ip_ranges.test", "git_ipv6.#"), resource.TestCheckResourceAttrSet("data.github_ip_ranges.test", "api_ipv6.#"), resource.TestCheckResourceAttrSet("data.github_ip_ranges.test", "web_ipv6.#"), + resource.TestCheckResourceAttrSet("data.github_ip_ranges.test", "packages_ipv6.#"), resource.TestCheckResourceAttrSet("data.github_ip_ranges.test", "pages_ipv6.#"), resource.TestCheckResourceAttrSet("data.github_ip_ranges.test", "importer_ipv6.#"), resource.TestCheckResourceAttrSet("data.github_ip_ranges.test", "actions_ipv6.#"), diff --git a/website/docs/d/ip_ranges.html.markdown b/website/docs/d/ip_ranges.html.markdown index 5bf7f75be8..7d9cbe1b53 100644 --- a/website/docs/d/ip_ranges.html.markdown +++ b/website/docs/d/ip_ranges.html.markdown @@ -35,6 +35,9 @@ data "github_ip_ranges" "test" {} * `api` - An Array of IP addresses in CIDR format for the GitHub API. * `api_ipv4` - A subset of the `api` array that contains IP addresses in IPv4 CIDR format. * `api_ipv6` - A subset of the `api` array that contains IP addresses in IPv6 CIDR format. + * `packages` - An Array of IP addresses in CIDR format specifying the A records for GitHub Packages. + * `packages_ipv4` - A subset of the `packages` array that contains IP addresses in IPv4 CIDR format. + * `packages_ipv6` - A subset of the `packages` array that contains IP addresses in IPv6 CIDR format. * `pages` - An Array of IP addresses in CIDR format specifying the A records for GitHub Pages. * `pages_ipv4` - A subset of the `pages` array that contains IP addresses in IPv4 CIDR format. * `pages_ipv6` - A subset of the `pages` array that contains IP addresses in IPv6 CIDR format.