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

Resource Link #67

Merged
merged 3 commits into from
Jan 17, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,12 @@
]
}
},
"serviceLink": {
PatMyron marked this conversation as resolved.
Show resolved Hide resolved
"$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": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this section? We can only pre-fill fields from the schema anyway, could the tokens in the URL just be the json-pointers directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we did consider this, but this way it might be possible to use existing templating engines, or simple regex replace. might be good for the console team to create a PoC to see how difficult/easy both would be.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AWS::DAX::ParameterGroup is a good candidate for a proof-of-concept:

/dynamodb/home#cache-parameter-group:selected=${lowercasedResourceId}

"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 @@ -207,6 +207,33 @@
"additionalProperties": false
}
]
},
"serviceLink": {
"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"
PatMyron marked this conversation as resolved.
Show resolved Hide resolved
],
"additionalProperties": false
}
},
"type": "object",
Expand Down Expand Up @@ -366,6 +393,10 @@
},
"oneOf": {
"$ref": "#/definitions/schemaArray"
},
"serviceLink": {
"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/serviceLink"
}
},
"required": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,36 @@ public void validateDefinition_schemaKeyword_shouldBeAllowed() {
validator.validateResourceDefinition(definition);
}

@Test
public void validateDefinition_relativeTemplateUri_shouldBeAllowed() {
final JSONObject serviceLink = new JSONObject().put("templateUri", "/cloudformation/home").put("mappings",
new JSONObject());
final JSONObject definition = baseSchema().put("serviceLink", serviceLink);

validator.validateResourceDefinition(definition);
}

@Test
public void validateDefinition_httpsTemplateUri_shouldBeAllowed() {
final JSONObject serviceLink = new JSONObject()
.put("templateUri", "https://eu-central-1.console.aws.amazon.com/cloudformation/home")
.put("mappings", new JSONObject());
final JSONObject definition = baseSchema().put("serviceLink", serviceLink);

validator.validateResourceDefinition(definition);
}

@Test
public void validateDefinition_httpTemplateUri_shouldThrow() {
final JSONObject serviceLink = new JSONObject()
.put("templateUri", "http://eu-central-1.console.aws.amazon.com/cloudformation/home")
.put("mappings", new JSONObject());
final JSONObject definition = baseSchema().put("serviceLink", serviceLink);

assertThatExceptionOfType(ValidationException.class).isThrownBy(() -> validator.validateResourceDefinition(definition))
.withMessageContaining("#/serviceLink/templateUri");
}

@Test
public void validateDefinition_idKeyword_shouldBeAllowed() {
final JSONObject definition = baseSchema().put("$id",
Expand Down