mirror of https://github.com/databricks/cli.git
fixes
This commit is contained in:
parent
87b1c7a402
commit
9675aa7294
|
@ -22,8 +22,8 @@ func (m *prependWorkspacePrefix) Name() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
var skipPrefixes = []string{
|
var skipPrefixes = []string{
|
||||||
"/Workspace",
|
"/Workspace/",
|
||||||
"/Volumes",
|
"/Volumes/",
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *prependWorkspacePrefix) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics {
|
func (m *prependWorkspacePrefix) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics {
|
||||||
|
|
|
@ -23,24 +23,26 @@ func (m *noWorkspacePrefixUsed) Name() string {
|
||||||
|
|
||||||
func (m *noWorkspacePrefixUsed) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics {
|
func (m *noWorkspacePrefixUsed) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics {
|
||||||
diags := diag.Diagnostics{}
|
diags := diag.Diagnostics{}
|
||||||
prefixes := []string{
|
paths := []string{
|
||||||
"/Workspace/${workspace.root_path}",
|
"/Workspace/${workspace.root_path}",
|
||||||
"/Workspace/${workspace.file_path}",
|
"/Workspace/${workspace.file_path}",
|
||||||
"/Workspace/${workspace.artifact_path}",
|
"/Workspace/${workspace.artifact_path}",
|
||||||
"/Workspace/${workspace.state_path}",
|
"/Workspace/${workspace.state_path}",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Walk through the bundle configuration, check all the string leaves and
|
||||||
|
// see if any of the prefixes are used in the remote path.
|
||||||
_, err := dyn.Walk(b.Config.Value(), func(p dyn.Path, v dyn.Value) (dyn.Value, error) {
|
_, err := dyn.Walk(b.Config.Value(), func(p dyn.Path, v dyn.Value) (dyn.Value, error) {
|
||||||
vv, ok := v.AsString()
|
vv, ok := v.AsString()
|
||||||
if !ok {
|
if !ok {
|
||||||
return v, nil
|
return v, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, prefix := range prefixes {
|
for _, path := range paths {
|
||||||
if strings.HasPrefix(vv, prefix) {
|
if strings.Contains(vv, path) {
|
||||||
diags = append(diags, diag.Diagnostic{
|
diags = append(diags, diag.Diagnostic{
|
||||||
Severity: diag.Error,
|
Severity: diag.Error,
|
||||||
Summary: fmt.Sprintf("%s used in the remote path %s. Please change to use %s instead", prefix, vv, strings.ReplaceAll(vv, "/Workspace/", "")),
|
Summary: fmt.Sprintf("%s used in the remote path %s. Please change to use %s instead", path, vv, strings.ReplaceAll(vv, "/Workspace/", "")),
|
||||||
Locations: v.Locations(),
|
Locations: v.Locations(),
|
||||||
Paths: []dyn.Path{p},
|
Paths: []dyn.Path{p},
|
||||||
})
|
})
|
||||||
|
|
|
@ -45,6 +45,8 @@ func Initialize() bundle.Mutator {
|
||||||
mutator.DefineDefaultWorkspacePaths(),
|
mutator.DefineDefaultWorkspacePaths(),
|
||||||
mutator.PrependWorkspacePrefix(),
|
mutator.PrependWorkspacePrefix(),
|
||||||
|
|
||||||
|
// This mutator needs to be run before variable interpolation because it
|
||||||
|
// searches for strings with variable references in them.
|
||||||
validate.NoWorkspacePrefixUsed(),
|
validate.NoWorkspacePrefixUsed(),
|
||||||
|
|
||||||
mutator.SetVariables(),
|
mutator.SetVariables(),
|
||||||
|
|
Loading…
Reference in New Issue