2023-02-20 18:42:55 +00:00
|
|
|
package files
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2023-04-18 14:55:06 +00:00
|
|
|
"fmt"
|
2023-02-20 18:42:55 +00:00
|
|
|
|
2023-05-16 16:35:39 +00:00
|
|
|
"github.com/databricks/cli/bundle"
|
|
|
|
"github.com/databricks/cli/libs/cmdio"
|
2024-03-25 14:18:47 +00:00
|
|
|
"github.com/databricks/cli/libs/diag"
|
2023-12-21 08:00:37 +00:00
|
|
|
"github.com/databricks/cli/libs/log"
|
2023-02-20 18:42:55 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type upload struct{}
|
|
|
|
|
|
|
|
func (m *upload) Name() string {
|
|
|
|
return "files.Upload"
|
|
|
|
}
|
|
|
|
|
2024-03-25 14:18:47 +00:00
|
|
|
func (m *upload) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics {
|
2023-12-21 08:00:37 +00:00
|
|
|
cmdio.LogString(ctx, fmt.Sprintf("Uploading bundle files to %s...", b.Config.Workspace.FilePath))
|
2024-04-18 15:13:16 +00:00
|
|
|
sync, err := GetSync(ctx, bundle.ReadOnly(b))
|
2023-02-20 18:42:55 +00:00
|
|
|
if err != nil {
|
2024-03-25 14:18:47 +00:00
|
|
|
return diag.FromErr(err)
|
2023-02-20 18:42:55 +00:00
|
|
|
}
|
|
|
|
|
2024-06-17 09:48:52 +00:00
|
|
|
b.Files, err = sync.RunOnce(ctx)
|
2023-02-20 18:42:55 +00:00
|
|
|
if err != nil {
|
2024-03-25 14:18:47 +00:00
|
|
|
return diag.FromErr(err)
|
2023-02-20 18:42:55 +00:00
|
|
|
}
|
|
|
|
|
2023-12-21 08:00:37 +00:00
|
|
|
log.Infof(ctx, "Uploaded bundle files")
|
2023-05-24 12:45:19 +00:00
|
|
|
return nil
|
2023-02-20 18:42:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func Upload() bundle.Mutator {
|
|
|
|
return &upload{}
|
|
|
|
}
|