mirror of https://github.com/databricks/cli.git
fixes
This commit is contained in:
parent
2318e09f5d
commit
87f26f69e5
|
@ -1,9 +1,7 @@
|
||||||
|
|
||||||
>>> $CLI bundle validate
|
>>> $CLI bundle validate -o json
|
||||||
Name: double_underscore
|
[
|
||||||
Target: default
|
{
|
||||||
Workspace:
|
"task_key": "test default"
|
||||||
User: $USERNAME
|
}
|
||||||
Path: /Workspace/Users/$USERNAME/.bundle/double_underscore/default
|
]
|
||||||
|
|
||||||
Validation OK!
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
trace $CLI bundle validate
|
trace $CLI bundle validate -o json | jq .resources.jobs.test_job.tasks
|
||||||
|
|
|
@ -1,13 +1,16 @@
|
||||||
package dynvar
|
package dynvar
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/databricks/cli/libs/dyn"
|
"github.com/databricks/cli/libs/dyn"
|
||||||
)
|
)
|
||||||
|
|
||||||
var re = regexp.MustCompile(`\$\{([a-zA-Z]+([-_]*[a-zA-Z0-9]+)*(\.[a-zA-Z]+([-_]*[a-zA-Z0-9]+)*(\[[0-9]+\])*)*(\[[0-9]+\])*)\}`)
|
var (
|
||||||
|
baseVarDef = `[a-zA-Z]+([-_]*[a-zA-Z0-9]+)*`
|
||||||
|
re = regexp.MustCompile(fmt.Sprintf(`\$\{(%s(\.%s(\[[0-9]+\])*)*(\[[0-9]+\])*)\}`, baseVarDef, baseVarDef))
|
||||||
|
)
|
||||||
|
|
||||||
// ref represents a variable reference.
|
// ref represents a variable reference.
|
||||||
// It is a string [dyn.Value] contained in a larger [dyn.Value].
|
// It is a string [dyn.Value] contained in a larger [dyn.Value].
|
||||||
|
@ -23,8 +26,6 @@ type ref struct {
|
||||||
matches [][]string
|
matches [][]string
|
||||||
}
|
}
|
||||||
|
|
||||||
var invalidSeq = []string{"-_", "_-"}
|
|
||||||
|
|
||||||
// newRef returns a new ref if the given [dyn.Value] contains a string
|
// newRef returns a new ref if the given [dyn.Value] contains a string
|
||||||
// with one or more variable references. It returns false if the given
|
// with one or more variable references. It returns false if the given
|
||||||
// [dyn.Value] does not contain variable references.
|
// [dyn.Value] does not contain variable references.
|
||||||
|
@ -45,16 +46,6 @@ func newRef(v dyn.Value) (ref, bool) {
|
||||||
return ref{}, false
|
return ref{}, false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that it does not have invalid sequences such as "-_" or "_-".
|
|
||||||
|
|
||||||
for _, match := range m {
|
|
||||||
for _, seq := range invalidSeq {
|
|
||||||
if strings.Contains(match[1], seq) {
|
|
||||||
return ref{}, false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ref{
|
return ref{
|
||||||
value: v,
|
value: v,
|
||||||
str: s,
|
str: s,
|
||||||
|
|
|
@ -20,6 +20,8 @@ func TestNewRefValidPattern(t *testing.T) {
|
||||||
"${hello-world.world-world}": {"hello-world.world-world"},
|
"${hello-world.world-world}": {"hello-world.world-world"},
|
||||||
"${hello_world.world__world}": {"hello_world.world__world"},
|
"${hello_world.world__world}": {"hello_world.world__world"},
|
||||||
"${hello_world.world--world}": {"hello_world.world--world"},
|
"${hello_world.world--world}": {"hello_world.world--world"},
|
||||||
|
"${hello_world.world-_world}": {"hello_world.world-_world"},
|
||||||
|
"${hello_world.world_-world}": {"hello_world.world_-world"},
|
||||||
} {
|
} {
|
||||||
ref, ok := newRef(dyn.V(in))
|
ref, ok := newRef(dyn.V(in))
|
||||||
require.True(t, ok, "should match valid pattern: %s", in)
|
require.True(t, ok, "should match valid pattern: %s", in)
|
||||||
|
@ -38,7 +40,6 @@ func TestNewRefInvalidPattern(t *testing.T) {
|
||||||
"${_-_._-_.id}", // cannot use _- in sequence
|
"${_-_._-_.id}", // cannot use _- in sequence
|
||||||
"${0helloworld.world-world}", // interpolated first section shouldn't start with number
|
"${0helloworld.world-world}", // interpolated first section shouldn't start with number
|
||||||
"${helloworld.9world-world}", // interpolated second section shouldn't start with number
|
"${helloworld.9world-world}", // interpolated second section shouldn't start with number
|
||||||
"${a-a.a-_a-a.id}", // fails because of -_ in the second segment
|
|
||||||
}
|
}
|
||||||
for _, v := range invalid {
|
for _, v := range invalid {
|
||||||
_, ok := newRef(dyn.V(v))
|
_, ok := newRef(dyn.V(v))
|
||||||
|
|
Loading…
Reference in New Issue