-
Notifications
You must be signed in to change notification settings - Fork 64
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
Set bundle auth configuration in command context #2195
base: main
Are you sure you want to change the base?
Conversation
cmd/root/bundle_test.go
Outdated
err := cmd.Flag("profile").Value.Set("PROFILE-2") | ||
require.NoError(t, err) | ||
b := setupWithProfile(t, cmd, "PROFILE-1") | ||
func TestBundleConfigureProfile(t *testing.T) { |
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.
While acceptance tests would be better suited for most of these, since this PR changes how auth is loaded I opted to keep the unit tests.
This reverts commit 27f1ae3.
cmd/root/bundle.go
Outdated
|
||
// Set the auth configuration in the command context. This can be used | ||
// downstream to initialize a API client. | ||
client, err := b.InitializeWorkspaceClient() |
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.
There is also WorkspaceClient() which creates and caches the client on bundle.
If that's not necessary, should we clean that up?
Related: Bundle.client, Bundke.clientOnce, can we get rid of those?
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.
If that's not necessary, should we clean that up?
Eyeballing it we could clean that up a bit without issues. It's out of the scope of what this PR is trying to achieve, though.
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.
I can send a follow-up PR to do so.
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.
I think it's in scope, we should not have multiple ways to set up client.
Also, please take a look "variables v2" doc. How would this work if we want to interpolate variables first?
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 not have multiple ways to set up client.
Fair enough. I modified the change to set the client as well. I was hesitant to do this because I don't like how decoupled the client's setting is from its usage, but this change should be safe enough (and covered by tests).
How would this work if we want to interpolate variables first?
We'd need to resolve the variables before we resolve the client.
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.
Changed the approach to still ensure that the client is only initialized / set once. Did so by renaming InitializeWorkspaceClient
to WorkspaceClientE
Changes
This change is required to enable tracking execution time telemetry for bundle commands. In order to track execution time for the command generally, we need to have the databricks auth configuration available at this section of the code:
cli/cmd/root/root.go
Line 99 in 41bbd89
In order to do this we can rely on the
configUsed
context key.Most commands rely on the
root.MustWorkspaceClient
function which automatically sets the client config in theconfigUsed
context key. Bundle commands, however, do not do so. They instead store their workspace clients in the&bundle.Bundle{}
object.With this PR, the
configUsed
context key will be set for allbundle
commands. Functionally nothing changes.Tests
Existing tests. Also manually verified that either
root.MustConfigureBundle
orutils.ConfigureBundleWithVariables
is called for all bundle commands (exceptbundle init
) thus ensuring this context key would be set for all bundle commands.refs for the functions:
root.MustConfigureBundle
:cli/cmd/root/bundle.go
Line 88 in 41bbd89
utils.ConfigureBundleWithVariables
:cli/cmd/bundle/utils/utils.go
Line 19 in 41bbd89