mirror of https://github.com/databricks/cli.git
feat: Use path translations instead of overriding config
This commit is contained in:
parent
518aa14b64
commit
aeb9813d25
|
@ -223,11 +223,8 @@ func (m *applyPresets) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnos
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.IsExplicitlyEnabled((b.Config.Presets.SourceLinkedDeployment)) {
|
if config.IsExplicitlyEnabled((b.Config.Presets.SourceLinkedDeployment)) {
|
||||||
root := b.SyncRootPath
|
isDatabricksWorkspace := dbr.RunsOnRuntime(ctx) && strings.HasPrefix(b.SyncRootPath, "/Workspace/")
|
||||||
isInWorkspace := strings.HasPrefix(root, "/Workspace/")
|
if !isDatabricksWorkspace {
|
||||||
if isInWorkspace && dbr.RunsOnRuntime(ctx) {
|
|
||||||
b.Config.Workspace.FilePath = root
|
|
||||||
} else {
|
|
||||||
disabled := false
|
disabled := false
|
||||||
b.Config.Presets.SourceLinkedDeployment = &disabled
|
b.Config.Presets.SourceLinkedDeployment = &disabled
|
||||||
diags = diags.Extend(diag.Warningf("source-linked deployment is available only in the Databricks Workspace"))
|
diags = diags.Extend(diag.Warningf("source-linked deployment is available only in the Databricks Workspace"))
|
||||||
|
|
|
@ -377,7 +377,6 @@ func TestApplyPresetsSourceLinkedDeployment(t *testing.T) {
|
||||||
testContext := context.Background()
|
testContext := context.Background()
|
||||||
enabled := true
|
enabled := true
|
||||||
disabled := false
|
disabled := false
|
||||||
remotePath := "/Users/files"
|
|
||||||
workspacePath := "/Workspace/user.name@company.com"
|
workspacePath := "/Workspace/user.name@company.com"
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
|
@ -386,7 +385,6 @@ func TestApplyPresetsSourceLinkedDeployment(t *testing.T) {
|
||||||
name string
|
name string
|
||||||
initialValue *bool
|
initialValue *bool
|
||||||
expectedValue *bool
|
expectedValue *bool
|
||||||
expectedFilePath string
|
|
||||||
expectedWarning string
|
expectedWarning string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
|
@ -395,8 +393,6 @@ func TestApplyPresetsSourceLinkedDeployment(t *testing.T) {
|
||||||
ctx: dbr.MockRuntime(testContext, true),
|
ctx: dbr.MockRuntime(testContext, true),
|
||||||
initialValue: &enabled,
|
initialValue: &enabled,
|
||||||
expectedValue: &enabled,
|
expectedValue: &enabled,
|
||||||
expectedFilePath: workspacePath,
|
|
||||||
expectedWarning: "",
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "preset enabled, bundle not in Workspace, databricks runtime",
|
name: "preset enabled, bundle not in Workspace, databricks runtime",
|
||||||
|
@ -404,7 +400,6 @@ func TestApplyPresetsSourceLinkedDeployment(t *testing.T) {
|
||||||
ctx: dbr.MockRuntime(testContext, true),
|
ctx: dbr.MockRuntime(testContext, true),
|
||||||
initialValue: &enabled,
|
initialValue: &enabled,
|
||||||
expectedValue: &disabled,
|
expectedValue: &disabled,
|
||||||
expectedFilePath: remotePath,
|
|
||||||
expectedWarning: "source-linked deployment is available only in the Databricks Workspace",
|
expectedWarning: "source-linked deployment is available only in the Databricks Workspace",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -413,7 +408,6 @@ func TestApplyPresetsSourceLinkedDeployment(t *testing.T) {
|
||||||
ctx: dbr.MockRuntime(testContext, false),
|
ctx: dbr.MockRuntime(testContext, false),
|
||||||
initialValue: &enabled,
|
initialValue: &enabled,
|
||||||
expectedValue: &disabled,
|
expectedValue: &disabled,
|
||||||
expectedFilePath: remotePath,
|
|
||||||
expectedWarning: "source-linked deployment is available only in the Databricks Workspace",
|
expectedWarning: "source-linked deployment is available only in the Databricks Workspace",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -422,7 +416,6 @@ func TestApplyPresetsSourceLinkedDeployment(t *testing.T) {
|
||||||
ctx: dbr.MockRuntime(testContext, true),
|
ctx: dbr.MockRuntime(testContext, true),
|
||||||
initialValue: &disabled,
|
initialValue: &disabled,
|
||||||
expectedValue: &disabled,
|
expectedValue: &disabled,
|
||||||
expectedFilePath: remotePath,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "preset nil, bundle in Workspace, databricks runtime",
|
name: "preset nil, bundle in Workspace, databricks runtime",
|
||||||
|
@ -430,22 +423,17 @@ func TestApplyPresetsSourceLinkedDeployment(t *testing.T) {
|
||||||
ctx: dbr.MockRuntime(testContext, true),
|
ctx: dbr.MockRuntime(testContext, true),
|
||||||
initialValue: nil,
|
initialValue: nil,
|
||||||
expectedValue: nil,
|
expectedValue: nil,
|
||||||
expectedFilePath: remotePath,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
b := &bundle.Bundle{
|
b := &bundle.Bundle{
|
||||||
SyncRoot: vfs.MustNew(tt.bundlePath),
|
|
||||||
SyncRootPath: tt.bundlePath,
|
SyncRootPath: tt.bundlePath,
|
||||||
Config: config.Root{
|
Config: config.Root{
|
||||||
Presets: config.Presets{
|
Presets: config.Presets{
|
||||||
SourceLinkedDeployment: tt.initialValue,
|
SourceLinkedDeployment: tt.initialValue,
|
||||||
},
|
},
|
||||||
Workspace: config.Workspace{
|
|
||||||
FilePath: remotePath,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -458,7 +446,6 @@ func TestApplyPresetsSourceLinkedDeployment(t *testing.T) {
|
||||||
require.Equal(t, tt.expectedWarning, diags[0].Summary)
|
require.Equal(t, tt.expectedWarning, diags[0].Summary)
|
||||||
}
|
}
|
||||||
|
|
||||||
require.Equal(t, tt.expectedFilePath, b.Config.Workspace.FilePath)
|
|
||||||
require.Equal(t, tt.expectedValue, b.Config.Presets.SourceLinkedDeployment)
|
require.Equal(t, tt.expectedValue, b.Config.Presets.SourceLinkedDeployment)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -524,14 +524,12 @@ func TestSourceLinkedDeploymentEnabled(t *testing.T) {
|
||||||
b, diags := processSourceLinkedBundle(t, true)
|
b, diags := processSourceLinkedBundle(t, true)
|
||||||
require.NoError(t, diags.Error())
|
require.NoError(t, diags.Error())
|
||||||
assert.True(t, *b.Config.Presets.SourceLinkedDeployment)
|
assert.True(t, *b.Config.Presets.SourceLinkedDeployment)
|
||||||
assert.Equal(t, b.Config.Workspace.FilePath, b.SyncRootPath)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSourceLinkedDeploymentDisabled(t *testing.T) {
|
func TestSourceLinkedDeploymentDisabled(t *testing.T) {
|
||||||
b, diags := processSourceLinkedBundle(t, false)
|
b, diags := processSourceLinkedBundle(t, false)
|
||||||
require.NoError(t, diags.Error())
|
require.NoError(t, diags.Error())
|
||||||
assert.False(t, *b.Config.Presets.SourceLinkedDeployment)
|
assert.False(t, *b.Config.Presets.SourceLinkedDeployment)
|
||||||
assert.NotEqual(t, b.Config.Workspace.FilePath, b.SyncRootPath)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func processSourceLinkedBundle(t *testing.T, presetEnabled bool) (*bundle.Bundle, diag.Diagnostics) {
|
func processSourceLinkedBundle(t *testing.T, presetEnabled bool) (*bundle.Bundle, diag.Diagnostics) {
|
||||||
|
@ -542,7 +540,6 @@ func processSourceLinkedBundle(t *testing.T, presetEnabled bool) (*bundle.Bundle
|
||||||
b := mockBundle(config.Development)
|
b := mockBundle(config.Development)
|
||||||
|
|
||||||
workspacePath := "/Workspace/lennart@company.com/"
|
workspacePath := "/Workspace/lennart@company.com/"
|
||||||
b.SyncRoot = vfs.MustNew(workspacePath)
|
|
||||||
b.SyncRootPath = workspacePath
|
b.SyncRootPath = workspacePath
|
||||||
b.Config.Presets.SourceLinkedDeployment = &presetEnabled
|
b.Config.Presets.SourceLinkedDeployment = &presetEnabled
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/databricks/cli/bundle"
|
"github.com/databricks/cli/bundle"
|
||||||
|
"github.com/databricks/cli/bundle/config"
|
||||||
"github.com/databricks/cli/libs/diag"
|
"github.com/databricks/cli/libs/diag"
|
||||||
"github.com/databricks/cli/libs/dyn"
|
"github.com/databricks/cli/libs/dyn"
|
||||||
"github.com/databricks/cli/libs/notebook"
|
"github.com/databricks/cli/libs/notebook"
|
||||||
|
@ -103,8 +104,13 @@ func (t *translateContext) rewritePath(
|
||||||
return fmt.Errorf("path %s is not contained in sync root path", localPath)
|
return fmt.Errorf("path %s is not contained in sync root path", localPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prefix remote path with its remote root path.
|
var workspacePath string
|
||||||
remotePath := path.Join(t.b.Config.Workspace.FilePath, filepath.ToSlash(localRelPath))
|
if config.IsExplicitlyEnabled(t.b.Config.Presets.SourceLinkedDeployment) {
|
||||||
|
workspacePath = t.b.SyncRootPath
|
||||||
|
} else {
|
||||||
|
workspacePath = t.b.Config.Workspace.FilePath
|
||||||
|
}
|
||||||
|
remotePath := path.Join(workspacePath, filepath.ToSlash(localRelPath))
|
||||||
|
|
||||||
// Convert local path into workspace path via specified function.
|
// Convert local path into workspace path via specified function.
|
||||||
interp, err := fn(*p, localPath, localRelPath, remotePath)
|
interp, err := fn(*p, localPath, localRelPath, remotePath)
|
||||||
|
|
Loading…
Reference in New Issue