Skip to content

Commit c5ae950

Browse files
committed
Revert bundle initialize_urls changes to avoid URL output regression
The shared workspaceurls lib uses a stricter adb- hostname check for workspace ID detection. This is correct but changes bundle summary URL output on non-Azure workspaces (adds ?o= where it was previously omitted due to a loose strings.Contains match). That behavior change should be a separate PR with its own integration test updates. experimental open still uses the shared lib with the strict check.
1 parent 59d2959 commit c5ae950

File tree

2 files changed

+23
-27
lines changed

2 files changed

+23
-27
lines changed

bundle/config/mutator/initialize_urls.go

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ package mutator
22

33
import (
44
"context"
5+
"net/url"
6+
"strconv"
7+
"strings"
58

69
"github.com/databricks/cli/bundle"
710
"github.com/databricks/cli/libs/diag"
8-
"github.com/databricks/cli/libs/workspaceurls"
911
)
1012

1113
type initializeURLs struct{}
@@ -23,24 +25,38 @@ func (m *initializeURLs) Name() string {
2325
}
2426

2527
func (m *initializeURLs) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics {
26-
workspaceID, err := b.WorkspaceClient().CurrentWorkspaceID(ctx)
28+
workspaceId, err := b.WorkspaceClient().CurrentWorkspaceID(ctx)
2729
if err != nil {
2830
return diag.FromErr(err)
2931
}
32+
orgId := strconv.FormatInt(workspaceId, 10)
3033
host := b.WorkspaceClient().Config.CanonicalHostName()
31-
err = initializeForWorkspace(b, workspaceID, host)
34+
err = initializeForWorkspace(b, orgId, host)
3235
if err != nil {
3336
return diag.FromErr(err)
3437
}
3538
return nil
3639
}
3740

38-
func initializeForWorkspace(b *bundle.Bundle, workspaceID int64, host string) error {
39-
baseURL, err := workspaceurls.WorkspaceBaseURL(host, workspaceID)
41+
func initializeForWorkspace(b *bundle.Bundle, orgId, host string) error {
42+
baseURL, err := url.Parse(host)
4043
if err != nil {
4144
return err
4245
}
4346

47+
// Add ?o=<workspace id> only if <workspace id> wasn't in the subdomain already.
48+
// The ?o= is needed when vanity URLs / legacy workspace URLs are used.
49+
// If it's not needed we prefer to leave it out since these URLs are rather
50+
// long for most terminals.
51+
//
52+
// See https://docs.databricks.com/en/workspace/workspace-details.html for
53+
// further reading about the '?o=' suffix.
54+
if !strings.Contains(baseURL.Hostname(), orgId) {
55+
values := baseURL.Query()
56+
values.Add("o", orgId)
57+
baseURL.RawQuery = values.Encode()
58+
}
59+
4460
for _, group := range b.Config.Resources.AllResources() {
4561
for _, r := range group.Resources {
4662
r.InitializeURL(*baseURL)

bundle/config/mutator/initialize_urls_test.go

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func TestInitializeURLs(t *testing.T) {
109109
"dashboard1": "https://mycompany.databricks.com/dashboardsv3/01ef8d56871e1d50ae30ce7375e42478/published?o=123456",
110110
}
111111

112-
err := initializeForWorkspace(b, 123456, "https://mycompany.databricks.com/")
112+
err := initializeForWorkspace(b, "123456", "https://mycompany.databricks.com/")
113113
require.NoError(t, err)
114114

115115
for _, group := range b.Config.Resources.AllResources() {
@@ -133,28 +133,8 @@ func TestInitializeURLsWithoutOrgId(t *testing.T) {
133133
},
134134
}
135135

136-
err := initializeForWorkspace(b, 123456, "https://adb-123456.azuredatabricks.net/")
136+
err := initializeForWorkspace(b, "123456", "https://adb-123456.azuredatabricks.net/")
137137
require.NoError(t, err)
138138

139139
require.Equal(t, "https://adb-123456.azuredatabricks.net/jobs/1", b.Config.Resources.Jobs["job1"].URL)
140140
}
141-
142-
func TestInitializeURLsWithWorkspaceIDInVanityHostname(t *testing.T) {
143-
b := &bundle.Bundle{
144-
Config: config.Root{
145-
Resources: config.Resources{
146-
Jobs: map[string]*resources.Job{
147-
"job1": {
148-
BaseResource: resources.BaseResource{ID: "1"},
149-
JobSettings: jobs.JobSettings{Name: "job1"},
150-
},
151-
},
152-
},
153-
},
154-
}
155-
156-
err := initializeForWorkspace(b, 123456, "https://workspace-123456.example.com/")
157-
require.NoError(t, err)
158-
159-
require.Equal(t, "https://workspace-123456.example.com/jobs/1?o=123456", b.Config.Resources.Jobs["job1"].URL)
160-
}

0 commit comments

Comments
 (0)