Skip to content

Commit

Permalink
corrects JSON schema for bundle vars (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
UncleGedd authored Sep 13, 2023
1 parent 9c9b816 commit e591ad4
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 24 deletions.
17 changes: 9 additions & 8 deletions src/pkg/bundle/common_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package bundle

import (
"github.com/defenseunicorns/uds-cli/src/types"
"testing"

"github.com/defenseunicorns/uds-cli/src/types"
)

func Test_validateBundleVars(t *testing.T) {
Expand All @@ -20,8 +21,8 @@ func Test_validateBundleVars(t *testing.T) {
description: "import matches export",
args: args{
packages: []types.BundleZarfPackage{
{Name: "foo", Exports: []types.BundleVariable{{Name: "foo"}}},
{Name: "bar", Imports: []types.BundleVariable{{Name: "foo", Package: "foo"}}},
{Name: "foo", Exports: []types.BundleVariableExport{{Name: "foo"}}},
{Name: "bar", Imports: []types.BundleVariableImport{{Name: "foo", Package: "foo"}}},
},
},
wantErr: false,
Expand All @@ -30,8 +31,8 @@ func Test_validateBundleVars(t *testing.T) {
description: "error when import doesn't match export",
args: args{
packages: []types.BundleZarfPackage{
{Name: "foo", Exports: []types.BundleVariable{{Name: "foo"}}},
{Name: "bar", Imports: []types.BundleVariable{{Name: "bar", Package: "foo"}}},
{Name: "foo", Exports: []types.BundleVariableExport{{Name: "foo"}}},
{Name: "bar", Imports: []types.BundleVariableImport{{Name: "bar", Package: "foo"}}},
},
},
wantErr: true,
Expand All @@ -40,7 +41,7 @@ func Test_validateBundleVars(t *testing.T) {
description: "error when first pkg has an import",
args: args{
packages: []types.BundleZarfPackage{
{Name: "foo", Imports: []types.BundleVariable{{Name: "foo", Package: "foo"}}},
{Name: "foo", Imports: []types.BundleVariableImport{{Name: "foo", Package: "foo"}}},
},
},
wantErr: true,
Expand All @@ -50,8 +51,8 @@ func Test_validateBundleVars(t *testing.T) {
description: "error when package name doesn't match",
args: args{
packages: []types.BundleZarfPackage{
{Name: "foo", Exports: []types.BundleVariable{{Name: "foo"}}},
{Name: "bar", Imports: []types.BundleVariable{{Name: "foo", Package: "baz"}}},
{Name: "foo", Exports: []types.BundleVariableExport{{Name: "foo"}}},
{Name: "bar", Imports: []types.BundleVariableImport{{Name: "foo", Package: "baz"}}},
},
},
wantErr: true,
Expand Down
28 changes: 17 additions & 11 deletions src/types/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,27 @@ type UDSBundle struct {

// BundleZarfPackage represents a Zarf package in a UDS bundle
type BundleZarfPackage struct {
Name string `json:"name" jsonschema:"name=Name of the Zarf package"`
Repository string `json:"repository,omitempty" jsonschema:"description=The repository to import the package from"`
Path string `json:"path,omitempty" jsonschema:"description=The local path to import the package from"`
Ref string `json:"ref" jsonschema:"description=Ref (tag) of the Zarf package"`
OptionalComponents []string `json:"optional-components,omitempty" jsonschema:"description=List of optional components to include from the package (required components are always included)"`
PublicKey string `json:"public-key,omitempty" jsonschema:"description=The public key to use to verify the package"`
Imports []BundleVariable `json:"imports,omitempty" jsonschema:"description=List of Zarf variables to import from another Zarf package"`
Exports []BundleVariable `json:"exports,omitempty" jsonschema:"description=List of Zarf variables to export from the Zarf package"`
Name string `json:"name" jsonschema:"name=Name of the Zarf package"`
Repository string `json:"repository,omitempty" jsonschema:"description=The repository to import the package from"`
Path string `json:"path,omitempty" jsonschema:"description=The local path to import the package from"`
Ref string `json:"ref" jsonschema:"description=Ref (tag) of the Zarf package"`
OptionalComponents []string `json:"optional-components,omitempty" jsonschema:"description=List of optional components to include from the package (required components are always included)"`
PublicKey string `json:"public-key,omitempty" jsonschema:"description=The public key to use to verify the package"`
Imports []BundleVariableImport `json:"imports,omitempty" jsonschema:"description=List of Zarf variables to import from another Zarf package"`
Exports []BundleVariableExport `json:"exports,omitempty" jsonschema:"description=List of Zarf variables to export from the Zarf package"`
}

// BundleVariable represents variables in the bundle
type BundleVariable struct {
// BundleVariableImport represents variables in the bundle
type BundleVariableImport struct {
Name string `json:"name" jsonschema:"name=Name of the variable"`
Package string `json:"package" jsonschema:"name=Name of the Zarf package to get the variable from"`
Description string `json:"description" jsonschema:"name=Description of the variable"`
Description string `json:"description,omitempty" jsonschema:"name=Description of the variable"`
}

// BundleVariableImport represents variables in the bundle
type BundleVariableExport struct {
Name string `json:"name" jsonschema:"name=Name of the variable"`
Description string `json:"description,omitempty" jsonschema:"name=Description of the variable"`
}

// UDSMetadata lists information about the current UDS Bundle.
Expand Down
25 changes: 20 additions & 5 deletions uds.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,25 @@
"$schema": "http://json-schema.org/draft-04/schema#",
"$ref": "#/definitions/UDSBundle",
"definitions": {
"BundleVariable": {
"BundleVariableExport": {
"required": [
"name"
],
"properties": {
"name": {
"type": "string"
},
"description": {
"type": "string"
}
},
"additionalProperties": false,
"type": "object"
},
"BundleVariableImport": {
"required": [
"name",
"package",
"description"
"package"
],
"properties": {
"name": {
Expand Down Expand Up @@ -57,14 +71,15 @@
"imports": {
"items": {
"$schema": "http://json-schema.org/draft-04/schema#",
"$ref": "#/definitions/BundleVariable"
"$ref": "#/definitions/BundleVariableImport"
},
"type": "array",
"description": "List of Zarf variables to import from another Zarf package"
},
"exports": {
"items": {
"$ref": "#/definitions/BundleVariable"
"$schema": "http://json-schema.org/draft-04/schema#",
"$ref": "#/definitions/BundleVariableExport"
},
"type": "array",
"description": "List of Zarf variables to export from the Zarf package"
Expand Down

0 comments on commit e591ad4

Please sign in to comment.