mirror of https://github.com/databricks/cli.git
Alias variables block in the `Target` struct (#1748)
## Changes
This PR aliases and overrides the schema associated with the variables
block in `target` to allow for directly specifying a variable value in
the JSON schema (without an levels of nesting). This is needed because
this direct value is resolved by dynamically parsing the configuration
tree.
ca6332a5a4/bundle/config/root.go (L424)
## Tests
Existing unit tests.
This commit is contained in:
parent
28b39cd3f7
commit
5d2c0e3885
|
@ -139,7 +139,7 @@ func TestRootMergeTargetOverridesWithVariables(t *testing.T) {
|
|||
},
|
||||
Targets: map[string]*Target{
|
||||
"development": {
|
||||
Variables: map[string]*variable.Variable{
|
||||
Variables: map[string]*variable.TargetVariable{
|
||||
"foo": {
|
||||
Default: "bar",
|
||||
Description: "wrong",
|
||||
|
|
|
@ -38,7 +38,26 @@ type Target struct {
|
|||
// Override default values or lookup name for defined variables
|
||||
// Does not permit defining new variables or redefining existing ones
|
||||
// in the scope of an target
|
||||
Variables map[string]*variable.Variable `json:"variables,omitempty"`
|
||||
//
|
||||
// There are two valid ways to define a variable override in a target:
|
||||
// 1. Direct value override. We normalize this to the variable.Variable
|
||||
// struct format when loading the configuration YAML:
|
||||
//
|
||||
// variables:
|
||||
// foo: "value"
|
||||
//
|
||||
// 2. Override matching the variable.Variable struct.
|
||||
//
|
||||
// variables:
|
||||
// foo:
|
||||
// default: "value"
|
||||
//
|
||||
// OR
|
||||
//
|
||||
// variables:
|
||||
// foo:
|
||||
// lookup: "resource_name"
|
||||
Variables map[string]*variable.TargetVariable `json:"variables,omitempty"`
|
||||
|
||||
Git Git `json:"git,omitempty"`
|
||||
|
||||
|
|
|
@ -16,6 +16,11 @@ const (
|
|||
VariableTypeComplex VariableType = "complex"
|
||||
)
|
||||
|
||||
// We alias it here to override the JSON schema associated with a variable value
|
||||
// in a target override. This is because we allow for directly specifying the value
|
||||
// in addition to the variable.Variable struct format in a target override.
|
||||
type TargetVariable Variable
|
||||
|
||||
// An input variable for the bundle config
|
||||
type Variable struct {
|
||||
// A type of the variable. This is used to validate the value of the variable
|
||||
|
|
|
@ -21,6 +21,22 @@ func addInterpolationPatterns(typ reflect.Type, s jsonschema.Schema) jsonschema.
|
|||
return s
|
||||
}
|
||||
|
||||
// The variables block in a target override allows for directly specifying
|
||||
// the value of the variable.
|
||||
if typ == reflect.TypeOf(variable.TargetVariable{}) {
|
||||
return jsonschema.Schema{
|
||||
AnyOf: []jsonschema.Schema{
|
||||
// We keep the original schema so that autocomplete suggestions
|
||||
// continue to work.
|
||||
s,
|
||||
// All values are valid for a variable value, be it primitive types
|
||||
// like string/bool or complex ones like objects/arrays. Thus we override
|
||||
// the schema to allow all valid JSON values.
|
||||
{},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
switch s.Type {
|
||||
case jsonschema.ArrayType, jsonschema.ObjectType:
|
||||
// arrays and objects can have complex variable values specified.
|
||||
|
|
|
@ -642,6 +642,29 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
"variable.TargetVariable": {
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"default": {
|
||||
"$ref": "#/$defs/interface"
|
||||
},
|
||||
"description": {
|
||||
"$ref": "#/$defs/string"
|
||||
},
|
||||
"lookup": {
|
||||
"$ref": "#/$defs/github.com/databricks/cli/bundle/config/variable.Lookup"
|
||||
},
|
||||
"type": {
|
||||
"$ref": "#/$defs/github.com/databricks/cli/bundle/config/variable.VariableType"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
{}
|
||||
]
|
||||
},
|
||||
"variable.Variable": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
@ -995,7 +1018,7 @@
|
|||
"$ref": "#/$defs/github.com/databricks/cli/bundle/config.Sync"
|
||||
},
|
||||
"variables": {
|
||||
"$ref": "#/$defs/map/github.com/databricks/cli/bundle/config/variable.Variable"
|
||||
"$ref": "#/$defs/map/github.com/databricks/cli/bundle/config/variable.TargetVariable"
|
||||
},
|
||||
"workspace": {
|
||||
"$ref": "#/$defs/github.com/databricks/cli/bundle/config.Workspace"
|
||||
|
@ -4993,6 +5016,20 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
"variable.TargetVariable": {
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"$ref": "#/$defs/github.com/databricks/cli/bundle/config/variable.TargetVariable"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"pattern": "\\$\\{(var(\\.[a-zA-Z]+([-_]?[a-zA-Z0-9]+)*(\\[[0-9]+\\])*)+)\\}"
|
||||
}
|
||||
]
|
||||
},
|
||||
"variable.Variable": {
|
||||
"anyOf": [
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue