From 352737cb6026fcf6ce0f5a203bc5e4604bac6b98 Mon Sep 17 00:00:00 2001 From: William Martin Date: Fri, 13 Sep 2024 14:22:34 +0200 Subject: [PATCH 1/2] Use api subdomains for commands using ghinstance package --- internal/ghinstance/host.go | 14 ++++++++++++++ internal/ghinstance/host_test.go | 8 ++++++++ pkg/cmd/attestation/verify/verify_test.go | 2 +- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/internal/ghinstance/host.go b/internal/ghinstance/host.go index 729d47f31..f80bfef57 100644 --- a/internal/ghinstance/host.go +++ b/internal/ghinstance/host.go @@ -73,6 +73,13 @@ func GraphQLEndpoint(hostname string) string { if isGarage(hostname) { return fmt.Sprintf("https://%s/api/graphql", hostname) } + // Once we change Tenancy to no longer be treated as Enterprise, this + // conditional can be removed as the flow will fall through to the bottom. + // However, we can't do that until we've investigated all places in which + // Tenancy is currently treated as Enterprise. + if IsTenancy(hostname) { + return fmt.Sprintf("https://api.%s/graphql", hostname) + } if IsEnterprise(hostname) { return fmt.Sprintf("https://%s/api/graphql", hostname) } @@ -86,6 +93,13 @@ func RESTPrefix(hostname string) string { if isGarage(hostname) { return fmt.Sprintf("https://%s/api/v3/", hostname) } + // Once we change Tenancy to no longer be treated as Enterprise, this + // conditional can be removed as the flow will fall through to the bottom. + // However, we can't do that until we've investigated all places in which + // Tenancy is currently treated as Enterprise. + if IsTenancy(hostname) { + return fmt.Sprintf("https://api.%s/", hostname) + } if IsEnterprise(hostname) { return fmt.Sprintf("https://%s/api/v3/", hostname) } diff --git a/internal/ghinstance/host_test.go b/internal/ghinstance/host_test.go index 673fad24c..e9fb97008 100644 --- a/internal/ghinstance/host_test.go +++ b/internal/ghinstance/host_test.go @@ -254,6 +254,10 @@ func TestGraphQLEndpoint(t *testing.T) { host: "ghe.io", want: "https://ghe.io/api/graphql", }, + { + host: "tenant.ghe.com", + want: "https://api.tenant.ghe.com/graphql", + }, } for _, tt := range tests { t.Run(tt.host, func(t *testing.T) { @@ -285,6 +289,10 @@ func TestRESTPrefix(t *testing.T) { host: "ghe.io", want: "https://ghe.io/api/v3/", }, + { + host: "tenant.ghe.com", + want: "https://api.tenant.ghe.com/", + }, } for _, tt := range tests { t.Run(tt.host, func(t *testing.T) { diff --git a/pkg/cmd/attestation/verify/verify_test.go b/pkg/cmd/attestation/verify/verify_test.go index 6f71b537f..3ff309922 100644 --- a/pkg/cmd/attestation/verify/verify_test.go +++ b/pkg/cmd/attestation/verify/verify_test.go @@ -43,7 +43,7 @@ func TestNewVerifyCmd(t *testing.T) { }, }, } - testReg.Register(httpmock.REST(http.MethodGet, "api/v3/meta"), + testReg.Register(httpmock.REST(http.MethodGet, "meta"), httpmock.StatusJSONResponse(200, &metaResp)) f := &cmdutil.Factory{ From 420d80b4980f1cffd39b0b0b6006c4a9ab1de254 Mon Sep 17 00:00:00 2001 From: William Martin Date: Fri, 13 Sep 2024 14:48:55 +0200 Subject: [PATCH 2/2] Update go-gh to use api subdomains --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 78ceb7f70..54d02ec8e 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/cenkalti/backoff/v4 v4.3.0 github.com/charmbracelet/glamour v0.7.0 github.com/charmbracelet/lipgloss v0.10.1-0.20240413172830-d0be07ea6b9c - github.com/cli/go-gh/v2 v2.9.0 + github.com/cli/go-gh/v2 v2.10.0 github.com/cli/oauth v1.0.1 github.com/cli/safeexec v1.0.1 github.com/cpuguy83/go-md2man/v2 v2.0.4 diff --git a/go.sum b/go.sum index 37c40407d..416f2ee59 100644 --- a/go.sum +++ b/go.sum @@ -95,8 +95,8 @@ github.com/charmbracelet/x/exp/term v0.0.0-20240425164147-ba2a9512b05f/go.mod h1 github.com/cli/browser v1.0.0/go.mod h1:IEWkHYbLjkhtjwwWlwTHW2lGxeS5gezEQBMLTwDHf5Q= github.com/cli/browser v1.3.0 h1:LejqCrpWr+1pRqmEPDGnTZOjsMe7sehifLynZJuqJpo= github.com/cli/browser v1.3.0/go.mod h1:HH8s+fOAxjhQoBUAsKuPCbqUuxZDhQ2/aD+SzsEfBTk= -github.com/cli/go-gh/v2 v2.9.0 h1:D3lTjEneMYl54M+WjZ+kRPrR5CEJ5BHS05isBPOV3LI= -github.com/cli/go-gh/v2 v2.9.0/go.mod h1:MeRoKzXff3ygHu7zP+NVTT+imcHW6p3tpuxHAzRM2xE= +github.com/cli/go-gh/v2 v2.10.0 h1:GMflBKoErBXlLvN2euxzL+p7JaM8erlSmw0cT7uZr7M= +github.com/cli/go-gh/v2 v2.10.0/go.mod h1:MeRoKzXff3ygHu7zP+NVTT+imcHW6p3tpuxHAzRM2xE= github.com/cli/oauth v1.0.1 h1:pXnTFl/qUegXHK531Dv0LNjW4mLx626eS42gnzfXJPA= github.com/cli/oauth v1.0.1/go.mod h1:qd/FX8ZBD6n1sVNQO3aIdRxeu5LGw9WhKnYhIIoC2A4= github.com/cli/safeexec v1.0.0/go.mod h1:Z/D4tTN8Vs5gXYHDCbaM1S/anmEDnJb1iW0+EJ5zx3Q=