How to use the sceptre.context.SceptreContext function in sceptre

To help you get started, we’ve selected a few sceptre examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Sceptre / sceptre / integration-tests / steps / templates.py View on Github external
def step_impl(context, stack_name):
    sceptre_context = SceptreContext(
        command_path=stack_name + '.yaml',
        project_path=context.sceptre_dir
    )
    sceptre_plan = SceptrePlan(sceptre_context)
    try:
        context.output = sceptre_plan.generate()
    except Exception as e:
        context.error = e
github Sceptre / sceptre / tests / test_plan.py View on Github external
def setup_method(self, test_method):
        self.patcher_SceptrePlan = patch("sceptre.plan.plan.SceptrePlan")
        self.stack = Stack(
            name='dev/app/stack', project_code=sentinel.project_code,
            template_path=sentinel.template_path, region=sentinel.region,
            profile=sentinel.profile, parameters={"key1": "val1"},
            sceptre_user_data=sentinel.sceptre_user_data, hooks={},
            s3_details=None, dependencies=sentinel.dependencies,
            role_arn=sentinel.role_arn, protected=False,
            tags={"tag1": "val1"}, external_name=sentinel.external_name,
            notifications=[sentinel.notification],
            on_failure=sentinel.on_failure,
            stack_timeout=sentinel.stack_timeout
        )
        self.mock_context = MagicMock(spec=SceptreContext)
        self.mock_config_reader = MagicMock(spec=ConfigReader)
        self.mock_context.project_path = sentinel.project_path
        self.mock_context.command_path = sentinel.command_path
        self.mock_context.config_file = sentinel.config_file
        self.mock_context.full_config_path.return_value =\
            sentinel.full_config_path
        self.mock_context.user_variables = {}
        self.mock_context.options = {}
        self.mock_context.no_colour = True
        self.mock_config_reader.context = self.mock_context
github Sceptre / sceptre / integration-tests / steps / change_sets.py View on Github external
def step_impl(context, change_set_name, stack_name):
    sceptre_context = SceptreContext(
        command_path=stack_name + '.yaml',
        project_path=context.sceptre_dir,
        ignore_dependencies=True
    )

    sceptre_plan = SceptrePlan(sceptre_context)
    allowed_errors = {'ValidationError', 'ChangeSetNotFound'}
    sceptre_plan.delete_change_set(change_set_name)

    try:
        sceptre_plan.delete_change_set(change_set_name)
    except ClientError as e:
        if e.response['Error']['Code'] in allowed_errors:
            context.error = e
            return
        else:
github Sceptre / sceptre / integration-tests / steps / change_sets.py View on Github external
def step_impl(context, change_set_name, stack_name):
    sceptre_context = SceptreContext(
        command_path=stack_name + '.yaml',
        project_path=context.sceptre_dir
    )

    sceptre_plan = SceptrePlan(sceptre_context)
    allowed_errors = {'ValidationError', 'ChangeSetNotFound'}
    try:
        sceptre_plan.create_change_set(change_set_name)
    except ClientError as e:
        if e.response['Error']['Code'] in allowed_errors:
            context.error = e
            return
        else:
            raise e

    wait_for_final_state(context, stack_name, change_set_name)
github Sceptre / sceptre / integration-tests / steps / templates.py View on Github external
def set_template_path(context, stack_name, template_name):
    sceptre_context = SceptreContext(
        command_path=stack_name + ".yaml",
        project_path=context.sceptre_dir
    )

    config_path = sceptre_context.full_config_path()

    template_path = os.path.join(
        sceptre_context.project_path,
        sceptre_context.templates_path,
        template_name
    )
    with open(os.path.join(config_path, stack_name + '.yaml')) as config_file:
        stack_config = yaml.safe_load(config_file)

    stack_config["template_path"] = template_path
github Sceptre / sceptre / sceptre / cli / list.py View on Github external
def list_resources(ctx, path):
    """
    List resources for stack or stack_group.
    \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 = [
        response for response
        in plan.describe_resources().values() if response
    ]

    write(responses, context.output_format)
github Sceptre / sceptre / sceptre / cli / create.py View on Github external
def create_command(ctx, path, change_set_name, yes):
    """
    Creates a stack for a given config PATH. Or if CHANGE_SET_NAME is specified
    creates a change set for stack in PATH.
    \f

    :param path: Path to a Stack or StackGroup
    :type path: str
    :param change_set_name: A name of the Change Set - optional
    :type change_set_name: str
    :param yes: A flag to assume yes to all questions.
    :type yes: bool
    """
    context = SceptreContext(
        command_path=path,
        project_path=ctx.obj.get("project_path"),
        user_variables=ctx.obj.get("user_variables"),
        options=ctx.obj.get("options"),
        ignore_dependencies=ctx.obj.get("ignore_dependencies")
    )

    action = "create"
    plan = SceptrePlan(context)

    if change_set_name:
        confirmation(action, yes, change_set=change_set_name,
                     command_path=path)
        plan.create_change_set(change_set_name)
    else:
        confirmation(action, yes, command_path=path)
github Sceptre / sceptre / sceptre / cli / template.py View on Github external
def generate_command(ctx, path):
    """
    Prints the 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.generate()
    output = [template for template in responses.values()]
    write(output, context.output_format)
github Sceptre / sceptre / sceptre / cli / list.py View on Github external
def list_outputs(ctx, path, export):
    """
    List outputs for stack.
    \f

    :param path: Path to execute the command on.
    :type path: str
    :param export: Specify the export formatting.
    :type export: str
   """
    context = SceptreContext(
        command_path=path,
        project_path=ctx.obj.get("project_path", None),
        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 = [
        response for response
        in plan.describe_outputs().values() if response
    ]

    if export == "envvar":
        for response in responses:
github Sceptre / sceptre / sceptre / cli / delete.py View on Github external
def delete_command(ctx, path, change_set_name, yes):
    """
    Deletes a stack for a given config PATH. Or if CHANGE_SET_NAME is specified
    deletes a change set for stack in PATH.
    \f

    :param path: Path to execute command on.
    :type path: str
    :param change_set_name: The name of the change set to use - optional
    :type change_set_name: str
    :param yes: Flag to answer yes to all CLI questions.
    :type yes: bool
    """
    context = SceptreContext(
        command_path=path,
        project_path=ctx.obj.get("project_path"),
        user_variables=ctx.obj.get("user_variables"),
        options=ctx.obj.get("options"),
        ignore_dependencies=ctx.obj.get("ignore_dependencies")
    )

    plan = SceptrePlan(context)
    plan.resolve(command='delete', reverse=True)

    if change_set_name:
        delete_msg = "The Change Set will be delete on the following stacks, if applicable:\n"
    else:
        delete_msg = "The following stacks, in the following order, will be deleted:\n"

    dependencies = ''