Skip to content

Commit 951ca77

Browse files
committed
fix(hosted): restore public upstream for anonymous reads
1 parent a79d6b4 commit 951ca77

5 files changed

Lines changed: 55 additions & 8 deletions

File tree

cmd/wl/cmd_serve.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ import (
3434
)
3535

3636
const (
37-
hostedPublicUpstreamOrg = "wasteland"
38-
hostedPublicUpstreamDB = "wl-commons"
39-
hostedPublicUpstream = hostedPublicUpstreamOrg + "/" + hostedPublicUpstreamDB
37+
hostedPublicUpstreamOrg = hosted.PublicUpstreamOrg
38+
hostedPublicUpstreamDB = hosted.PublicUpstreamDB
39+
hostedPublicUpstream = hosted.PublicUpstream
4040
pendingRefreshTimeout = 30 * time.Second
4141
)
4242

cmd/wl/cmd_serve_additional_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ func TestResolvePort_InvalidEnvFallsBackToFlag(t *testing.T) {
6565
}
6666

6767
func TestHostedPublicUpstream_IsCanonical(t *testing.T) {
68-
if hostedPublicUpstreamOrg != "wasteland" {
68+
if hostedPublicUpstreamOrg != "hop" {
6969
t.Fatalf("hostedPublicUpstreamOrg = %q", hostedPublicUpstreamOrg)
7070
}
7171
if hostedPublicUpstreamDB != "wl-commons" {
7272
t.Fatalf("hostedPublicUpstreamDB = %q", hostedPublicUpstreamDB)
7373
}
74-
if hostedPublicUpstream != "wasteland/wl-commons" {
74+
if hostedPublicUpstream != "hop/wl-commons" {
7575
t.Fatalf("hostedPublicUpstream = %q", hostedPublicUpstream)
7676
}
7777
}

internal/hosted/public_upstream.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package hosted
2+
3+
import (
4+
"fmt"
5+
"net/url"
6+
"strings"
7+
)
8+
9+
const (
10+
// PublicUpstreamOrg defines the anonymous hosted board owner that backs
11+
// logged-out browse, detail, and scoreboard reads.
12+
PublicUpstreamOrg = "hop"
13+
// PublicUpstreamDB defines the anonymous hosted board name that backs
14+
// logged-out browse, detail, and scoreboard reads.
15+
PublicUpstreamDB = "wl-commons"
16+
// PublicUpstream is the canonical anonymous hosted board identity.
17+
PublicUpstream = PublicUpstreamOrg + "/" + PublicUpstreamDB
18+
)
19+
20+
// PublicDoltHubQueryURL builds the DoltHub SQL API URL for the canonical
21+
// public hosted upstream.
22+
func PublicDoltHubQueryURL(query string) string {
23+
escaped := strings.ReplaceAll(url.QueryEscape(query), "+", "%20")
24+
return fmt.Sprintf(
25+
"https://www.dolthub.com/api/v1alpha1/%s/%s/main?q=%s",
26+
PublicUpstreamOrg,
27+
PublicUpstreamDB,
28+
escaped,
29+
)
30+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package hosted
2+
3+
import "testing"
4+
5+
func TestPublicDoltHubQueryURL_UsesCanonicalPublicRepo(t *testing.T) {
6+
if PublicUpstreamOrg != "hop" {
7+
t.Fatalf("PublicUpstreamOrg = %q", PublicUpstreamOrg)
8+
}
9+
if PublicUpstreamDB != "wl-commons" {
10+
t.Fatalf("PublicUpstreamDB = %q", PublicUpstreamDB)
11+
}
12+
if PublicUpstream != "hop/wl-commons" {
13+
t.Fatalf("PublicUpstream = %q", PublicUpstream)
14+
}
15+
if got := PublicDoltHubQueryURL("SELECT 1"); got != "https://www.dolthub.com/api/v1alpha1/hop/wl-commons/main?q=SELECT%201" {
16+
t.Fatalf("PublicDoltHubQueryURL() = %q", got)
17+
}
18+
}

internal/hosted/server.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ func (e *authError) Error() string { return e.msg }
576576
// not restart us for an upstream outage).
577577
func healthHandler() http.HandlerFunc {
578578
client := &http.Client{Timeout: 3 * time.Second}
579-
const probe = "https://www.dolthub.com/api/v1alpha1/hop/wl-commons/main?q=SELECT%201"
579+
probe := PublicDoltHubQueryURL("SELECT 1")
580580

581581
return func(w http.ResponseWriter, _ *http.Request) {
582582
dolthub := "ok"
@@ -608,8 +608,7 @@ var ProbeDoltHubToken = func(apiKey string) error {
608608
if apiKey == "" {
609609
return nil
610610
}
611-
req, err := http.NewRequest("GET",
612-
"https://www.dolthub.com/api/v1alpha1/hop/wl-commons/main?q=SELECT%201", nil)
611+
req, err := http.NewRequest("GET", PublicDoltHubQueryURL("SELECT 1"), nil)
613612
if err != nil {
614613
return nil // don't block connect for request construction errors
615614
}

0 commit comments

Comments
 (0)