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.
|
||||
clientOnce sync.Once
|
||||
client *databricks.WorkspaceClient
|
||||
clientErr error
|
||||
|
||||
// Files that are synced to the workspace.file_path
|
||||
Files []fileset.File
|
||||
|
@ -134,23 +135,25 @@ func TryLoad(ctx context.Context) (*Bundle, error) {
|
|||
return Load(ctx, root)
|
||||
}
|
||||
|
||||
func (b *Bundle) InitializeWorkspaceClient() (*databricks.WorkspaceClient, error) {
|
||||
client, err := b.Config.Workspace.Client()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot resolve bundle auth configuration: %w", err)
|
||||
}
|
||||
return client, nil
|
||||
func (b *Bundle) WorkspaceClientE() (*databricks.WorkspaceClient, error) {
|
||||
b.clientOnce.Do(func() {
|
||||
var err error
|
||||
b.client, err = b.WorkspaceClientE()
|
||||
if err != nil {
|
||||
b.clientErr = fmt.Errorf("cannot resolve bundle auth configuration: %w", err)
|
||||
}
|
||||
})
|
||||
|
||||
return b.client, b.clientErr
|
||||
}
|
||||
|
||||
func (b *Bundle) WorkspaceClient() *databricks.WorkspaceClient {
|
||||
b.clientOnce.Do(func() {
|
||||
var err error
|
||||
b.client, err = b.InitializeWorkspaceClient()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
})
|
||||
return b.client
|
||||
client, err := b.WorkspaceClientE()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return client
|
||||
}
|
||||
|
||||
// SetWorkpaceClient sets the workspace client for this bundle.
|
||||
|
|
|
@ -209,7 +209,7 @@ func MustWorkspaceClient(cmd *cobra.Command, args []string) error {
|
|||
if b != nil {
|
||||
ctx = context.WithValue(ctx, &configUsed, b.Config.Workspace.Config())
|
||||
cmd.SetContext(ctx)
|
||||
client, err := b.InitializeWorkspaceClient()
|
||||
client, err := b.WorkspaceClientE()
|
||||
if err != nil {
|
||||
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
|
||||
// downstream to initialize a API client.
|
||||
client, err := b.InitializeWorkspaceClient()
|
||||
client, err := b.WorkspaceClientE()
|
||||
if err != nil {
|
||||
return b, diags.Extend(diag.FromErr(err))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue