From 32e17005f77434f07eeb70bea069091e91ca648f Mon Sep 17 00:00:00 2001 From: Cory O'Daniel Date: Wed, 24 May 2023 17:20:43 -0700 Subject: [PATCH] Adding support for experimental 'metadata' block. 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 --- cmd/bundle.go | 12 + internal/bundle/bundle.go | 2 + internal/bundle/lint.go | 3 +- internal/bundle/lint_test.go | 6 + internal/bundle/schemas/bundle-schema.json | 479 ++++++++++++------ internal/bundle/schemas/bundle-v1-schema.json | 157 ++++++ internal/bundle/schemas/bundle-v2-schema.json | 183 +++++++ internal/bundle/schemas/meta-schema.json | 80 --- internal/commands/publish/publisher_test.go | 33 ++ internal/restclient/client.go | 1 + 10 files changed, 723 insertions(+), 233 deletions(-) create mode 100644 internal/bundle/schemas/bundle-v1-schema.json create mode 100644 internal/bundle/schemas/bundle-v2-schema.json delete mode 100755 internal/bundle/schemas/meta-schema.json diff --git a/cmd/bundle.go b/cmd/bundle.go index 24182ea..4356b08 100644 --- a/cmd/bundle.go +++ b/cmd/bundle.go @@ -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() { diff --git a/internal/bundle/bundle.go b/internal/bundle/bundle.go index 2642e8e..cd38663 100644 --- a/internal/bundle/bundle.go +++ b/internal/bundle/bundle.go @@ -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 { @@ -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{} diff --git a/internal/bundle/lint.go b/internal/bundle/lint.go index 4a283d0..b11d657 100644 --- a/internal/bundle/lint.go +++ b/internal/bundle/lint.go @@ -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) diff --git a/internal/bundle/lint_test.go b/internal/bundle/lint_test.go index 9254c56..eda8763 100644 --- a/internal/bundle/lint_test.go +++ b/internal/bundle/lint_test.go @@ -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", @@ -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, }, @@ -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" `), }, diff --git a/internal/bundle/schemas/bundle-schema.json b/internal/bundle/schemas/bundle-schema.json index 0f760a9..7065b63 100644 --- a/internal/bundle/schemas/bundle-schema.json +++ b/internal/bundle/schemas/bundle-schema.json @@ -1,177 +1,354 @@ { "$schema": "https://json-schema.org/draft-07/schema", "type": "object", - "title": "Bundle", - "required": [ - "params", - "connections", - "artifacts", - "ui", - "schema", - "description", - "access", - "type" + "oneOf": [ + { + "$ref": "#/$defs/bundle-v1" + }, + { + "$ref": "#/$defs/bundle-v2" + } ], - "properties": { - "app": { - "title": "Application Configuration", + "$defs": { + "bundle-v1": { + "$schema": "https://json-schema.org/draft-07/schema", "type": "object", + "title": "Bundle", + "required": [ + "params", + "connections", + "artifacts", + "ui", + "schema", + "description", + "access", + "type" + ], "properties": { - "secrets": { - "title": "Secrets", - "description": "", + "app": { + "title": "Application Configuration", "type": "object", - "propertyNames": { - "pattern": "^[A-Za-z_][A-Za-z0-9_]*$" - }, - "patternProperties": { - "^.*$": { + "properties": { + "secrets": { + "title": "Secrets", + "description": "", "type": "object", - "additionalProperties": false, - "properties": { - "required": { - "type": "boolean", - "default": false - }, - "json": { - "type": "boolean", - "default": false - }, - "title": { - "type": "string" - }, - "description": { + "propertyNames": { + "pattern": "^[A-Za-z_][A-Za-z0-9_]*$" + }, + "patternProperties": { + "^.*$": { + "type": "object", + "additionalProperties": false, + "properties": { + "required": { + "type": "boolean", + "default": false + }, + "json": { + "type": "boolean", + "default": false + }, + "title": { + "type": "string" + }, + "description": { + "type": "string" + } + } + } + } + }, + "policies": { + "title": "IAM Permissions", + "description": "Map param and connection values to IAM Permissions & Policies for your application.", + "type": "array", + "items": { + "type": "string", + "pattern": "^\\.[a-zA-Z0-9._-]*$" + } + }, + "envs": { + "title": "Environment variables", + "description": "Map param and connection values to environment variables with JQ for processing.", + "type": "object", + "propertyNames": { + "pattern": "^[a-zA-Z_][a-zA-Z0-9_]*$" + }, + "patternProperties": { + "^[a-zA-Z_][a-zA-Z0-9_]*$": { "type": "string" } } } } }, - "policies": { - "title": "IAM Permissions", - "description": "Map param and connection values to IAM Permissions & Policies for your application.", + "name": { + "title": "Title", + "type": "string", + "description": "The name of the bundle. This will be prefixed with your organization name upon publishing.", + "pattern": "^[a-z][a-z0-9-]+[a-z0-9]$", + "minLength": 3, + "maxLength": 53 + }, + "schema": { + "title": "JSON Schema Schema", + "type": "string", + "description": "The JSON Schema used to define the bundle.", + "enum": [ + "draft-07" + ] + }, + "description": { + "title": "Description", + "description": "A description of the bundle.", + "type": "string", + "minLength": 10, + "maxLength": 1024 + }, + "source_url": { + "title": "Source URL", + "type": "string", + "description": "Link to the bundle source code." + }, + "access": { + "title": "Access", + "type": "string", + "description": "The access level of the bundle. Private bundles will only be accessible by the organization it is published under.", + "enum": [ + "public", + "private" + ] + }, + "type": { + "title": "Type", + "type": "string", + "description": "The type of bundle: infrastructure or application.", + "enum": [ + "infrastructure", + "application" + ] + }, + "params": { + "type": "object", + "title": "Input Parameters", + "description": "Input parameters for the bundle. These will be converted to input variables for your IaC module." + }, + "connections": { + "type": "object", + "title": "Input Connections", + "description": "Input connections for this bundle. Determines which artifacts from other bundles this bundle depends on. These will be converted to input variables for your IaC module." + }, + "artifacts": { + "type": "object", + "title": "Output Artifacts", + "description": "Cloud resources created by this bundle that are available to be used as input connections to other bundles. See: https://github.com/massdriver-cloud/artifact-definitions" + }, + "ui": { + "type": "object", + "description": "RJSF UI Schema for advanced control over the UI. See https://react-jsonschema-form.readthedocs.io/en/docs/api-reference/uiSchema/#uischema" + }, + "steps": { "type": "array", + "description": "Massdriver provisioning steps", "items": { - "type": "string", - "pattern": "^\\.[a-zA-Z0-9._-]*$" + "type": "object", + "properties": { + "path": { + "type": "string", + "description": "Path to the IaC directory" + }, + "provisioner": { + "type": "string", + "description": "Provisioner type to use for step" + } + } + } + } + } + }, + "bundle-v2": { + "$schema": "https://json-schema.org/draft-07/schema", + "type": "object", + "title": "Bundle", + "required": [ + "params", + "connections", + "artifacts", + "ui", + "metadata" + ], + "properties": { + "metadata": { + "type": "object", + "title": "Metadata", + "required": [ + "name", + "schema", + "description", + "access", + "type" + ], + "properties": { + "name": { + "title": "Name", + "type": "string", + "description": "The name of the bundle. This will be prefixed with your organization name upon publishing.", + "pattern": "^[a-z][a-z0-9-]+[a-z0-9]$", + "minLength": 3, + "maxLength": 53 + }, + "schema": { + "title": "JSON Schema Version", + "type": "string", + "description": "The JSON Schema used to define the bundle.", + "enum": [ + "draft-07" + ] + }, + "description": { + "title": "Description", + "description": "A description of the bundle.", + "type": "string", + "minLength": 10, + "maxLength": 1024 + }, + "source_url": { + "title": "Source URL", + "type": "string", + "description": "Link to the bundle source code." + }, + "access": { + "title": "Access", + "type": "string", + "description": "The access level of the bundle. Private bundles will only be accessible by the organization it is published under.", + "enum": [ + "public", + "private" + ] + }, + "type": { + "title": "Type", + "type": "string", + "description": "The type of bundle", + "enum": [ + "infrastructure", + "application" + ] + }, + "tags": { + "title": "Tags", + "type": "array", + "description": "List of short descriptors for bundle search", + "items": { + "type": "string" + } + }, + "clouds": { + "title": "Cloud", + "type": "array", + "description": "List of clouds this bundle supports", + "items": { + "type": "string" + } + } } }, - "envs": { - "title": "Environment variables", - "description": "Map param and connection values to environment variables with JQ for processing.", + "app": { + "title": "Application Configuration", "type": "object", - "propertyNames": { - "pattern": "^[a-zA-Z_][a-zA-Z0-9_]*$" - }, - "patternProperties": { - "^[a-zA-Z_][a-zA-Z0-9_]*$": { - "type": "string" + "properties": { + "secrets": { + "title": "Secrets", + "description": "", + "type": "object", + "propertyNames": { + "pattern": "^[A-Za-z_][A-Za-z0-9_]*$" + }, + "patternProperties": { + "^.*$": { + "type": "object", + "additionalProperties": false, + "properties": { + "required": { + "type": "boolean", + "default": false + }, + "json": { + "type": "boolean", + "default": false + }, + "title": { + "type": "string" + }, + "description": { + "type": "string" + } + } + } + } + }, + "policies": { + "title": "IAM Permissions", + "description": "Map param and connection values to IAM Permissions & Policies for your application.", + "type": "array", + "items": { + "type": "string", + "pattern": "^\\.[a-zA-Z0-9._-]*$" + } + }, + "envs": { + "title": "Environment variables", + "description": "Map param and connection values to environment variables with JQ for processing.", + "type": "object", + "propertyNames": { + "pattern": "^[a-zA-Z_][a-zA-Z0-9_]*$" + }, + "patternProperties": { + "^[a-zA-Z_][a-zA-Z0-9_]*$": { + "type": "string" + } + } + } + } + }, + "params": { + "type": "object", + "title": "Input Parameters", + "description": "Input parameters for the bundle. These will be converted to input variables for your IaC module." + }, + "connections": { + "type": "object", + "title": "Input Connections", + "description": "Input connections for this bundle. Determines which artifacts from other bundles this bundle depends on. These will be converted to input variables for your IaC module." + }, + "artifacts": { + "type": "object", + "title": "Output Artifacts", + "description": "Cloud resources created by this bundle that are available to be used as input connections to other bundles. See: https://github.com/massdriver-cloud/artifact-definitions" + }, + "ui": { + "type": "object", + "description": "RJSF UI Schema for advanced control over the UI. See https://react-jsonschema-form.readthedocs.io/en/docs/api-reference/uiSchema/#uischema" + }, + "steps": { + "type": "array", + "description": "Massdriver provisioning steps", + "items": { + "type": "object", + "properties": { + "path": { + "type": "string", + "description": "Path to the IaC directory" + }, + "provisioner": { + "type": "string", + "description": "Provisioner type to use for step" + } } } } } - }, - "name": { - "title": "Title", - "type": "string", - "description": "The name of the bundle. This will be prefixed with your organization name upon publishing.", - "pattern": "^[a-z][a-z0-9-]+[a-z0-9]$", - "minLength": 3, - "maxLength": 53 - }, - "schema": { - "title": "JSON Schema Schema", - "type": "string", - "description": "The JSON Schema used to define the bundle.", - "enum": [ - "draft-07" - ] - }, - "description": { - "title": "Description", - "description": "A description of the bundle.", - "type": "string", - "minLength": 10, - "maxLength": 1024 - }, - "source_url": { - "title": "Source URL", - "type": "string", - "description": "Link to the bundle source code." - }, - "access": { - "title": "Access", - "type": "string", - "description": "The access level of the bundle. Private bundles will only be accessible by the organization it is published under.", - "enum": [ - "public", - "private" - ] - }, - "type": { - "title": "Type", - "type": "string", - "description": "The type of bundle: infrastructure (legacy term: bundle) or application.", - "enum": [ - "infrastructure", - "application" - ] - }, - "tags": { - "title": "Tags", - "type": "array", - "description": "List of short descriptors for bundle search", - "items": { - "type": "string", - "enum": [ - "compute", - "networking", - "database", - "storage", - "event driven", - "serverless" - ] - } - }, - "cloud": { - "title": "Cloud", - "type": "array", - "description": "List of clouds this bundle supports", - "items": { - "type": "string", - "enum": [ - "AWS", - "GCP", - "Azure", - "Kubernetes" - ] - } - }, - "runtime": { - "title": "Runtime", - "type": "string", - "description": "For applications, the runtime this application provides", - "enum": [ - "VM", - "Kubernetes", - "Function" - ] - }, - "params": { - "title": "Input Parameters", - "description": "Input parameters for the bundle. These will be converted to input variables for your IaC module." - }, - "connections": { - "title": "Input Connections", - "description": "Input connections for this bundle. Determines which artifacts from other bundles this bundle depends on. These will be converted to input variables for your IaC module." - }, - "artifacts": { - "title": "Output Artifacts", - "description": "Cloud resources created by this bundle that are available to be used as input connections to other bundles. See: https://github.com/massdriver-cloud/artifact-definitions" - }, - "ui": { - "type": "object", - "description": "RJSF UI Schema for advanced control over the UI. See https://react-jsonschema-form.readthedocs.io/en/docs/api-reference/uiSchema/#uischema" } } } diff --git a/internal/bundle/schemas/bundle-v1-schema.json b/internal/bundle/schemas/bundle-v1-schema.json new file mode 100644 index 0000000..75d4549 --- /dev/null +++ b/internal/bundle/schemas/bundle-v1-schema.json @@ -0,0 +1,157 @@ +{ + "$schema": "https://json-schema.org/draft-07/schema", + "type": "object", + "title": "Bundle", + "required": [ + "params", + "connections", + "artifacts", + "ui", + "schema", + "description", + "access", + "type" + ], + "properties": { + "app": { + "title": "Application Configuration", + "type": "object", + "properties": { + "secrets": { + "title": "Secrets", + "description": "", + "type": "object", + "propertyNames": { + "pattern": "^[A-Za-z_][A-Za-z0-9_]*$" + }, + "patternProperties": { + "^.*$": { + "type": "object", + "additionalProperties": false, + "properties": { + "required": { + "type": "boolean", + "default": false + }, + "json": { + "type": "boolean", + "default": false + }, + "title": { + "type": "string" + }, + "description": { + "type": "string" + } + } + } + } + }, + "policies": { + "title": "IAM Permissions", + "description": "Map param and connection values to IAM Permissions & Policies for your application.", + "type": "array", + "items": { + "type": "string", + "pattern": "^\\.[a-zA-Z0-9._-]*$" + } + }, + "envs": { + "title": "Environment variables", + "description": "Map param and connection values to environment variables with JQ for processing.", + "type": "object", + "propertyNames": { + "pattern": "^[a-zA-Z_][a-zA-Z0-9_]*$" + }, + "patternProperties": { + "^[a-zA-Z_][a-zA-Z0-9_]*$": { + "type": "string" + } + } + } + } + }, + "name": { + "title": "Title", + "type": "string", + "description": "The name of the bundle. This will be prefixed with your organization name upon publishing.", + "pattern": "^[a-z][a-z0-9-]+[a-z0-9]$", + "minLength": 3, + "maxLength": 53 + }, + "schema": { + "title": "JSON Schema Schema", + "type": "string", + "description": "The JSON Schema used to define the bundle.", + "enum": [ + "draft-07" + ] + }, + "description": { + "title": "Description", + "description": "A description of the bundle.", + "type": "string", + "minLength": 10, + "maxLength": 1024 + }, + "source_url": { + "title": "Source URL", + "type": "string", + "description": "Link to the bundle source code." + }, + "access": { + "title": "Access", + "type": "string", + "description": "The access level of the bundle. Private bundles will only be accessible by the organization it is published under.", + "enum": [ + "public", + "private" + ] + }, + "type": { + "title": "Type", + "type": "string", + "description": "The type of bundle: infrastructure or application.", + "enum": [ + "infrastructure", + "application" + ] + }, + "params": { + "type": "object", + "title": "Input Parameters", + "description": "Input parameters for the bundle. These will be converted to input variables for your IaC module." + }, + "connections": { + "type": "object", + "title": "Input Connections", + "description": "Input connections for this bundle. Determines which artifacts from other bundles this bundle depends on. These will be converted to input variables for your IaC module." + }, + "artifacts": { + "type": "object", + "title": "Output Artifacts", + "description": "Cloud resources created by this bundle that are available to be used as input connections to other bundles. See: https://github.com/massdriver-cloud/artifact-definitions" + }, + "ui": { + "type": "object", + "description": "RJSF UI Schema for advanced control over the UI. See https://react-jsonschema-form.readthedocs.io/en/docs/api-reference/uiSchema/#uischema" + }, + "steps": { + "type": "array", + "description": "Massdriver provisioning steps", + "items": { + "type": "object", + "properties": { + "path": { + "type": "string", + "description": "Path to the IaC directory" + }, + "provisioner": { + "type": "string", + "description": "Provisioner type to use for step" + } + } + } + } + } +} diff --git a/internal/bundle/schemas/bundle-v2-schema.json b/internal/bundle/schemas/bundle-v2-schema.json new file mode 100644 index 0000000..a33d46d --- /dev/null +++ b/internal/bundle/schemas/bundle-v2-schema.json @@ -0,0 +1,183 @@ +{ + "$schema": "https://json-schema.org/draft-07/schema", + "type": "object", + "title": "Bundle", + "required": [ + "params", + "connections", + "artifacts", + "ui", + "metadata" + ], + "properties": { + "metadata": { + "type": "object", + "title": "Metadata", + "required": [ + "name", + "schema", + "description", + "access", + "type" + ], + "properties": { + "name": { + "title": "Name", + "type": "string", + "description": "The name of the bundle. This will be prefixed with your organization name upon publishing.", + "pattern": "^[a-z][a-z0-9-]+[a-z0-9]$", + "minLength": 3, + "maxLength": 53 + }, + "schema": { + "title": "JSON Schema Version", + "type": "string", + "description": "The JSON Schema used to define the bundle.", + "enum": [ + "draft-07" + ] + }, + "description": { + "title": "Description", + "description": "A description of the bundle.", + "type": "string", + "minLength": 10, + "maxLength": 1024 + }, + "source_url": { + "title": "Source URL", + "type": "string", + "description": "Link to the bundle source code." + }, + "access": { + "title": "Access", + "type": "string", + "description": "The access level of the bundle. Private bundles will only be accessible by the organization it is published under.", + "enum": [ + "public", + "private" + ] + }, + "type": { + "title": "Type", + "type": "string", + "description": "The type of bundle", + "enum": [ + "infrastructure", + "application" + ] + }, + "tags": { + "title": "Tags", + "type": "array", + "description": "List of short descriptors for bundle search", + "items": { + "type": "string" + } + }, + "clouds": { + "title": "Cloud", + "type": "array", + "description": "List of clouds this bundle supports", + "items": { + "type": "string" + } + } + } + }, + "app": { + "title": "Application Configuration", + "type": "object", + "properties": { + "secrets": { + "title": "Secrets", + "description": "", + "type": "object", + "propertyNames": { + "pattern": "^[A-Za-z_][A-Za-z0-9_]*$" + }, + "patternProperties": { + "^.*$": { + "type": "object", + "additionalProperties": false, + "properties": { + "required": { + "type": "boolean", + "default": false + }, + "json": { + "type": "boolean", + "default": false + }, + "title": { + "type": "string" + }, + "description": { + "type": "string" + } + } + } + } + }, + "policies": { + "title": "IAM Permissions", + "description": "Map param and connection values to IAM Permissions & Policies for your application.", + "type": "array", + "items": { + "type": "string", + "pattern": "^\\.[a-zA-Z0-9._-]*$" + } + }, + "envs": { + "title": "Environment variables", + "description": "Map param and connection values to environment variables with JQ for processing.", + "type": "object", + "propertyNames": { + "pattern": "^[a-zA-Z_][a-zA-Z0-9_]*$" + }, + "patternProperties": { + "^[a-zA-Z_][a-zA-Z0-9_]*$": { + "type": "string" + } + } + } + } + }, + "params": { + "type": "object", + "title": "Input Parameters", + "description": "Input parameters for the bundle. These will be converted to input variables for your IaC module." + }, + "connections": { + "type": "object", + "title": "Input Connections", + "description": "Input connections for this bundle. Determines which artifacts from other bundles this bundle depends on. These will be converted to input variables for your IaC module." + }, + "artifacts": { + "type": "object", + "title": "Output Artifacts", + "description": "Cloud resources created by this bundle that are available to be used as input connections to other bundles. See: https://github.com/massdriver-cloud/artifact-definitions" + }, + "ui": { + "type": "object", + "description": "RJSF UI Schema for advanced control over the UI. See https://react-jsonschema-form.readthedocs.io/en/docs/api-reference/uiSchema/#uischema" + }, + "steps": { + "type": "array", + "description": "Massdriver provisioning steps", + "items": { + "type": "object", + "properties": { + "path": { + "type": "string", + "description": "Path to the IaC directory" + }, + "provisioner": { + "type": "string", + "description": "Provisioner type to use for step" + } + } + } + } + } +} diff --git a/internal/bundle/schemas/meta-schema.json b/internal/bundle/schemas/meta-schema.json deleted file mode 100755 index 3a7f55c..0000000 --- a/internal/bundle/schemas/meta-schema.json +++ /dev/null @@ -1,80 +0,0 @@ -{ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://json-schema.org/draft/2020-12/schema", - "$vocabulary": { - "https://json-schema.org/draft/2020-12/vocab/core": true, - "https://json-schema.org/draft/2020-12/vocab/applicator": true, - "https://json-schema.org/draft/2020-12/vocab/unevaluated": true, - "https://json-schema.org/draft/2020-12/vocab/validation": true, - "https://json-schema.org/draft/2020-12/vocab/meta-data": true, - "https://json-schema.org/draft/2020-12/vocab/format-annotation": true, - "https://json-schema.org/draft/2020-12/vocab/content": true - }, - "$dynamicAnchor": "meta", - "title": "Core and Validation specifications meta-schema", - "allOf": [ - { - "$ref": "meta/core" - }, - { - "$ref": "meta/applicator" - }, - { - "$ref": "meta/unevaluated" - }, - { - "$ref": "meta/validation" - }, - { - "$ref": "meta/meta-data" - }, - { - "$ref": "meta/format-annotation" - }, - { - "$ref": "meta/content" - } - ], - "type": [ - "object", - "boolean" - ], - "$comment": "This meta-schema also defines keywords that have appeared in previous drafts in order to prevent incompatible extensions as they remain in common use.", - "properties": { - "definitions": { - "$comment": "\"definitions\" has been replaced by \"$defs\".", - "type": "object", - "additionalProperties": { - "$dynamicRef": "#meta" - }, - "deprecated": true, - "default": {} - }, - "dependencies": { - "$comment": "\"dependencies\" has been split and replaced by \"dependentSchemas\" and \"dependentRequired\" in order to serve their differing semantics.", - "type": "object", - "additionalProperties": { - "anyOf": [ - { - "$dynamicRef": "#meta" - }, - { - "$ref": "meta/validation#/$defs/stringArray" - } - ] - }, - "deprecated": true, - "default": {} - }, - "$recursiveAnchor": { - "$comment": "\"$recursiveAnchor\" has been replaced by \"$dynamicAnchor\".", - "$ref": "meta/core#/$defs/anchorString", - "deprecated": true - }, - "$recursiveRef": { - "$comment": "\"$recursiveRef\" has been replaced by \"$dynamicRef\".", - "$ref": "meta/core#/$defs/uriReferenceString", - "deprecated": true - } - } -} diff --git a/internal/commands/publish/publisher_test.go b/internal/commands/publish/publisher_test.go index a91cc4b..24898c4 100644 --- a/internal/commands/publish/publisher_test.go +++ b/internal/commands/publish/publisher_test.go @@ -29,6 +29,39 @@ func TestPublish(t *testing.T) { wantBody string } tests := []test{ + { + name: "Includes the original massdriver.yaml in the request body", + path: "./templates", + guideType: "", + bundle: bundle.Bundle{ + Name: "the-bundle", + Description: "something", + SourceURL: "github.com/some-repo", + Type: "bundle", + Access: "public", + Artifacts: map[string]interface{}{ + "artifacts": "foo", + }, + Connections: map[string]interface{}{ + "connections": "bar", + }, + Params: map[string]interface{}{ + "params": map[string]string{ + "hello": "world", + }, + }, + UI: map[string]interface{}{ + "ui": "baz", + }, + AppSpec: nil, + Conf: map[string]interface{}{ + "metadata": map[string]interface{}{ + "foo": "bar", + }, + }, + }, + wantBody: `{"name":"the-bundle","description":"something","type":"bundle","source_url":"github.com/some-repo","access":"public","artifacts_schema":{"artifacts":"foo"},"connections_schema":{"connections":"bar"},"params_schema":{"params":{"hello":"world"}},"ui_schema":{"ui":"baz"},"conf":{"metadata":{"foo":"bar"}}}`, + }, { name: "Does not submit an app block field if one does not exist", path: "./templates", diff --git a/internal/restclient/client.go b/internal/restclient/client.go index e2f1409..a71fe2b 100644 --- a/internal/restclient/client.go +++ b/internal/restclient/client.go @@ -33,6 +33,7 @@ type PublishPost struct { UISchema map[string]interface{} `json:"ui_schema"` OperatorGuide []byte `json:"operator_guide,omitempty"` AppSpec map[string]interface{} `json:"app,omitempty"` + Conf map[string]interface{} `json:"conf,omitempty"` } type PublishResponse struct {