Skip to content

Commit 144792d

Browse files
committed
Drop numeric-only validation from host URL workspace ID parsing
The new X-Databricks-Workspace-Id routing header accepts non-numeric workspace identifiers (e.g. connection-style strings) in addition to classic numeric workspace IDs; the server disambiguates. The URL parser was rejecting any non-numeric value via strconv.ParseInt and silently dropping it, which would block pasted URLs that carry one of the new identifier shapes. Remove the numeric validation from all three branches (?o=, ?w=, ?workspace_id=) in ExtractHostQueryParams and pass the raw value through. Affects every caller of the helper: - databricks auth login --host - workspace.host in databricks.yml (via bundle/config/workspace.go) Flip the existing "non-numeric is skipped" tests in hostparams_test.go and host_env_test.go to "non-numeric is passed through". Add a positive test case for a UUID-shaped connection-style identifier.
1 parent 146a88a commit 144792d

3 files changed

Lines changed: 26 additions & 23 deletions

File tree

libs/auth/host_env_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,10 @@ func TestNormalizeDatabricksConfigFromEnv(t *testing.T) {
5353
name: "no host env is a no-op",
5454
},
5555
{
56-
name: "non-numeric o is dropped, host trailing slash trimmed",
57-
host: "https://acme.databricks.net/?o=notanumber",
58-
wantHost: "https://acme.databricks.net",
56+
name: "non-numeric o is passed through, host trailing slash trimmed",
57+
host: "https://acme.databricks.net/?o=notanumber",
58+
wantHost: "https://acme.databricks.net",
59+
wantWorkspaceID: "notanumber",
5960
},
6061
}
6162

libs/auth/hostparams.go

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package auth
22

33
import (
44
"net/url"
5-
"strconv"
65
"strings"
76
)
87

@@ -12,7 +11,10 @@ type HostParams struct {
1211
Host string
1312

1413
// WorkspaceID extracted from ?o=, ?w=, or ?workspace_id=.
15-
// Empty if not present or not numeric.
14+
// Empty if not present. Any non-empty value is accepted as-is —
15+
// X-Databricks-Workspace-Id supports both classic numeric workspace IDs
16+
// and non-numeric connection-style identifiers, and the server
17+
// disambiguates.
1618
WorkspaceID string
1719

1820
// AccountID extracted from ?a= or ?account_id=.
@@ -26,9 +28,10 @@ type HostParams struct {
2628
// X-Databricks-Workspace-Id routing header; "o" is the legacy SPOG form and
2729
// stays accepted so URLs already in databricks.yml / shell history keep
2830
// working. When more than one is present, "o" wins to preserve the meaning
29-
// of existing URLs. Workspace IDs must be numeric; non-numeric values are
30-
// ignored. The returned Host has all query parameters and fragments
31-
// stripped.
31+
// of existing URLs. Workspace ID values are passed through unchanged — the
32+
// server-side header accepts both classic numeric IDs and non-numeric
33+
// connection-style identifiers. The returned Host has all query parameters
34+
// and fragments stripped.
3235
func ExtractHostQueryParams(host string) HostParams {
3336
u, err := url.Parse(host)
3437
if err != nil || u.RawQuery == "" {
@@ -39,17 +42,11 @@ func ExtractHostQueryParams(host string) HostParams {
3942

4043
var workspaceID string
4144
if v := q.Get("o"); v != "" {
42-
if _, err := strconv.ParseInt(v, 10, 64); err == nil {
43-
workspaceID = v
44-
}
45+
workspaceID = v
4546
} else if v := q.Get("w"); v != "" {
46-
if _, err := strconv.ParseInt(v, 10, 64); err == nil {
47-
workspaceID = v
48-
}
47+
workspaceID = v
4948
} else if v := q.Get("workspace_id"); v != "" {
50-
if _, err := strconv.ParseInt(v, 10, 64); err == nil {
51-
workspaceID = v
52-
}
49+
workspaceID = v
5350
}
5451

5552
var accountID string

libs/auth/hostparams_test.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,24 @@ func TestExtractHostQueryParams(t *testing.T) {
5353
want: HostParams{Host: "https://spog.example.com"},
5454
},
5555
{
56-
name: "non-numeric ?o= is skipped",
56+
name: "non-numeric ?o= is passed through",
5757
host: "https://spog.example.com/?o=abc",
58-
want: HostParams{Host: "https://spog.example.com"},
58+
want: HostParams{Host: "https://spog.example.com", WorkspaceID: "abc"},
5959
},
6060
{
61-
name: "non-numeric ?w= is skipped",
61+
name: "non-numeric ?w= is passed through",
6262
host: "https://spog.example.com/?w=abc",
63-
want: HostParams{Host: "https://spog.example.com"},
63+
want: HostParams{Host: "https://spog.example.com", WorkspaceID: "abc"},
6464
},
6565
{
66-
name: "non-numeric ?workspace_id= is skipped",
66+
name: "non-numeric ?workspace_id= is passed through",
6767
host: "https://spog.example.com/?workspace_id=abc",
68-
want: HostParams{Host: "https://spog.example.com"},
68+
want: HostParams{Host: "https://spog.example.com", WorkspaceID: "abc"},
69+
},
70+
{
71+
name: "connection-id-style ?w= value passed through",
72+
host: "https://spog.example.com/?w=123e4567-e89b-12d3-a456-426614174000",
73+
want: HostParams{Host: "https://spog.example.com", WorkspaceID: "123e4567-e89b-12d3-a456-426614174000"},
6974
},
7075
{
7176
name: "invalid URL is left unchanged",

0 commit comments

Comments
 (0)