mirror of https://github.com/databricks/cli.git
cleanu unused code
This commit is contained in:
parent
d07192fe03
commit
fcdccb359a
|
@ -52,7 +52,8 @@ func addInterpolationPatterns(_ reflect.Type, s jsonschema.Schema) jsonschema.Sc
|
||||||
// as well. Make sure to pull those in.
|
// as well. Make sure to pull those in.
|
||||||
// TODO: Add unit tests for all permutations of structs, maps and slices for the FromType
|
// TODO: Add unit tests for all permutations of structs, maps and slices for the FromType
|
||||||
// method.
|
// method.
|
||||||
// TODO: Note the minor regression of losing the bundle descriptions
|
// TODO: Note the minor regression of losing the bundle descriptions.
|
||||||
|
// TODO: Ensure descriptions work for target resources section.
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if len(os.Args) != 2 {
|
if len(os.Args) != 2 {
|
||||||
|
|
|
@ -1,13 +1,7 @@
|
||||||
package bundle
|
package bundle
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"reflect"
|
|
||||||
|
|
||||||
"github.com/databricks/cli/bundle/config"
|
|
||||||
"github.com/databricks/cli/bundle/schema"
|
|
||||||
"github.com/databricks/cli/cmd/root"
|
"github.com/databricks/cli/cmd/root"
|
||||||
"github.com/databricks/cli/libs/jsonschema"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -19,31 +13,31 @@ func newSchemaCommand() *cobra.Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.RunE = func(cmd *cobra.Command, args []string) error {
|
cmd.RunE = func(cmd *cobra.Command, args []string) error {
|
||||||
// Load embedded schema descriptions.
|
// // Load embedded schema descriptions.
|
||||||
docs, err := schema.LoadBundleDescriptions()
|
// docs, err := schema.LoadBundleDescriptions()
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
return err
|
// return err
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Generate the JSON schema from the bundle configuration struct in Go.
|
// // Generate the JSON schema from the bundle configuration struct in Go.
|
||||||
schema, err := schema.New(reflect.TypeOf(config.Root{}), docs)
|
// schema, err := schema.New(reflect.TypeOf(config.Root{}), docs)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
return err
|
// return err
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Target variable value overrides can be primitives, maps or sequences.
|
// // Target variable value overrides can be primitives, maps or sequences.
|
||||||
// Set an empty schema for them.
|
// // Set an empty schema for them.
|
||||||
err = schema.SetByPath("targets.*.variables.*", jsonschema.Schema{})
|
// err = schema.SetByPath("targets.*.variables.*", jsonschema.Schema{})
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
return err
|
// return err
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Print the JSON schema to stdout.
|
// // Print the JSON schema to stdout.
|
||||||
result, err := json.MarshalIndent(schema, "", " ")
|
// result, err := json.MarshalIndent(schema, "", " ")
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
return err
|
// return err
|
||||||
}
|
// }
|
||||||
cmd.OutOrStdout().Write(result)
|
// cmd.OutOrStdout().Write(result)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,20 +6,12 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
"slices"
|
"slices"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/databricks/cli/internal/build"
|
"github.com/databricks/cli/internal/build"
|
||||||
"golang.org/x/mod/semver"
|
"golang.org/x/mod/semver"
|
||||||
)
|
)
|
||||||
|
|
||||||
// defines schema for a json object
|
// defines schema for a json object
|
||||||
// TODO: Remove pointers from properties and AnyOf.
|
|
||||||
// TODO: Can / should we emulate dyn.V here in having a readonly model for the data
|
|
||||||
// structure? Makes it easier to reason about.
|
|
||||||
//
|
|
||||||
// Any performance issues can be addressed by storing the schema
|
|
||||||
//
|
|
||||||
// as an embedded file.
|
|
||||||
type Schema struct {
|
type Schema struct {
|
||||||
// TODO: Comments for this field
|
// TODO: Comments for this field
|
||||||
Definitions any `json:"$defs,omitempty"`
|
Definitions any `json:"$defs,omitempty"`
|
||||||
|
@ -38,6 +30,7 @@ type Schema struct {
|
||||||
|
|
||||||
// Schemas for the fields of an struct. The keys are the first json tag.
|
// Schemas for the fields of an struct. The keys are the first json tag.
|
||||||
// The values are the schema for the type of the field
|
// The values are the schema for the type of the field
|
||||||
|
// TODO: Followup: Make this a map[string]Schema
|
||||||
Properties map[string]*Schema `json:"properties,omitempty"`
|
Properties map[string]*Schema `json:"properties,omitempty"`
|
||||||
|
|
||||||
// The schema for all values of an array
|
// The schema for all values of an array
|
||||||
|
@ -95,48 +88,12 @@ func (s *Schema) ParseString(v string) (any, error) {
|
||||||
return fromString(v, s.Type)
|
return fromString(v, s.Type)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Schema) getByPath(path string) (*Schema, error) {
|
|
||||||
p := strings.Split(path, ".")
|
|
||||||
|
|
||||||
res := s
|
|
||||||
for _, node := range p {
|
|
||||||
if node == "*" {
|
|
||||||
res = res.AdditionalProperties.(*Schema)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
var ok bool
|
|
||||||
res, ok = res.Properties[node]
|
|
||||||
if !ok {
|
|
||||||
return nil, fmt.Errorf("property %q not found in schema. Query path: %s", node, path)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return res, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Schema) GetByPath(path string) (Schema, error) {
|
|
||||||
v, err := s.getByPath(path)
|
|
||||||
if err != nil {
|
|
||||||
return Schema{}, err
|
|
||||||
}
|
|
||||||
return *v, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Schema) SetByPath(path string, v Schema) error {
|
|
||||||
dst, err := s.getByPath(path)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
*dst = v
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type Type string
|
type Type string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// Default zero value of a schema. This does not correspond to a type in the
|
// Default zero value of a schema. This does not correspond to a type in the
|
||||||
// JSON schema spec and is an internal type defined for convenience.
|
// JSON schema spec and is an internal type defined for convenience.
|
||||||
InvalidType Type = "invalid"
|
InvalidType Type = "invalid"
|
||||||
NullType Type = "null"
|
|
||||||
BooleanType Type = "boolean"
|
BooleanType Type = "boolean"
|
||||||
StringType Type = "string"
|
StringType Type = "string"
|
||||||
NumberType Type = "number"
|
NumberType Type = "number"
|
||||||
|
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSchemaValidateTypeNames(t *testing.T) {
|
func TestSchemaValidateTypeNames(t *testing.T) {
|
||||||
|
@ -340,58 +339,3 @@ func testSchema() *Schema {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSchemaGetByPath(t *testing.T) {
|
|
||||||
s := testSchema()
|
|
||||||
|
|
||||||
ss, err := s.GetByPath("int_val")
|
|
||||||
require.NoError(t, err)
|
|
||||||
assert.Equal(t, Schema{
|
|
||||||
Type: IntegerType,
|
|
||||||
Default: int64(123),
|
|
||||||
}, ss)
|
|
||||||
|
|
||||||
ss, err = s.GetByPath("string_val")
|
|
||||||
require.NoError(t, err)
|
|
||||||
assert.Equal(t, Schema{
|
|
||||||
Type: StringType,
|
|
||||||
}, ss)
|
|
||||||
|
|
||||||
ss, err = s.GetByPath("object_val.bar")
|
|
||||||
require.NoError(t, err)
|
|
||||||
assert.Equal(t, Schema{
|
|
||||||
Type: StringType,
|
|
||||||
Default: "baz",
|
|
||||||
}, ss)
|
|
||||||
|
|
||||||
ss, err = s.GetByPath("object_val.*.foo")
|
|
||||||
require.NoError(t, err)
|
|
||||||
assert.Equal(t, Schema{
|
|
||||||
Type: StringType,
|
|
||||||
Default: "zab",
|
|
||||||
}, ss)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSchemaSetByPath(t *testing.T) {
|
|
||||||
s := testSchema()
|
|
||||||
|
|
||||||
err := s.SetByPath("int_val", Schema{
|
|
||||||
Type: IntegerType,
|
|
||||||
Default: int64(456),
|
|
||||||
})
|
|
||||||
require.NoError(t, err)
|
|
||||||
assert.Equal(t, int64(456), s.Properties["int_val"].Default)
|
|
||||||
|
|
||||||
err = s.SetByPath("object_val.*.foo", Schema{
|
|
||||||
Type: StringType,
|
|
||||||
Default: "zooby",
|
|
||||||
})
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
ns, err := s.GetByPath("object_val.*.foo")
|
|
||||||
require.NoError(t, err)
|
|
||||||
assert.Equal(t, Schema{
|
|
||||||
Type: StringType,
|
|
||||||
Default: "zooby",
|
|
||||||
}, ns)
|
|
||||||
}
|
|
||||||
|
|
|
@ -461,7 +461,7 @@ func TestPromptIsSkippedAnyOf(t *testing.T) {
|
||||||
Default: "hello-world",
|
Default: "hello-world",
|
||||||
Extension: jsonschema.Extension{
|
Extension: jsonschema.Extension{
|
||||||
SkipPromptIf: &jsonschema.Schema{
|
SkipPromptIf: &jsonschema.Schema{
|
||||||
AnyOf: []*jsonschema.Schema{
|
AnyOf: []jsonschema.Schema{
|
||||||
{
|
{
|
||||||
Properties: map[string]*jsonschema.Schema{
|
Properties: map[string]*jsonschema.Schema{
|
||||||
"abc": {
|
"abc": {
|
||||||
|
|
Loading…
Reference in New Issue