This commit is contained in:
Andrew Nester 2025-01-27 15:34:57 +00:00
parent 2318e09f5d
commit 87f26f69e5
No known key found for this signature in database
GPG Key ID: 12BC628A44B7DA57
4 changed files with 14 additions and 24 deletions

View File

@ -1,9 +1,7 @@
>>> $CLI bundle validate
Name: double_underscore
Target: default
Workspace:
User: $USERNAME
Path: /Workspace/Users/$USERNAME/.bundle/double_underscore/default
Validation OK!
>>> $CLI bundle validate -o json
[
{
"task_key": "test default"
}
]

View File

@ -1 +1 @@
trace $CLI bundle validate
trace $CLI bundle validate -o json | jq .resources.jobs.test_job.tasks

View File

@ -1,13 +1,16 @@
package dynvar
import (
"fmt"
"regexp"
"strings"
"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.
// It is a string [dyn.Value] contained in a larger [dyn.Value].
@ -23,8 +26,6 @@ type ref struct {
matches [][]string
}
var invalidSeq = []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
// [dyn.Value] does not contain variable references.
@ -45,16 +46,6 @@ func newRef(v dyn.Value) (ref, bool) {
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{
value: v,
str: s,

View File

@ -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"},
} {
ref, ok := newRef(dyn.V(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
"${0helloworld.world-world}", // interpolated first 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 {
_, ok := newRef(dyn.V(v))