Skip to content

Commit

Permalink
Resource Link (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
tobywf authored and vladtsir committed Feb 12, 2020
1 parent b053d26 commit f327717
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
31 changes: 31 additions & 0 deletions src/main/resources/schema/provider.definition.schema.v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit f327717

Please sign in to comment.