Skip to content

Commit 9e22628

Browse files
committed
Fix broken build
1 parent 7381d1b commit 9e22628

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

github/apps.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,11 @@ import (
99
"io"
1010
"net/http"
1111
"time"
12-
"regexp"
1312

1413
"github.com/go-jose/go-jose/v3"
1514
"github.com/go-jose/go-jose/v3/jwt"
1615
)
1716

18-
// regex to match a GitHub Enterprise Cloud with data residency URL
19-
var GhecDrRegex = regexp.MustCompile(`^https:\/\/[a-zA-Z0-9.\-]*\.ghe\.com$`)
20-
2117
// GenerateOAuthTokenFromApp generates a GitHub OAuth access token from a set of valid GitHub App credentials.
2218
// The returned token can be used to interact with both GitHub's REST and GraphQL APIs.
2319
func GenerateOAuthTokenFromApp(baseURL, appID, appInstallationID, pemData string) (string, error) {
@@ -35,7 +31,7 @@ func GenerateOAuthTokenFromApp(baseURL, appID, appInstallationID, pemData string
3531
}
3632

3733
func getInstallationAccessToken(baseURL string, jwt string, installationID string) (string, error) {
38-
if baseURL != "https://api.github.com/" && !GhecDrRegex.MatchString(baseURL) {
34+
if baseURL != "https://api.github.com/" && !GHECDataResidencyMatch.MatchString(baseURL) {
3935
baseURL += "api/v3/"
4036
}
4137

github/config.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import (
55
"net/http"
66
"net/url"
77
"path"
8+
"regexp"
89
"strings"
910
"time"
10-
"regexp"
1111

1212
"github.com/google/go-github/v66/github"
1313
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/logging"
@@ -37,8 +37,9 @@ type Owner struct {
3737
IsOrganization bool
3838
}
3939

40-
// regex to match a GitHub Enterprise Cloud with data residency URL
41-
var GhecDrRegex = regexp.MustCompile(`^https:\/\/[a-zA-Z0-9.\-]*\.ghe\.com$`)
40+
// GHECDataResidencyMatch is a regex to match a GitHub Enterprise Cloud data residency URL:
41+
// https://[hostname].ghe.com instances expect paths that behave similar to GitHub.com, not GitHub Enterprise Server.
42+
var GHECDataResidencyMatch = regexp.MustCompile(`^https:\/\/[a-zA-Z0-9.\-]*\.ghe\.com$`)
4243

4344
func RateLimitedHTTPClient(client *http.Client, writeDelay time.Duration, readDelay time.Duration, retryDelay time.Duration, parallelRequests bool, retryableErrors map[int]bool, maxRetries int) *http.Client {
4445

@@ -84,7 +85,7 @@ func (c *Config) NewGraphQLClient(client *http.Client) (*githubv4.Client, error)
8485
return nil, err
8586
}
8687

87-
if uv4.String() != "https://api.github.com/" && !GhecDrRegex.MatchString(uv4.String()) {
88+
if uv4.String() != "https://api.github.com/" && !GHECDataResidencyMatch.MatchString(uv4.String()) {
8889
uv4.Path = path.Join(uv4.Path, "api/graphql/")
8990
} else {
9091
uv4.Path = path.Join(uv4.Path, "graphql")
@@ -100,7 +101,7 @@ func (c *Config) NewRESTClient(client *http.Client) (*github.Client, error) {
100101
return nil, err
101102
}
102103

103-
if uv3.String() != "https://api.github.com/" && !GhecDrRegex.MatchString(uv3.String()) {
104+
if uv3.String() != "https://api.github.com/" && !GHECDataResidencyMatch.MatchString(uv3.String()) {
104105
uv3.Path = uv3.Path + "api/v3/"
105106
}
106107

0 commit comments

Comments
 (0)