Add new graph feature, make validate work against latest cfn-lint
This commit is contained in:
parent
8fbe40771e
commit
fbc69a3965
@ -1,5 +1,9 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 0.9.4
|
||||||
|
- new option to generate Dot Graph files via `--graph` option for the create-docs command
|
||||||
|
- fix validate command using latest cfn-lint library
|
||||||
|
|
||||||
## 0.9.3
|
## 0.9.3
|
||||||
- Improved bash minify for user-data
|
- Improved bash minify for user-data
|
||||||
- Unused additional parameters are now printed as a warning to catch potential typos early
|
- Unused additional parameters are now printed as a warning to catch potential typos early
|
||||||
|
@ -2,7 +2,7 @@ import logging
|
|||||||
|
|
||||||
__author__ = "Stefan Reimer"
|
__author__ = "Stefan Reimer"
|
||||||
__email__ = "stefan@zero-downtimet.net"
|
__email__ = "stefan@zero-downtimet.net"
|
||||||
__version__ = "0.9.3"
|
__version__ = "0.9.4"
|
||||||
|
|
||||||
|
|
||||||
# Set up logging to ``/dev/null`` like a library is supposed to.
|
# Set up logging to ``/dev/null`` like a library is supposed to.
|
||||||
|
@ -105,13 +105,14 @@ def outputs(cb, stack_names, multi, include, values):
|
|||||||
@click.command()
|
@click.command()
|
||||||
@click.argument("stack_names", nargs=-1)
|
@click.argument("stack_names", nargs=-1)
|
||||||
@click.option("--multi", is_flag=True, help="Allow more than one stack to match")
|
@click.option("--multi", is_flag=True, help="Allow more than one stack to match")
|
||||||
|
@click.option("--graph", is_flag=True, help="Create Dot Graph file")
|
||||||
@click.pass_obj
|
@click.pass_obj
|
||||||
def create_docs(cb, stack_names, multi):
|
def create_docs(cb, stack_names, multi, graph):
|
||||||
""" Parses all documentation fragments out of rendered templates creating docs/*.md file """
|
""" Parses all documentation fragments out of rendered templates creating docs/*.md file """
|
||||||
|
|
||||||
stacks = _find_stacks(cb, stack_names, multi)
|
stacks = _find_stacks(cb, stack_names, multi)
|
||||||
for s in stacks:
|
for s in stacks:
|
||||||
s.create_docs()
|
s.create_docs(graph=graph)
|
||||||
|
|
||||||
|
|
||||||
@click.command()
|
@click.command()
|
||||||
|
@ -19,6 +19,8 @@ from .exceptions import ParameterNotFound, ParameterIllegalValue
|
|||||||
from .hooks import exec_hooks
|
from .hooks import exec_hooks
|
||||||
|
|
||||||
import cfnlint.core
|
import cfnlint.core
|
||||||
|
import cfnlint.template
|
||||||
|
import cfnlint.graph
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import importlib.resources as pkg_resources
|
import importlib.resources as pkg_resources
|
||||||
@ -353,7 +355,7 @@ class Stack(object):
|
|||||||
output_contents.write(template.render(**data))
|
output_contents.write(template.render(**data))
|
||||||
logger.info('Wrote outputs for %s to %s', self.stackname, output_file)
|
logger.info('Wrote outputs for %s to %s', self.stackname, output_file)
|
||||||
|
|
||||||
def create_docs(self, template=False):
|
def create_docs(self, template=False, graph=False):
|
||||||
""" Read rendered template, parse documentation fragments, eg. parameter description
|
""" Read rendered template, parse documentation fragments, eg. parameter description
|
||||||
and create a mardown doc file for the stack
|
and create a mardown doc file for the stack
|
||||||
same idea as eg. helm-docs for values.yaml
|
same idea as eg. helm-docs for values.yaml
|
||||||
@ -404,6 +406,24 @@ class Stack(object):
|
|||||||
doc_contents.write(template.render(**data))
|
doc_contents.write(template.render(**data))
|
||||||
logger.info('Wrote documentation for %s to %s', self.stackname, doc_file)
|
logger.info('Wrote documentation for %s to %s', self.stackname, doc_file)
|
||||||
|
|
||||||
|
# Write Graph in Dot format
|
||||||
|
if graph:
|
||||||
|
filename = os.path.join(self.ctx['template_path'], self.rel_path, self.stackname + ".yaml")
|
||||||
|
|
||||||
|
lint_args = ['--template', filename]
|
||||||
|
(args, filenames, formatter) = cfnlint.core.get_args_filenames(lint_args)
|
||||||
|
(template, rules, matches) = cfnlint.core.get_template_rules(filename, args)
|
||||||
|
template_obj = cfnlint.template.Template(filename, template, [self.region])
|
||||||
|
|
||||||
|
g = cfnlint.graph.Graph(template_obj)
|
||||||
|
path = os.path.join(self.ctx['docs_path'], self.rel_path, self.stackname + ".dot")
|
||||||
|
try:
|
||||||
|
g.to_dot(path)
|
||||||
|
logger.info('DOT representation of the graph written to %s', path)
|
||||||
|
except ImportError:
|
||||||
|
logger.error(
|
||||||
|
'Could not write the graph in DOT format. Please install either `pygraphviz` or `pydot` modules.')
|
||||||
|
|
||||||
def resolve_parameters(self):
|
def resolve_parameters(self):
|
||||||
""" Renders parameters for the stack based on the source template and the environment configuration """
|
""" Renders parameters for the stack based on the source template and the environment configuration """
|
||||||
|
|
||||||
|
@ -3,4 +3,4 @@ Jinja2
|
|||||||
oyaml
|
oyaml
|
||||||
click
|
click
|
||||||
pyminifier
|
pyminifier
|
||||||
cfn-lint
|
cfn-lint>=0.34
|
||||||
|
Loading…
Reference in New Issue
Block a user