def dry_run(f):
    manifest = manifest_utils.load(f)

    launch_tasks = {}
    tasks_to_run = []

    all_launch_tasks = cli_command_helpers.deploy_launches(manifest)
    launch_tasks.update(all_launch_tasks)

    for task in cli_command_helpers.wire_dependencies(launch_tasks):
        task_status = task.get('status')
        del task['status']
        if task_status == constants.PROVISIONED:
            tasks_to_run.append(
                luigi_tasks_and_targets.ProvisionProductDryRunTask(**task))
        elif task_status == constants.TERMINATED:
            tasks_to_run.append(
                luigi_tasks_and_targets.TerminateProductDryRunTask(**task))
        else:
            raise Exception(f"Unsupported status of {task_status}")

    # spoke_local_portfolio_tasks_to_run = cli_command_helpers.deploy_spoke_local_portfolios(manifest, launch_tasks)
    # tasks_to_run += spoke_local_portfolio_tasks_to_run

    cli_command_helpers.run_tasks_for_dry_run(tasks_to_run)
def deploy(f, single_account):
    puppet_account_id = cli_command_helpers.get_puppet_account_id()

    manifest = manifest_utils.load(f)

    launch_tasks = {}
    tasks_to_run = []

    should_use_sns = cli_command_helpers.get_should_use_sns(
        os.environ.get("AWS_DEFAULT_REGION"))

    all_launch_tasks = cli_command_helpers.deploy_launches(
        manifest, puppet_account_id)
    launch_tasks.update(all_launch_tasks)

    for task in cli_command_helpers.wire_dependencies(launch_tasks):
        task_status = task.get('status')
        del task['status']
        if task_status == constants.PROVISIONED:
            task['should_use_sns'] = should_use_sns
            tasks_to_run.append(
                luigi_tasks_and_targets.ProvisionProductTask(**task))
        elif task_status == constants.TERMINATED:
            for attribute in constants.DISALLOWED_ATTRIBUTES_FOR_TERMINATED_LAUNCHES:
                logger.info(
                    f"checking {task.get('launch_name')} for disallowed attributes"
                )
                attribute_value = task.get(attribute)
                if attribute_value is not None:
                    if isinstance(attribute_value, list):
                        if len(attribute_value) != 0:
                            raise Exception(
                                f"Launch {task.get('launch_name')} has disallowed attribute: {attribute}"
                            )
                    elif isinstance(attribute_value, dict):
                        if len(attribute_value.keys()) != 0:
                            raise Exception(
                                f"Launch {task.get('launch_name')} has disallowed attribute: {attribute}"
                            )
                    else:
                        raise Exception(
                            f"Launch {task.get('launch_name')} has disallowed attribute: {attribute}"
                        )

            tasks_to_run.append(
                luigi_tasks_and_targets.TerminateProductTask(**task))
        else:
            raise Exception(f"Unsupported status of {task_status}")

    spoke_local_portfolio_tasks_to_run = cli_command_helpers.deploy_spoke_local_portfolios(
        manifest, launch_tasks, should_use_sns, puppet_account_id)
    tasks_to_run += spoke_local_portfolio_tasks_to_run

    cli_command_helpers.run_tasks(tasks_to_run)
def reset_provisioned_product_owner(f):
    manifest = manifest_utils.load(f)

    launch_tasks = {}
    tasks_to_run = []

    all_launch_tasks = cli_command_helpers.deploy_launches(manifest)
    launch_tasks.update(all_launch_tasks)

    for task in cli_command_helpers.wire_dependencies(launch_tasks):
        task_status = task.get('status')
        del task['status']
        if task_status == constants.PROVISIONED:
            tasks_to_run.append(
                luigi_tasks_and_targets.ResetProvisionedProductOwnerTask(
                    **task))

    cli_command_helpers.run_tasks(tasks_to_run)