mirror of https://github.com/databricks/cli.git
Set bundle auth configuration in command context
This commit is contained in:
parent
41bbd89257
commit
bf68318a0c
|
@ -1,26 +0,0 @@
|
||||||
package mutator
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
|
|
||||||
"github.com/databricks/cli/bundle"
|
|
||||||
"github.com/databricks/cli/libs/diag"
|
|
||||||
)
|
|
||||||
|
|
||||||
type initializeWorkspaceClient struct{}
|
|
||||||
|
|
||||||
func InitializeWorkspaceClient() bundle.Mutator {
|
|
||||||
return &initializeWorkspaceClient{}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *initializeWorkspaceClient) Name() string {
|
|
||||||
return "InitializeWorkspaceClient"
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply initializes the workspace client for the bundle. We do this here so
|
|
||||||
// downstream calls to b.WorkspaceClient() do not panic if there's an error in the
|
|
||||||
// auth configuration.
|
|
||||||
func (m *initializeWorkspaceClient) Apply(_ context.Context, b *bundle.Bundle) diag.Diagnostics {
|
|
||||||
_, err := b.InitializeWorkspaceClient()
|
|
||||||
return diag.FromErr(err)
|
|
||||||
}
|
|
|
@ -81,6 +81,19 @@ func configureBundle(cmd *cobra.Command, b *bundle.Bundle) (*bundle.Bundle, diag
|
||||||
|
|
||||||
// Configure the workspace profile if the flag has been set.
|
// Configure the workspace profile if the flag has been set.
|
||||||
diags = diags.Extend(configureProfile(cmd, b))
|
diags = diags.Extend(configureProfile(cmd, b))
|
||||||
|
if diags.HasError() {
|
||||||
|
return b, diags
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the auth configuration in the command context. This can be used
|
||||||
|
// downstream to initialize a API client.
|
||||||
|
client, err := b.InitializeWorkspaceClient()
|
||||||
|
if err != nil {
|
||||||
|
return b, diags.Extend(diag.FromErr(err))
|
||||||
|
}
|
||||||
|
ctx = context.WithValue(ctx, &configUsed, client.Config)
|
||||||
|
cmd.SetContext(ctx)
|
||||||
|
|
||||||
return b, diags
|
return b, diags
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue