Minimum Python >= 3.7, drop oyaml, add support for short intrinsic AWS functions

This commit is contained in:
Stefan Reimer 2021-01-11 14:34:50 +00:00
parent 3a7783acc9
commit 540d4c2faa
6 changed files with 21 additions and 8 deletions

View File

@ -1,5 +1,10 @@
# Changelog
## 0.9.7
- CloudBender now requires Python >= 3.7
- drop oyaml requirement
- support for short intrinsic functions like !Ref, !Sub etc. by ignoring custom constructors before sending them to AWS to resolve
## 0.9.6
- only upload templates if render is successful
- support for jinja user-data

View File

@ -2,7 +2,7 @@ import logging
__author__ = "Stefan Reimer"
__email__ = "stefan@zero-downtimet.net"
__version__ = "0.9.6"
__version__ = "0.9.7"
# Set up logging to ``/dev/null`` like a library is supposed to.

View File

@ -1,7 +1,7 @@
import os
import re
import hashlib
import oyaml as yaml
import yaml
import time
import pathlib
import pprint
@ -32,6 +32,15 @@ import logging
logger = logging.getLogger(__name__)
# Ignore any !<Constructors> during re-loading of CFN templates
class SafeLoaderIgnoreUnknown(yaml.SafeLoader):
def ignore_unknown(self, node):
return node.tag
SafeLoaderIgnoreUnknown.add_constructor(None, SafeLoaderIgnoreUnknown.ignore_unknown)
class Stack(object):
def __init__(self, name, template, path, rel_path, ctx):
self.stackname = name
@ -135,7 +144,7 @@ class Stack(object):
try:
self.cfn_template = template.render(_config)
self.cfn_data = yaml.safe_load(self.cfn_template)
self.cfn_data = yaml.load(self.cfn_template, Loader=SafeLoaderIgnoreUnknown)
except Exception as e:
# In case we rendered invalid yaml this helps to debug
if self.cfn_template:
@ -184,7 +193,7 @@ class Stack(object):
logger.info("Piped mode: Added parameters for remote stack references")
# Re-read updated template
self.cfn_data = yaml.safe_load(self.cfn_template)
self.cfn_data = yaml.load(self.cfn_template, Loader=SafeLoaderIgnoreUnknown)
# Check for empty top level Parameters, Outputs and Conditions and remove
for key in ['Parameters', 'Outputs', 'Conditions']:
@ -318,7 +327,7 @@ class Stack(object):
logger.warn("Could not find template file: {}".format(yaml_file))
raise e
self.cfn_data = yaml.safe_load(self.cfn_template)
self.cfn_data = yaml.load(self.cfn_template, Loader=SafeLoaderIgnoreUnknown)
self._parse_metadata()
else:
logger.debug('Using cached cfn template %s.', self.stackname)

View File

@ -1,6 +1,5 @@
boto3
Jinja2
oyaml
click
pyminifier
cfn-lint

View File

@ -1,6 +1,5 @@
boto3
Jinja2
oyaml
click
pyminifier
cfn-lint>=0.34

View File

@ -47,6 +47,7 @@ setup(
name='cloudbender',
version=find_version("cloudbender/__init__.py"),
description='Toolset to render and manage AWS Cloudformation',
python_requires='>=3.7',
long_description=long_description,
long_description_content_type="text/markdown",
author='Stefan Reimer',
@ -56,7 +57,7 @@ setup(
package_data={ 'cloudbender': ['templates/*.md'], },
include_package_data=True,
entry_points={'console_scripts': [ "cloudbender = cloudbender.cli:cli" ]},
install_requires=['boto3', 'Jinja2', 'oyaml', 'click', 'cfn-lint>=0.34', 'pyminifier'],
install_requires=['boto3', 'Jinja2', 'click', 'cfn-lint>=0.34', 'pyminifier'],
tests_require=["pytest-cov", "moto", "mock", 'pytest'],
cmdclass={"test": PyTest},
classifiers=[