Skip to content

Commit 902ffa0

Browse files
Add support for Hooks (#861)
* Added support for Hooks * Bump version to 0.2.23 * Removed unused unsupported target hook contract test * Update src/rpdk/core/data/schema/provider.configuration.definition.schema.hooks.v1.json Co-authored-by: Ben Bridts <[email protected]> * Update src/rpdk/core/data/schema/provider.configuration.definition.schema.hooks.v1.json Co-authored-by: Ben Bridts <[email protected]> Co-authored-by: Ben Bridts <[email protected]>
1 parent fe0b680 commit 902ffa0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+5653
-301
lines changed

README.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# AWS CloudFormation CLI
44

5-
The CloudFormation CLI (cfn) allows you to author your own resource providers and modules that can be used by CloudFormation.
5+
The CloudFormation CLI (cfn) allows you to author your own resource providers, hooks, and modules that can be used by CloudFormation.
66

77
## Usage
88

@@ -12,7 +12,7 @@ Primary documentation for the CloudFormation CLI can be found at the [AWS Docume
1212

1313
### Installation
1414

15-
This tool can be installed using [pip](https://pypi.org/project/pip/) from the Python Package Index (PyPI). It requires Python 3. For resource types, the tool requires at least one language plugin. Language plugins are not needed to create a module type. The language plugins are also available on PyPI and as such can be installed all at once:
15+
This tool can be installed using [pip](https://pypi.org/project/pip/) from the Python Package Index (PyPI). It requires Python 3. For resource and hook types, the tool requires at least one language plugin. Language plugins are not needed to create a module type. The language plugins are also available on PyPI and as such can be installed all at once:
1616

1717
```bash
1818
pip install cloudformation-cli cloudformation-cli-java-plugin cloudformation-cli-go-plugin cloudformation-cli-python-plugin cloudformation-cli-typescript-plugin
@@ -38,7 +38,7 @@ cfn generate
3838

3939
### Command: submit
4040

41-
To register a resource provider or module in your account, use the `submit` command.
41+
To register a resource provider, module, or hook in your account, use the `submit` command.
4242

4343
```bash
4444
cfn submit
@@ -65,7 +65,7 @@ Note: To use your type configuration in contract tests, you will need to save yo
6565

6666
To validate the schema, use the `validate` command.
6767

68-
This command is automatically run whenever one attempts to submit a resource or module. Errors will prevent you from submitting your resource/module. Module fragments will additionally be validated via [`cfn-lint`](https://github.com/aws-cloudformation/cfn-python-lint/) (but resulting warnings will not cause this step to fail).
68+
This command is automatically run whenever one attempts to submit a resource, module, or hook. Errors will prevent you from submitting your resource/module. Module fragments will additionally be validated via [`cfn-lint`](https://github.com/aws-cloudformation/cfn-python-lint/) (but resulting warnings will not cause this step to fail).
6969

7070
```bash
7171
cfn validate
@@ -99,7 +99,7 @@ pip install -e . -r requirements.txt
9999
pre-commit install
100100
```
101101

102-
If you're creating a resource type, you will also need to install a language plugin, such as [the Java language plugin](https://github.com/aws-cloudformation/cloudformation-cli-java-plugin), also via `pip install`. For example, assuming the plugin is checked out in the same parent directory as this repository:
102+
If you're creating a resource or hook type, you will also need to install a language plugin, such as [the Java language plugin](https://github.com/aws-cloudformation/cloudformation-cli-java-plugin), also via `pip install`. For example, assuming the plugin is checked out in the same parent directory as this repository:
103103

104104
```bash
105105
pip install -e ../cloudformation-cli-java-plugin
@@ -128,13 +128,20 @@ Plugins must provide the same interface as `LanguagePlugin` (in `plugin_base.py`
128128

129129
### Supported plugins
130130

131+
#### Resource Types Supported Plugins
131132
| Language | Status | Github | PyPI |
132133
| -------- | ----------------- | ----------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- |
133134
| Java | Available | [cloudformation-cli-java-plugin](https://github.com/aws-cloudformation/cloudformation-cli-java-plugin/) | [cloudformation-cli-java-plugin](https://pypi.org/project/cloudformation-cli-java-plugin/) |
134135
| Go | Available | [cloudformation-cli-go-plugin](https://github.com/aws-cloudformation/cloudformation-cli-go-plugin/) | [cloudformation-cli-go-plugin](https://pypi.org/project/cloudformation-cli-go-plugin/) |
135136
| Python | Available | [cloudformation-cli-python-plugin](https://github.com/aws-cloudformation/cloudformation-cli-python-plugin/) | [cloudformation-cli-python-plugin](https://pypi.org/project/cloudformation-cli-python-plugin/) |
136137
| TypeScript| Available | [cloudformation-cli-typescript-plugin](https://github.com/aws-cloudformation/cloudformation-cli-typescript-plugin/) | [cloudformation-cli-typescript-plugin](https://pypi.org/project/cloudformation-cli-typescript-plugin/) |
137138

139+
#### Hook Types Supported Plugins
140+
| Language | Status | Github | PyPI |
141+
| -------- | ----------------- | ----------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- |
142+
| Java | Available | [cloudformation-cli-java-plugin](https://github.com/aws-cloudformation/cloudformation-cli-java-plugin/) | [cloudformation-cli-java-plugin](https://pypi.org/project/cloudformation-cli-java-plugin/) |
143+
| Python | Available | [cloudformation-cli-python-plugin](https://github.com/aws-cloudformation/cloudformation-cli-python-plugin/) | [cloudformation-cli-python-plugin](https://pypi.org/project/cloudformation-cli-python-plugin/) |
144+
138145
## License
139146

140147
This library is licensed under the Apache 2.0 License.

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ include_trailing_comma = true
2929
combine_as_imports = True
3030
force_grid_wrap = 0
3131
known_first_party = rpdk
32-
known_third_party = boto3,botocore,cfn_tools,cfnlint,colorama,docker,hypothesis,jinja2,jsonschema,nested_lookup,ordered_set,pkg_resources,pytest,pytest_localserver,setuptools,yaml
32+
known_third_party = boto3,botocore,cfn_tools,cfnlint,colorama,docker,hypothesis,jinja2,jsonschema,nested_lookup,ordered_set,pkg_resources,pytest,pytest_localserver,requests,setuptools,yaml
3333

3434
[tool:pytest]
3535
# can't do anything about 3rd part modules, so don't spam us

src/rpdk/core/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import logging
22

3-
__version__ = "0.2.22"
3+
__version__ = "0.2.23"
44

55
logging.getLogger(__name__).addHandler(logging.NullHandler())
Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,37 @@
11
import pytest
22

3+
from rpdk.core.contract.hook_client import HookClient
4+
5+
from .resource_client import ResourceClient
6+
37

48
class ContractPlugin:
5-
def __init__(self, resource_client):
6-
self._resource_client = resource_client
9+
def __init__(self, plugin_clients):
10+
if not plugin_clients:
11+
raise RuntimeError("No plugin clients are set up")
12+
13+
self._plugin_clients = plugin_clients
714

815
@pytest.fixture(scope="module")
916
def resource_client(self):
10-
return self._resource_client
17+
try:
18+
resource_client = self._plugin_clients["resource_client"]
19+
except KeyError:
20+
resource_client = None
21+
22+
if not isinstance(resource_client, ResourceClient):
23+
raise ValueError("Contract plugin client not setup for RESOURCE type")
24+
25+
return resource_client
26+
27+
@pytest.fixture(scope="module")
28+
def hook_client(self):
29+
try:
30+
hook_client = self._plugin_clients["hook_client"]
31+
except KeyError:
32+
hook_client = None
33+
34+
if not isinstance(hook_client, HookClient):
35+
raise ValueError("Contract plugin client not setup for HOOK type")
36+
37+
return hook_client

0 commit comments

Comments
 (0)