Skip to content

Commit 6da9c9a

Browse files
authored
config: also extract ?w= from Host URL (#1704)
## Changes Follow-up to #1699, which started promoting `?o=`/`?workspace_id=` and `?a=`/`?account_id=` from `Config.Host` into `Config.WorkspaceID`/`Config.AccountID` during `fixHostIfNeeded`. `?w=` is the unified workspace addressing query parameter that supersedes `?o=`/`?workspace_id=`. It accepts a broader range of workspace identifier formats — both classic numeric workspace IDs and other identifier formats the server understands — so the numeric-only validation applied to `?o=`/`?workspace_id=` is intentionally not applied to `?w=`. Priority order in `workspaceIDFromQuery` becomes: 1. `?w=` — any non-empty value 2. `?o=` — numeric only 3. `?workspace_id=` — numeric only Existing `Config.WorkspaceID` is still never overwritten. ## Tests Four cases added to the existing `TestConfig_fixHostIfNeeded_extractsWorkspaceIDFromQuery` table-driven test: - `?w=12345` is promoted to `Config.WorkspaceID`. - `?w=7a99b43c-b46c-432b-b0a7-814217701909` (UUID-shaped) is promoted as-is. - `?w=` takes precedence over `?o=` when both appear. - An existing `Config.WorkspaceID` is preserved when `?w=` is present. `make fmt test lint` clean. NO_CHANGELOG=true Signed-off-by: Divyansh Vijayvergia <divyansh.vijayvergia@databricks.com>
1 parent 59ad59e commit 6da9c9a

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

config/config.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,14 @@ func (c *Config) fixHostIfNeeded() error {
653653
}
654654

655655
func workspaceIDFromQuery(q url.Values) string {
656+
// ?w= is the unified workspace addressing query parameter. It supersedes
657+
// the older ?o=/?workspace_id= forms and accepts a broader range of
658+
// workspace identifier formats — both classic numeric workspace IDs and
659+
// other identifier formats the server understands — so we don't apply the
660+
// numeric-only validation that we use for ?o=/?workspace_id=.
661+
if v := q.Get("w"); v != "" {
662+
return v
663+
}
656664
for _, key := range []string{"o", "workspace_id"} {
657665
v := q.Get(key)
658666
if v == "" {

config/config_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,6 +1362,31 @@ func TestConfig_fixHostIfNeeded_extractsWorkspaceIDFromQuery(t *testing.T) {
13621362
host: "https://acme.databricks.net/?o=notanumber",
13631363
wantHost: "https://acme.databricks.net",
13641364
},
1365+
{
1366+
name: "?w= with numeric value promoted to WorkspaceID",
1367+
host: "https://acme.databricks.net/?w=12345",
1368+
wantHost: "https://acme.databricks.net",
1369+
wantWorkspaceID: "12345",
1370+
},
1371+
{
1372+
name: "?w= with non-numeric value promoted to WorkspaceID",
1373+
host: "https://acme.databricks.net/?w=7a99b43c-b46c-432b-b0a7-814217701909",
1374+
wantHost: "https://acme.databricks.net",
1375+
wantWorkspaceID: "7a99b43c-b46c-432b-b0a7-814217701909",
1376+
},
1377+
{
1378+
name: "?w= takes precedence over ?o=",
1379+
host: "https://acme.databricks.net/?w=12345&o=99999",
1380+
wantHost: "https://acme.databricks.net",
1381+
wantWorkspaceID: "12345",
1382+
},
1383+
{
1384+
name: "existing WorkspaceID is preserved over ?w=",
1385+
host: "https://acme.databricks.net/?w=12345",
1386+
workspaceID: "99999",
1387+
wantHost: "https://acme.databricks.net",
1388+
wantWorkspaceID: "99999",
1389+
},
13651390
{
13661391
name: "host without query is unchanged",
13671392
host: "https://acme.databricks.net",

0 commit comments

Comments
 (0)