-
Notifications
You must be signed in to change notification settings - Fork 237
Fix incorrect ?w= workspace parameter in resource URLs #6754
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
andrewnester
wants to merge
7
commits into
main
Choose a base branch
from
fix/spog-regression
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9543ba6
Fix incorrect ?w= workspace parameter in resource URLs
andrewnester cc457b6
fix changelog
andrewnester eb42617
update output
andrewnester 1a412f2
fix pr link
andrewnester 902d8a1
fix output
andrewnester c8dc931
error on mismatch
andrewnester 791ce82
update nextchangelog
andrewnester File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| * Fix incorrect `?w=` workspace parameter in resource URLs emitted by `bundle summary`. When a numeric `workspace_id` is explicitly set in `.databrickscfg` or `databricks.yml` and it does not match the connected workspace's org ID, the CLI now returns an error asking the user to remove or correct the value. This prevents stale or mis-scoped workspace IDs from silently embedding the wrong `?w=` in job and pipeline links and causing unexpected workspace switches. ([#6754](https://github.com/databricks/cli/pull/6754)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,8 @@ import ( | |
| "github.com/databricks/cli/bundle" | ||
| "github.com/databricks/cli/bundle/config" | ||
| "github.com/databricks/cli/bundle/config/resources" | ||
| "github.com/databricks/cli/libs/testserver" | ||
| "github.com/databricks/databricks-sdk-go" | ||
| "github.com/databricks/databricks-sdk-go/service/catalog" | ||
| "github.com/databricks/databricks-sdk-go/service/compute" | ||
| "github.com/databricks/databricks-sdk-go/service/jobs" | ||
|
|
@@ -149,3 +151,78 @@ func TestInitializeURLsWithoutOrgId(t *testing.T) { | |
|
|
||
| require.Equal(t, "https://adb-123456.azuredatabricks.net/jobs/1", b.Config.Resources.Jobs["job1"].URL) | ||
| } | ||
|
|
||
| // TestInitializeURLsApplyNonNumericConfigPassedThrough verifies that a | ||
| // non-numeric Config.WorkspaceID (e.g. a UUID connection-style identifier) is | ||
| // passed through unchanged into the ?w= parameter. The numeric-mismatch check | ||
| // is skipped because such IDs cannot be compared against an integer org ID. | ||
| func TestInitializeURLsApplyNonNumericConfigPassedThrough(t *testing.T) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. make this and the case below an acceptance test? Would be simpler? |
||
| server := testserver.New(t) | ||
| testserver.AddDefaultHandlers(server) | ||
|
|
||
| w, err := databricks.NewWorkspaceClient(&databricks.Config{ | ||
| Host: server.URL, | ||
| Token: "testtoken", | ||
| WorkspaceID: "some-uuid-style-id", | ||
| }) | ||
| require.NoError(t, err) | ||
|
|
||
| b := &bundle.Bundle{ | ||
| Config: config.Root{ | ||
| Resources: config.Resources{ | ||
| Jobs: map[string]*resources.Job{ | ||
| "job1": { | ||
| ID: "1", | ||
| JobSettings: jobs.JobSettings{Name: "job1"}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
| b.SetWorkpaceClient(w) | ||
|
|
||
| diags := InitializeURLs().Apply(t.Context(), b) | ||
| require.NoError(t, diags.Error()) | ||
|
|
||
| // UUID flows through into ?w= unchanged — no numeric comparison is possible. | ||
| require.Equal(t, | ||
| server.URL+"/jobs/1?w=some-uuid-style-id", | ||
| b.Config.Resources.Jobs["job1"].URL, | ||
| ) | ||
| } | ||
|
|
||
| // TestInitializeURLsApplyErrorsOnNumericWorkspaceIDMismatch verifies that Apply | ||
| // returns an error when Config.WorkspaceID is a numeric value that differs from | ||
| // the workspace org ID returned by the API. This prevents silently embedding a | ||
| // wrong ?w= parameter in resource URLs that would navigate to an unexpected workspace. | ||
| func TestInitializeURLsApplyErrorsOnNumericWorkspaceIDMismatch(t *testing.T) { | ||
| server := testserver.New(t) | ||
| testserver.AddDefaultHandlers(server) | ||
| // /Me returns X-Databricks-Org-Id: 900800700600. | ||
|
|
||
| w, err := databricks.NewWorkspaceClient(&databricks.Config{ | ||
| Host: server.URL, | ||
| Token: "testtoken", | ||
| WorkspaceID: "12345", // numeric but does not match 900800700600 | ||
| }) | ||
| require.NoError(t, err) | ||
|
|
||
| b := &bundle.Bundle{ | ||
| Config: config.Root{ | ||
| Resources: config.Resources{ | ||
| Jobs: map[string]*resources.Job{ | ||
| "job1": { | ||
| ID: "1", | ||
| JobSettings: jobs.JobSettings{Name: "job1"}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
| b.SetWorkpaceClient(w) | ||
|
|
||
| diags := InitializeURLs().Apply(t.Context(), b) | ||
| require.ErrorContains(t, diags.Error(), "12345") | ||
| require.ErrorContains(t, diags.Error(), "900800700600") | ||
| require.ErrorContains(t, diags.Error(), "disambiguate") | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be able to avoid this additoinal call?