Skip to content

Commit 267e1ca

Browse files
authored
Merge pull request #172 from cli/wm/tenant-api
Use api subdomain for REST and GQL clients when host is tenant
2 parents 25db6b9 + af31cb3 commit 267e1ca

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

Diff for: pkg/api/graphql_client_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,11 @@ func TestGraphQLEndpoint(t *testing.T) {
293293
host: "enterprise.com",
294294
wantEndpoint: "https://enterprise.com/api/graphql",
295295
},
296+
{
297+
name: "tenant",
298+
host: "tenant.ghe.com",
299+
wantEndpoint: "https://api.tenant.ghe.com/graphql",
300+
},
296301
}
297302

298303
for _, tt := range tests {

Diff for: pkg/api/http_client.go

+16-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,14 @@ func isGarage(host string) bool {
135135
}
136136

137137
func isEnterprise(host string) bool {
138-
return host != github && host != localhost
138+
return host != github && host != localhost && !isTenancy(host)
139+
}
140+
141+
// tenancyHost is the domain name of a tenancy GitHub instance.
142+
const tenancyHost = "ghe.com"
143+
144+
func isTenancy(host string) bool {
145+
return strings.HasSuffix(host, "."+tenancyHost)
139146
}
140147

141148
func normalizeHostname(hostname string) string {
@@ -146,6 +153,14 @@ func normalizeHostname(hostname string) string {
146153
if strings.HasSuffix(hostname, "."+localhost) {
147154
return localhost
148155
}
156+
// This has been copied over from the cli/cli NormalizeHostname function
157+
// to ensure compatible behaviour but we don't fully understand when or
158+
// why it would be useful here. We can't see what harm will come of
159+
// duplicating the logic.
160+
if before, found := strings.CutSuffix(hostname, "."+tenancyHost); found {
161+
idx := strings.LastIndex(before, ".")
162+
return fmt.Sprintf("%s.%s", before[idx+1:], tenancyHost)
163+
}
149164
return hostname
150165
}
151166

Diff for: pkg/api/rest_client_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,11 @@ func TestRestPrefix(t *testing.T) {
474474
host: "enterprise.com",
475475
wantEndpoint: "https://enterprise.com/api/v3/",
476476
},
477+
{
478+
name: "tenant",
479+
host: "tenant.ghe.com",
480+
wantEndpoint: "https://api.tenant.ghe.com/",
481+
},
477482
}
478483

479484
for _, tt := range tests {

0 commit comments

Comments
 (0)