-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from hashicorp/f-06-23-2023-provider.definitio…
…n.schema-update 06/23/2023 AWS CloudFormation Resource Provider Definition Schema
- Loading branch information
Showing
8 changed files
with
226 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package cfschema | ||
|
||
type HandlerSchema struct { | ||
AllOf []*PropertySubschema `json:"allOf,omitempty"` | ||
AnyOf []*PropertySubschema `json:"anyOf,omitempty"` | ||
OneOf []*PropertySubschema `json:"oneOf,omitempty"` | ||
Properties map[string]*Property `json:"properties,omitempty"` | ||
Required []string `json:"required,omitempty"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package cfschema_test | ||
|
||
import ( | ||
"path/filepath" | ||
"testing" | ||
|
||
cfschema "github.com/hashicorp/aws-cloudformation-resource-schema-sdk-go" | ||
) | ||
|
||
func TestHandlerSchema(t *testing.T) { | ||
testCases := []struct { | ||
TestDescription string | ||
MetaSchemaPath string | ||
ResourceSchemaPath string | ||
ExpectError bool | ||
ExpectedHandlerSchema int | ||
}{ | ||
{ | ||
TestDescription: "no handlerSchema", | ||
MetaSchemaPath: "provider.definition.schema.v1.json", | ||
ResourceSchemaPath: "AWS_CloudWatch_MetricStream.json", | ||
}, | ||
{ | ||
TestDescription: "list handlerSchema", | ||
MetaSchemaPath: "provider.definition.schema.v1.json", | ||
ResourceSchemaPath: "AWS_NetworkManager_TransitGatewayRegistration.json", | ||
ExpectedHandlerSchema: 1, | ||
}, | ||
} | ||
|
||
for _, testCase := range testCases { | ||
testCase := testCase | ||
|
||
t.Run(testCase.TestDescription, func(t *testing.T) { | ||
metaSchema, err := cfschema.NewMetaJsonSchemaPath(filepath.Join("testdata", testCase.MetaSchemaPath)) | ||
|
||
if err != nil { | ||
t.Fatalf("unexpected NewMetaJsonSchemaPath() error: %s", err) | ||
} | ||
|
||
resourceSchema, err := cfschema.NewResourceJsonSchemaPath(filepath.Join("testdata", testCase.ResourceSchemaPath)) | ||
|
||
if err != nil { | ||
t.Fatalf("unexpected NewResourceJsonSchemaPath() error: %s", err) | ||
} | ||
|
||
err = metaSchema.ValidateResourceJsonSchema(resourceSchema) | ||
|
||
if err != nil { | ||
t.Fatalf("unexpected ValidateResourceJsonSchema() error: %s", err) | ||
} | ||
|
||
resource, err := resourceSchema.Resource() | ||
|
||
if err != nil { | ||
t.Fatalf("unexpected Resource() error: %s", err) | ||
} | ||
|
||
got := 0 | ||
|
||
for _, handler := range resource.Handlers { | ||
if handler.HandlerSchema != nil { | ||
got++ | ||
} | ||
} | ||
|
||
if actual, expected := got, testCase.ExpectedHandlerSchema; actual != expected { | ||
t.Errorf("expected %d handlerSchema elements, got: %d", expected, actual) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
testdata/AWS_NetworkManager_TransitGatewayRegistration.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
{ | ||
"typeName": "AWS::NetworkManager::TransitGatewayRegistration", | ||
"description": "The AWS::NetworkManager::TransitGatewayRegistration type registers a transit gateway in your global network. The transit gateway can be in any AWS Region, but it must be owned by the same AWS account that owns the global network. You cannot register a transit gateway in more than one global network.", | ||
"sourceUrl": "https://github.com/aws-cloudformation/aws-cloudformation-resource-providers-networkmanager.git", | ||
"properties": { | ||
"GlobalNetworkId": { | ||
"description": "The ID of the global network.", | ||
"type": "string" | ||
}, | ||
"TransitGatewayArn": { | ||
"description": "The Amazon Resource Name (ARN) of the transit gateway.", | ||
"type": "string" | ||
} | ||
}, | ||
"taggable": false, | ||
"additionalProperties": false, | ||
"required": [ | ||
"GlobalNetworkId", | ||
"TransitGatewayArn" | ||
], | ||
"createOnlyProperties": [ | ||
"/properties/GlobalNetworkId", | ||
"/properties/TransitGatewayArn" | ||
], | ||
"primaryIdentifier": [ | ||
"/properties/GlobalNetworkId", | ||
"/properties/TransitGatewayArn" | ||
], | ||
"handlers": { | ||
"create": { | ||
"permissions": [ | ||
"networkmanager:RegisterTransitGateway" | ||
], | ||
"timeoutInMinutes": 30 | ||
}, | ||
"read": { | ||
"permissions": [ | ||
"networkmanager:GetTransitGatewayRegistrations" | ||
] | ||
}, | ||
"list": { | ||
"handlerSchema": { | ||
"properties": { | ||
"GlobalNetworkId": { | ||
"$ref": "resource-schema.json#/properties/GlobalNetworkId" | ||
} | ||
}, | ||
"required": ["GlobalNetworkId"] | ||
}, | ||
"permissions": [ | ||
"networkmanager:GetTransitGatewayRegistrations" | ||
] | ||
}, | ||
"delete": { | ||
"permissions": [ | ||
"networkmanager:DeregisterTransitGateway" | ||
], | ||
"timeoutInMinutes": 30 | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters