Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support connection and associated metadata in validate #2453

Merged
merged 2 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 97 additions & 1 deletion cli/bpmetadata/schema/gcp-blueprint-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,18 @@
"pageUrl"
]
},
"BlueprintConnection": {
"properties": {
"source": {
"$ref": "#/$defs/ConnectionSource"
},
"spec": {
"$ref": "#/$defs/ConnectionSpec"
}
},
"additionalProperties": false,
"type": "object"
},
"BlueprintContent": {
"properties": {
"architecture": {
Expand Down Expand Up @@ -357,7 +369,8 @@
},
"description": {
"type": "string"
}
},
"type": true
},
"additionalProperties": false,
"type": "object",
Expand Down Expand Up @@ -426,6 +439,12 @@
"type": "string"
},
"type": "array"
},
"versions": {
"items": {
"$ref": "#/$defs/ProviderVersion"
},
"type": "array"
}
},
"additionalProperties": false,
Expand Down Expand Up @@ -597,6 +616,12 @@
"defaultValue": true,
"required": {
"type": "boolean"
},
"connections": {
"items": {
"$ref": "#/$defs/BlueprintConnection"
},
"type": "array"
}
},
"additionalProperties": false,
Expand Down Expand Up @@ -645,6 +670,30 @@
"title"
]
},
"ConnectionSource": {
"properties": {
"source": {
"type": "string"
},
"version": {
"type": "string"
}
},
"additionalProperties": false,
"type": "object"
},
"ConnectionSpec": {
"properties": {
"outputExpr": {
"type": "string"
},
"inputPath": {
"type": "string"
}
},
"additionalProperties": false,
"type": "object"
},
"DisplayOutput": {
"properties": {
"openInNewTab": {
Expand All @@ -655,6 +704,16 @@
},
"label": {
"type": "string"
},
"visibility": {
"oneOf": [
{
"type": "string"
},
{
"type": "integer"
}
]
}
},
"additionalProperties": false,
Expand Down Expand Up @@ -745,6 +804,12 @@
},
"booleanGroup": {
"type": "string"
},
"altDefaults": {
"items": {
"$ref": "#/$defs/DisplayVariable_AlternateDefault"
},
"type": "array"
}
},
"additionalProperties": false,
Expand All @@ -754,6 +819,25 @@
"title"
]
},
"DisplayVariable_AlternateDefault": {
"properties": {
"type": {
"oneOf": [
{
"type": "string"
},
{
"type": "integer"
}
]
},
"value": {
"$ref": "#/$defs/Value"
}
},
"additionalProperties": false,
"type": "object"
},
"GCEDiskSizeExtension": {
"properties": {
"diskTypeVariable": {
Expand Down Expand Up @@ -1060,6 +1144,18 @@
"roles"
]
},
"ProviderVersion": {
"properties": {
"source": {
"type": "string"
},
"version": {
"type": "string"
}
},
"additionalProperties": false,
"type": "object"
},
"ResourceTypeMeta": {
"properties": {
"name": {
Expand Down
6 changes: 6 additions & 0 deletions cli/bpmetadata/schema/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ func GenerateSchema() ([]byte, error) {
if defExists {
vDef.Properties.Set("defaultValue", jsonschema.TrueSchema)
}
// JSON schema seems to infer google.protobuf.Value as object type
// so we use the same workaround as above.
oDef, defExists := s.Definitions["BlueprintOutput"]
if defExists {
oDef.Properties.Set("type", jsonschema.TrueSchema)
}

sData, err := json.MarshalIndent(s, "", " ")
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions cli/bpmetadata/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ func TestValidateMetadata(t *testing.T) {
path: "valid-metadata.yaml",
wantErr: false,
},
{
name: "valid metadata with connections",
path: "valid-metadata-connections.yaml",
wantErr: false,
},
{
name: "invalid metadata - title missing",
path: "invalid-metadata.yaml",
Expand Down
45 changes: 45 additions & 0 deletions cli/testdata/bpmetadata/schema/valid-metadata-connections.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
apiVersion: blueprints.cloud.google.com/v1alpha1
kind: BlueprintMetadata
metadata:
name: terraform-google-module
spec:
info:
title: Terraform Google Module
source:
repo: https://github.com/GoogleCloudPlatform/terraform-google-module.git
sourceType: git
interfaces:
variables:
- name: foo
connections:
- source:
source: "GoogleCloudPlatform/terraform-google-module1"
version: "~> v1"
spec:
outputExpr: "field1"
inputPath: "nested.field"
- name: bar
connections:
- source:
source: "GoogleCloudPlatform/terraform-google-module1"
version: "~> v1"
spec:
outputExpr: "field1"
- source:
source: "GoogleCloudPlatform/terraform-google-module1"
version: "~> v2"
spec:
outputExpr: "field2"
- name: baz
outputs:
- name: qux
type: [
"object",
{
"VAR1": "string",
"VAR2": "number"
}
]



Loading