From f3277176eeeee53427ca1dcc5c5ee820273cb90d Mon Sep 17 00:00:00 2001 From: Toby Fleming Date: Fri, 17 Jan 2020 11:57:16 -0800 Subject: [PATCH] Resource Link (#67) --- .../resource/initech.tps.report.v1.json | 7 +++++ .../schema/provider.definition.schema.v1.json | 31 +++++++++++++++++++ .../resource/ValidatorTest.java | 30 ++++++++++++++++++ 3 files changed, 68 insertions(+) diff --git a/src/main/resources/examples/resource/initech.tps.report.v1.json b/src/main/resources/examples/resource/initech.tps.report.v1.json index a11a3b3..b908689 100644 --- a/src/main/resources/examples/resource/initech.tps.report.v1.json +++ b/src/main/resources/examples/resource/initech.tps.report.v1.json @@ -100,5 +100,12 @@ ] } }, + "resourceLink": { + "$comment": "This is an example of a relative, AWS-internal service link. For external links, use an absolute URI.", + "templateUri": "/tps/v2/home?region=${awsRegion}#Report:tpsCode=${TPSCode}", + "mappings": { + "TPSCode": "/TPSCode" + } + }, "additionalProperties": false } diff --git a/src/main/resources/schema/provider.definition.schema.v1.json b/src/main/resources/schema/provider.definition.schema.v1.json index 13b5aef..314678d 100644 --- a/src/main/resources/schema/provider.definition.schema.v1.json +++ b/src/main/resources/schema/provider.definition.schema.v1.json @@ -214,6 +214,33 @@ "additionalProperties": false } ] + }, + "resourceLink": { + "type": "object", + "properties": { + "$comment": { + "$ref": "https://json-schema.org/draft-07/schema#/properties/$comment" + }, + "templateUri": { + "type": "string", + "pattern": "^(/|https:)" + }, + "mappings": { + "type": "object", + "patternProperties": { + "^[A-Za-z0-9]{1,64}$": { + "type": "string", + "format": "json-pointer" + } + }, + "additionalProperties": false + } + }, + "required": [ + "templateUri", + "mappings" + ], + "additionalProperties": false } }, "type": "object", @@ -373,6 +400,10 @@ }, "oneOf": { "$ref": "#/definitions/schemaArray" + }, + "resourceLink": { + "description": "A template-able link to a resource instance. AWS-internal service links must be relative to the AWS console domain. External service links must be absolute, HTTPS URIs.", + "$ref": "#/definitions/resourceLink" } }, "required": [ diff --git a/src/test/java/software/amazon/cloudformation/resource/ValidatorTest.java b/src/test/java/software/amazon/cloudformation/resource/ValidatorTest.java index 3d601d8..eba1b17 100644 --- a/src/test/java/software/amazon/cloudformation/resource/ValidatorTest.java +++ b/src/test/java/software/amazon/cloudformation/resource/ValidatorTest.java @@ -434,6 +434,36 @@ public void validateDefinition_schemaKeyword_shouldBeAllowed() { validator.validateResourceDefinition(definition); } + @Test + public void validateDefinition_relativeTemplateUri_shouldBeAllowed() { + final JSONObject resourceLink = new JSONObject().put("templateUri", "/cloudformation/home").put("mappings", + new JSONObject()); + final JSONObject definition = baseSchema().put("resourceLink", resourceLink); + + validator.validateResourceDefinition(definition); + } + + @Test + public void validateDefinition_httpsTemplateUri_shouldBeAllowed() { + final JSONObject resourceLink = new JSONObject() + .put("templateUri", "https://eu-central-1.console.aws.amazon.com/cloudformation/home") + .put("mappings", new JSONObject()); + final JSONObject definition = baseSchema().put("resourceLink", resourceLink); + + validator.validateResourceDefinition(definition); + } + + @Test + public void validateDefinition_httpTemplateUri_shouldThrow() { + final JSONObject resourceLink = new JSONObject() + .put("templateUri", "http://eu-central-1.console.aws.amazon.com/cloudformation/home") + .put("mappings", new JSONObject()); + final JSONObject definition = baseSchema().put("resourceLink", resourceLink); + + assertThatExceptionOfType(ValidationException.class).isThrownBy(() -> validator.validateResourceDefinition(definition)) + .withMessageContaining("#/resourceLink/templateUri"); + } + @Test public void validateDefinition_idKeyword_shouldBeAllowed() { final JSONObject definition = baseSchema().put("$id",