Skip to content

Commit

Permalink
Adding support for experimental 'metadata' block.
Browse files Browse the repository at this point in the history
This adds support for putting top level fields into a 'metadata' block for organization purposes.

It also ships a 'conf' field to the publish endpoint containing the full contents of the `massdriver.yaml` file.

The goal is that the CLI will not need to be kept aware of changes to the spec and will simply ship the config off to the pkg manager.

This will make it easier to make changes to the structure of massdriver YAML files since it doesnt have to be changed in the pkg manager and the CLI.

TODOs:

* [ ] remove TODOs / notes
* [ ] Fix validate schema logic (bundle.LintSchema)
* [ ] Move JSON Schemas to gh json-schemas repo, pull for CLI & backend
* [ ] Add code to 'upgrade' schema definitions
* [ ] Remove legacy
  • Loading branch information
coryodaniel committed May 25, 2023
1 parent 17d1ae5 commit 32e1700
Show file tree
Hide file tree
Showing 10 changed files with 723 additions and 233 deletions.
12 changes: 12 additions & 0 deletions cmd/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,18 @@ func unmarshalBundle(readDirectory string, cmd *cobra.Command, fs afero.Fs) (*bu
return nil, err
}

// TODO: Begin experimental conf/metadata change
rawConfig := map[string]interface{}{}

err = yaml.Unmarshal(file, &rawConfig)

if err != nil {
return nil, err
}

unmarshalledBundle.Conf = rawConfig
// TODO: End experimental conf/metadata change

applyOverrides(unmarshalledBundle, cmd)

if unmarshalledBundle.IsApplication() {
Expand Down
2 changes: 2 additions & 0 deletions internal/bundle/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type Bundle struct {
Connections map[string]interface{} `json:"connections" yaml:"connections"`
UI map[string]interface{} `json:"ui" yaml:"ui"`
AppSpec *AppSpec `json:"app,omitempty" yaml:"app,omitempty"`
Conf map[string]interface{}
}

type AppSpec struct {
Expand Down Expand Up @@ -54,6 +55,7 @@ func (b *Bundle) GenerateBundlePublishBody(srcDir string, fs afero.Fs) (restclie
body.ConnectionsSchema = b.Connections
body.ParamsSchema = b.Params
body.UISchema = b.UI
body.Conf = b.Conf

var appSpec map[string]interface{}

Expand Down
3 changes: 1 addition & 2 deletions internal/bundle/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ import (
)

//go:embed schemas/bundle-schema.json
//go:embed schemas/meta-schema.json
var bundleFS embed.FS

func (b *Bundle) LintSchema() error {
schemaBytes, _ := bundleFS.ReadFile("schemas/bundle-schema.json")
documentLoader := gojsonschema.NewGoLoader(b)
documentLoader := gojsonschema.NewGoLoader(b.Conf)
schemaLoader := gojsonschema.NewBytesLoader(schemaBytes)

result, err := gojsonschema.Validate(schemaLoader, documentLoader)
Expand Down
6 changes: 6 additions & 0 deletions internal/bundle/lint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ func TestLintSchema(t *testing.T) {
bun *bundle.Bundle
err error
}

// TODO: this is currently failing because we are using b.Conf to get actualy files to pass, but this
// is mocking w/o it... fix this code to use the actual massdriver.yaml
tests := []test{
{
name: "Valid pass",
Expand All @@ -27,6 +30,7 @@ func TestLintSchema(t *testing.T) {
Connections: map[string]interface{}{},
Artifacts: map[string]interface{}{},
UI: map[string]interface{}{},
Steps: []bundle.Step{},
},
err: nil,
},
Expand All @@ -41,8 +45,10 @@ func TestLintSchema(t *testing.T) {
Connections: map[string]interface{}{},
Artifacts: map[string]interface{}{},
UI: map[string]interface{}{},
Steps: []bundle.Step{},
},
err: errors.New(`massdriver.yaml has schema violations:
- (root): Must validate one and only one schema (oneOf)
- schema: schema must be one of the following: "draft-07"
`),
},
Expand Down
Loading

0 comments on commit 32e1700

Please sign in to comment.