mirror of https://github.com/databricks/cli.git
modify approach
This commit is contained in:
parent
c07f1370d2
commit
7855d91597
|
@ -72,6 +72,7 @@ type Bundle struct {
|
||||||
// It can be initialized on demand after loading the configuration.
|
// It can be initialized on demand after loading the configuration.
|
||||||
clientOnce sync.Once
|
clientOnce sync.Once
|
||||||
client *databricks.WorkspaceClient
|
client *databricks.WorkspaceClient
|
||||||
|
clientErr error
|
||||||
|
|
||||||
// Files that are synced to the workspace.file_path
|
// Files that are synced to the workspace.file_path
|
||||||
Files []fileset.File
|
Files []fileset.File
|
||||||
|
@ -134,23 +135,25 @@ func TryLoad(ctx context.Context) (*Bundle, error) {
|
||||||
return Load(ctx, root)
|
return Load(ctx, root)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bundle) InitializeWorkspaceClient() (*databricks.WorkspaceClient, error) {
|
func (b *Bundle) WorkspaceClientE() (*databricks.WorkspaceClient, error) {
|
||||||
client, err := b.Config.Workspace.Client()
|
b.clientOnce.Do(func() {
|
||||||
|
var err error
|
||||||
|
b.client, err = b.WorkspaceClientE()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("cannot resolve bundle auth configuration: %w", err)
|
b.clientErr = fmt.Errorf("cannot resolve bundle auth configuration: %w", err)
|
||||||
}
|
}
|
||||||
return client, nil
|
})
|
||||||
|
|
||||||
|
return b.client, b.clientErr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bundle) WorkspaceClient() *databricks.WorkspaceClient {
|
func (b *Bundle) WorkspaceClient() *databricks.WorkspaceClient {
|
||||||
b.clientOnce.Do(func() {
|
client, err := b.WorkspaceClientE()
|
||||||
var err error
|
|
||||||
b.client, err = b.InitializeWorkspaceClient()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
})
|
|
||||||
return b.client
|
return client
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetWorkpaceClient sets the workspace client for this bundle.
|
// SetWorkpaceClient sets the workspace client for this bundle.
|
||||||
|
|
|
@ -209,7 +209,7 @@ func MustWorkspaceClient(cmd *cobra.Command, args []string) error {
|
||||||
if b != nil {
|
if b != nil {
|
||||||
ctx = context.WithValue(ctx, &configUsed, b.Config.Workspace.Config())
|
ctx = context.WithValue(ctx, &configUsed, b.Config.Workspace.Config())
|
||||||
cmd.SetContext(ctx)
|
cmd.SetContext(ctx)
|
||||||
client, err := b.InitializeWorkspaceClient()
|
client, err := b.WorkspaceClientE()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,7 +87,7 @@ func configureBundle(cmd *cobra.Command, b *bundle.Bundle) (*bundle.Bundle, diag
|
||||||
|
|
||||||
// Set the auth configuration in the command context. This can be used
|
// Set the auth configuration in the command context. This can be used
|
||||||
// downstream to initialize a API client.
|
// downstream to initialize a API client.
|
||||||
client, err := b.InitializeWorkspaceClient()
|
client, err := b.WorkspaceClientE()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return b, diags.Extend(diag.FromErr(err))
|
return b, diags.Extend(diag.FromErr(err))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue