Decentralize cloudformation naming responsibilities (#3201)
* #3127 - Decentralize CF naming responsibilities * Decentralize CloudFormation naming responsibilities * Update URLs in cloudformation_resource_type functions * Fix flake8 errors * Black formatting * Add a bunch of imports to populate CloudFormationModel.__subclasses__ * Add noqa to s3 models import statement in cloudformation/parsing.py * Black formatting * Remove debugging print statement Co-authored-by: Bert Blommers <info@bertblommers.nl>
This commit is contained in:
parent
88a1134657
commit
9a9a1d8413
26 changed files with 717 additions and 208 deletions
|
|
@ -8,6 +8,7 @@ import os
|
|||
import re
|
||||
import six
|
||||
import types
|
||||
from abc import abstractmethod
|
||||
from io import BytesIO
|
||||
from collections import defaultdict
|
||||
from botocore.config import Config
|
||||
|
|
@ -534,6 +535,47 @@ class BaseModel(object):
|
|||
return instance
|
||||
|
||||
|
||||
# Parent class for every Model that can be instantiated by CloudFormation
|
||||
# On subclasses, implement the two methods as @staticmethod to ensure correct behaviour of the CF parser
|
||||
class CloudFormationModel(BaseModel):
|
||||
@abstractmethod
|
||||
def cloudformation_name_type(self):
|
||||
# This must be implemented as a staticmethod with no parameters
|
||||
# Return None for resources that do not have a name property
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def cloudformation_type(self):
|
||||
# This must be implemented as a staticmethod with no parameters
|
||||
# See for example https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-dynamodb-table.html
|
||||
return "AWS::SERVICE::RESOURCE"
|
||||
|
||||
@abstractmethod
|
||||
def create_from_cloudformation_json(self):
|
||||
# This must be implemented as a classmethod with parameters:
|
||||
# cls, resource_name, cloudformation_json, region_name
|
||||
# Extract the resource parameters from the cloudformation json
|
||||
# and return an instance of the resource class
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def update_from_cloudformation_json(self):
|
||||
# This must be implemented as a classmethod with parameters:
|
||||
# cls, original_resource, new_resource_name, cloudformation_json, region_name
|
||||
# Extract the resource parameters from the cloudformation json,
|
||||
# delete the old resource and return the new one. Optionally inspect
|
||||
# the change in parameters and no-op when nothing has changed.
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def delete_from_cloudformation_json(self):
|
||||
# This must be implemented as a classmethod with parameters:
|
||||
# cls, resource_name, cloudformation_json, region_name
|
||||
# Extract the resource parameters from the cloudformation json
|
||||
# and delete the resource. Do not include a return statement.
|
||||
pass
|
||||
|
||||
|
||||
class BaseBackend(object):
|
||||
def _reset_model_refs(self):
|
||||
# Remove all references to the models stored
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue