mirror of https://github.com/databricks/cli.git
Simplified isFullVariableOverrideDef implementation (#1791)
## Changes Simplified isFullVariableOverrideDef implementation Follow up on https://github.com/databricks/cli/pull/1787
This commit is contained in:
parent
94d8c3ba1e
commit
66f2ba64a8
|
@ -406,7 +406,14 @@ func (r *Root) MergeTargetOverrides(name string) error {
|
||||||
return r.updateWithDynamicValue(root)
|
return r.updateWithDynamicValue(root)
|
||||||
}
|
}
|
||||||
|
|
||||||
var variableKeywords = []string{"default", "lookup"}
|
var allowedVariableDefinitions = []([]string){
|
||||||
|
{"default", "type", "description"},
|
||||||
|
{"default", "type"},
|
||||||
|
{"default", "description"},
|
||||||
|
{"lookup", "description"},
|
||||||
|
{"default"},
|
||||||
|
{"lookup"},
|
||||||
|
}
|
||||||
|
|
||||||
// isFullVariableOverrideDef checks if the given value is a full syntax varaible override.
|
// isFullVariableOverrideDef checks if the given value is a full syntax varaible override.
|
||||||
// A full syntax variable override is a map with either 1 of 2 keys.
|
// A full syntax variable override is a map with either 1 of 2 keys.
|
||||||
|
@ -423,42 +430,21 @@ func isFullVariableOverrideDef(v dyn.Value) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the map has 3 keys, they should be "description", "type" and "default" or "lookup"
|
for _, keys := range allowedVariableDefinitions {
|
||||||
if mv.Len() == 3 {
|
if len(keys) != mv.Len() {
|
||||||
if _, ok := mv.GetByString("type"); ok {
|
continue
|
||||||
if _, ok := mv.GetByString("description"); ok {
|
|
||||||
if _, ok := mv.GetByString("default"); ok {
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if the keys are the same.
|
||||||
|
match := true
|
||||||
|
for _, key := range keys {
|
||||||
|
if _, ok := mv.GetByString(key); !ok {
|
||||||
|
match = false
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
if match {
|
||||||
}
|
|
||||||
|
|
||||||
// If the map has 2 keys, one of them should be "default" or "lookup" and the other is "type" or "description"
|
|
||||||
if mv.Len() == 2 {
|
|
||||||
if _, ok := mv.GetByString("type"); ok {
|
|
||||||
if _, ok := mv.GetByString("default"); ok {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, ok := mv.GetByString("description"); ok {
|
|
||||||
if _, ok := mv.GetByString("default"); ok {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, ok := mv.GetByString("lookup"); ok {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, keyword := range variableKeywords {
|
|
||||||
if _, ok := mv.GetByString(keyword); ok {
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue