Skip to content

Commit

Permalink
Merge pull request #2 from mrowlingfox/feature/fetch-remote-template
Browse files Browse the repository at this point in the history
Fetch remote template
  • Loading branch information
mrowlingfox committed Apr 8, 2021
2 parents 8a6e2b6 + b763a10 commit 08a5734
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 2 deletions.
2 changes: 1 addition & 1 deletion sceptre/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

__author__ = 'Cloudreach'
__email__ = 'sceptre@cloudreach.com'
__version__ = '2.4.0'
__version__ = '2.5.0'


# Set up logging to ``/dev/null`` like a library is supposed to.
Expand Down
2 changes: 2 additions & 0 deletions sceptre/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from sceptre.cli.policy import set_policy_command
from sceptre.cli.status import status_command
from sceptre.cli.template import (validate_command, generate_command,
fetch_remote_template_command,
estimate_cost_command)
from sceptre.cli.helpers import setup_logging, catch_exceptions

Expand Down Expand Up @@ -119,6 +120,7 @@ def nested_set(dic, keys, value):
cli.add_command(validate_command)
cli.add_command(estimate_cost_command)
cli.add_command(generate_command)
cli.add_command(fetch_remote_template_command)
cli.add_command(set_policy_command)
cli.add_command(status_command)
cli.add_command(list_group)
Expand Down
27 changes: 27 additions & 0 deletions sceptre/cli/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,33 @@ def generate_command(ctx, path):
write(output, context.output_format)


@click.command(name="fetch-remote-template", short_help="Prints the remote template.")
@click.argument("path")
@click.pass_context
@catch_exceptions
def fetch_remote_template_command(ctx, path):
"""
Prints the remote template used for stack in PATH.
\f
:param path: Path to execute the command on.
:type path: str
"""
context = SceptreContext(
command_path=path,
project_path=ctx.obj.get("project_path"),
user_variables=ctx.obj.get("user_variables"),
options=ctx.obj.get("options"),
output_format=ctx.obj.get("output_format"),
ignore_dependencies=ctx.obj.get("ignore_dependencies")
)

plan = SceptrePlan(context)
responses = plan.fetch_remote_template()
output = [template for template in responses.values()]
write(output, context.output_format)


@click.command(name="estimate-cost", short_help="Estimates the cost of the template.")
@click.argument("path")
@click.pass_context
Expand Down
15 changes: 15 additions & 0 deletions sceptre/plan/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,21 @@ def generate(self):
"""
return self.stack.template.body

@add_stack_hooks
def fetch_remote_template(self):
"""
Returns the Template for the remote Stack
"""
self.logger.debug("%s - Fetching remote template", self.stack.name)
response = self.connection_manager.call(
service="cloudformation",
command="get_template",
kwargs={
"StackName": self.stack.external_name
}
)
return response.get("TemplateBody")

@add_stack_hooks
def validate(self):
"""
Expand Down
10 changes: 10 additions & 0 deletions sceptre/plan/plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,16 @@ def generate(self, *args):
self.resolve(command=self.generate.__name__)
return self._execute(*args)

def fetch_remote_template(self, *args):
"""
Returns a generated Template for a given Stack
:returns: A dictionary of Stacks and their template body.
:rtype: dict
"""
self.resolve(command=self.fetch_remote_template.__name__)
return self._execute(*args)

def _valid_stack_paths(self):
return [
sceptreise_path(path.relpath(path.join(dirpath, f), self.context.config_path))
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 2.4.0
current_version = 2.5.0
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)|(?P<release_candidate>.*)
commit = True
tag = True
Expand Down

0 comments on commit 08a5734

Please sign in to comment.