Skip to content

Commit 75bed27

Browse files
Handler schema definition (#1009)
Parametrized Handler Definition --------- Co-authored-by: Anton Mokhovikov <[email protected]>
1 parent fcae347 commit 75bed27

File tree

4 files changed

+66
-5
lines changed

4 files changed

+66
-5
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def find_version(*file_paths):
4141
"boto3>=1.10.20",
4242
"Jinja2>=3.1.2",
4343
"markupsafe>=2.1.0",
44-
"jsonschema>=4.0.0,<5.0",
44+
"jsonschema>=3.0.0,<=4.17.3",
4545
"pytest>=4.5.0",
4646
"pytest-random-order>=1.0.4",
4747
"pytest-localserver>=0.5.0",

src/rpdk/core/data/schema/provider.definition.schema.v1.json

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,55 @@
44
"title": "CloudFormation Resource Provider Definition MetaSchema",
55
"description": "This schema validates a CloudFormation resource provider definition.",
66
"definitions": {
7+
"handlerSchema": {
8+
"type": "object",
9+
"properties": {
10+
"properties": {
11+
"$ref": "base.definition.schema.v1.json#/properties/properties"
12+
},
13+
"required": {
14+
"$ref": "base.definition.schema.v1.json#/properties/required"
15+
},
16+
"allOf": {
17+
"$ref": "base.definition.schema.v1.json#/definitions/schemaArray"
18+
},
19+
"anyOf": {
20+
"$ref": "base.definition.schema.v1.json#/definitions/schemaArray"
21+
},
22+
"oneOf": {
23+
"$ref": "base.definition.schema.v1.json#/definitions/schemaArray"
24+
}
25+
},
26+
"required": ["properties"],
27+
"additionalProperties": false
28+
},
29+
"handlerDefinitionWithSchemaOverride": {
30+
"description": "Defines any execution operations which can be performed on this resource provider",
31+
"type": "object",
32+
"properties": {
33+
"handlerSchema": {
34+
"$ref": "#/definitions/handlerSchema"
35+
},
36+
"permissions": {
37+
"type": "array",
38+
"items": {
39+
"type": "string"
40+
},
41+
"additionalItems": false
42+
},
43+
"timeoutInMinutes": {
44+
"description": "Defines the timeout for the entire operation to be interpreted by the invoker of the handler. The default is 120 (2 hours).",
45+
"type": "integer",
46+
"minimum": 2,
47+
"maximum": 2160,
48+
"default": 120
49+
}
50+
},
51+
"additionalProperties": false,
52+
"required": [
53+
"permissions"
54+
]
55+
},
756
"handlerDefinition": {
857
"description": "Defines any execution operations which can be performed on this resource provider",
958
"type": "object",
@@ -190,7 +239,7 @@
190239
"$ref": "#/definitions/handlerDefinition"
191240
},
192241
"list": {
193-
"$ref": "#/definitions/handlerDefinition"
242+
"$ref": "#/definitions/handlerDefinitionWithSchemaOverride"
194243
}
195244
},
196245
"additionalProperties": false

src/rpdk/core/jsonutils/inliner.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import logging
22
from collections.abc import Iterable, Mapping
33

4-
from jsonschema import RefResolver
4+
from jsonschema import RefResolutionError, RefResolver
55

66
from .renamer import RefRenamer
77
from .utils import BASE, rewrite_ref, traverse
@@ -12,6 +12,8 @@
1212
class RefInliner(RefResolver):
1313
"""Mutates the schema."""
1414

15+
META_SCHEMA = "resource-schema.json"
16+
1517
def __init__(self, base_uri, schema):
1618
self.schema = schema
1719
self.ref_graph = {}
@@ -33,7 +35,7 @@ def resolve(self, ref):
3335
url = self._urljoin_cache(self.resolution_scope, ref)
3436
return url, self._remote_cache(url)
3537

36-
def _walk(self, obj, old_path):
38+
def _walk(self, obj, old_path): # noqa: C901 # pylint: disable=R0912
3739
if isinstance(obj, str):
3840
return # very common, easier to debug this case
3941

@@ -43,7 +45,16 @@ def _walk(self, obj, old_path):
4345
if old_path in self.ref_graph:
4446
LOG.debug("Already visited '%s' (%s)", old_path, value)
4547
return
46-
url, resolved = self.resolve(value)
48+
try:
49+
url, resolved = self.resolve(value)
50+
except RefResolutionError: # noqa: E203
51+
if self.META_SCHEMA in value: # noqa: E203
52+
url, resolved = self.resolve( # noqa: E203
53+
value[len(self.META_SCHEMA) :] # noqa: E203
54+
) # noqa: E203
55+
else: # noqa: E203
56+
raise
57+
4758
LOG.debug("Resolved '%s' to '%s'", value, url)
4859
# parse the URL into
4960
new_path = self.renamer.parse_ref_url(url)

tests/jsonutils/test_inliner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def test_refinliner_local_refs_simple_are_walked_and_unchanged():
4747
"definitions": {"bar": {"type": "string"}},
4848
"properties": {"foo": {"$ref": "#/definitions/bar"}},
4949
}
50+
5051
inliner = make_inliner(local)
5152
schema = inliner.inline()
5253
assert schema == local

0 commit comments

Comments
 (0)