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

Add support for Hooks #861

Merged
merged 5 commits into from
Feb 10, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# AWS CloudFormation CLI

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

## Usage

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

### Installation

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:
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:

```bash
pip install cloudformation-cli cloudformation-cli-java-plugin cloudformation-cli-go-plugin cloudformation-cli-python-plugin cloudformation-cli-typescript-plugin
Expand All @@ -38,7 +38,7 @@ cfn generate

### Command: submit

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

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

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

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).
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).

```bash
cfn validate
Expand Down Expand Up @@ -99,7 +99,7 @@ pip install -e . -r requirements.txt
pre-commit install
```

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:
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:

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

### Supported plugins

#### Resource Types Supported Plugins
| Language | Status | Github | PyPI |
| -------- | ----------------- | ----------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- |
| 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/) |
| 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/) |
| 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/) |
| 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/) |

#### Hook Types Supported Plugins
| Language | Status | Github | PyPI |
| -------- | ----------------- | ----------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- |
| 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/) |
| 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/) |

## License

This library is licensed under the Apache 2.0 License.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ include_trailing_comma = true
combine_as_imports = True
force_grid_wrap = 0
known_first_party = rpdk
known_third_party = boto3,botocore,cfn_tools,cfnlint,colorama,docker,hypothesis,jinja2,jsonschema,nested_lookup,ordered_set,pkg_resources,pytest,pytest_localserver,setuptools,yaml
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

[tool:pytest]
# can't do anything about 3rd part modules, so don't spam us
Expand Down
2 changes: 1 addition & 1 deletion src/rpdk/core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging

__version__ = "0.2.22"
__version__ = "0.2.23"

logging.getLogger(__name__).addHandler(logging.NullHandler())
33 changes: 30 additions & 3 deletions src/rpdk/core/contract/contract_plugin.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,37 @@
import pytest

from rpdk.core.contract.hook_client import HookClient

from .resource_client import ResourceClient


class ContractPlugin:
def __init__(self, resource_client):
self._resource_client = resource_client
def __init__(self, plugin_clients):
if not plugin_clients:
raise RuntimeError("No plugin clients are set up")

self._plugin_clients = plugin_clients

@pytest.fixture(scope="module")
def resource_client(self):
return self._resource_client
try:
resource_client = self._plugin_clients["resource_client"]
except KeyError:
resource_client = None

if not isinstance(resource_client, ResourceClient):
raise ValueError("Contract plugin client not setup for RESOURCE type")

return resource_client

@pytest.fixture(scope="module")
def hook_client(self):
try:
hook_client = self._plugin_clients["hook_client"]
except KeyError:
hook_client = None

if not isinstance(hook_client, HookClient):
raise ValueError("Contract plugin client not setup for HOOK type")

return hook_client
Loading