Skip to content
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

Move WorkspaceClient to libs/command #2444

Merged
merged 15 commits into from
Mar 7, 2025
Merged

Move WorkspaceClient to libs/command #2444

merged 15 commits into from
Mar 7, 2025

Conversation

shreyas-goenka
Copy link
Contributor

@shreyas-goenka shreyas-goenka commented Mar 6, 2025

Changes

Move the WorkspaceClient reader and setter from the root package to libs/command.

Why

This allows us to read the workspace client set in the context in all CLI packages. This was not possible before because using root.WorkspaceClient would often result in an import cycle.

This would also allow us to standardise reads of the workspace client to be from the context in bundle commands. Today those are read from the bundle object tree instead.

This is a natural followup to #2440.

Tests

Existing tests and one new unit test.

NO_CHANGELOG=true

@shreyas-goenka shreyas-goenka marked this pull request as draft March 6, 2025 17:33
@shreyas-goenka shreyas-goenka changed the title Move WorkspaceClient to libs/command Move WorkspaceClient to libs/command Mar 6, 2025
@shreyas-goenka shreyas-goenka marked this pull request as ready for review March 6, 2025 18:39
)

func SetWorkspaceClient(ctx context.Context, w *databricks.WorkspaceClient) context.Context {
if v := ctx.Value(workspaceClientKey); v != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it might okay to do so, for example, overriding with a different workspace client or smth like this, any thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like having this restriction because ideally every command should only configure a working workspace client once. This keep reasoning about auth simple and would force the upstream code to be designed better.

We can ofcourse remove it if we ever have a usercase where we need to override with a different workspace.

@shreyas-goenka shreyas-goenka added this pull request to the merge queue Mar 7, 2025
Merged via the queue into main with commit af3914d Mar 7, 2025
10 checks passed
@shreyas-goenka shreyas-goenka deleted the wc-command branch March 7, 2025 16:55
@@ -240,7 +241,7 @@ func new{{.PascalName}}() *cobra.Command {
cmd.PreRunE = root.Must{{if .Service.IsAccounts}}Account{{else}}Workspace{{end}}Client
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The MustZZZ functions should also move to the new pkg.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants