modify approach

This commit is contained in:
Shreyas Goenka 2025-01-21 16:49:51 +01:00
parent c07f1370d2
commit 7855d91597
No known key found for this signature in database
GPG Key ID: 92A07DF49CCB0622
3 changed files with 19 additions and 16 deletions

View File

@ -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() {
if err != nil { var err error
return nil, fmt.Errorf("cannot resolve bundle auth configuration: %w", err) b.client, err = b.WorkspaceClientE()
} if err != nil {
return client, nil b.clientErr = fmt.Errorf("cannot resolve bundle auth configuration: %w", err)
}
})
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 if err != nil {
b.client, err = b.InitializeWorkspaceClient() panic(err)
if err != nil { }
panic(err)
} return client
})
return b.client
} }
// SetWorkpaceClient sets the workspace client for this bundle. // SetWorkpaceClient sets the workspace client for this bundle.

View File

@ -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
} }

View File

@ -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))
} }