Example #1
0
def dynamodb_to_ecs(xresources, services_stack, services_families,
                    res_root_stack, settings):
    """
    Function to link the resource and the ECS Services.

    :param dict xresources:
    :param ecs_composex.common.stacks.ComposeXStack services_stack:
    :param dict services_families:
    :param ecs_composex.common.stacks.ComposeXStack res_root_stack:
    :param ecs_composex.common.settings.ComposeXSettings settings:
    :return:
    """
    l_tables = xresources.copy()
    handle_new_tables(xresources, services_families, services_stack,
                      res_root_stack, l_tables)
    for table_name in l_tables:
        table = xresources[table_name]
        validate_lookup_resource(table_name, table, res_root_stack)
        found_resources = lookup_dyn_table(settings.session,
                                           table["Lookup"]["Tags"])
        if not found_resources:
            LOG.warning(
                f"404 not tables found with the provided tags was found in defintion {table_name}."
            )
            continue
        for found_table in found_resources:
            table.update(found_table)
            perms = generate_resource_permissions(found_table["Name"],
                                                  ACCESS_TYPES,
                                                  TABLE_ARN,
                                                  arn=found_table["Arn"])
            envvars = generate_resource_envvars(
                found_table["Name"],
                xresources[table_name],
                TABLE_ARN,
                arn=found_table["Arn"],
            )
            apply_iam_based_resources(
                table,
                services_families,
                services_stack,
                res_root_stack,
                envvars,
                perms,
            )
Example #2
0
def handle_new_topics(
    xresources,
    services_families,
    services_stack,
    res_root_stack,
    l_topics,
    nested=False,
):
    topics_r = []
    s_resources = res_root_stack.stack_template.resources
    for resource_name in s_resources:
        if isinstance(s_resources[resource_name], Topic):
            topics_r.append(s_resources[resource_name].title)
        elif issubclass(type(s_resources[resource_name]), ComposeXStack):
            handle_new_topics(
                xresources,
                services_families,
                services_stack,
                s_resources[resource_name],
                l_topics,
                nested=True,
            )

    for topic_name in xresources:
        if topic_name in topics_r:
            perms = generate_resource_permissions(topic_name, ACCESS_TYPES,
                                                  TOPIC_ARN_T)
            envvars = generate_resource_envvars(topic_name,
                                                xresources[topic_name],
                                                TOPIC_ARN_T)
            apply_iam_based_resources(
                xresources[topic_name],
                services_families,
                services_stack,
                res_root_stack,
                envvars,
                perms,
                nested,
            )
            del l_topics[topic_name]
Example #3
0
def handle_new_queues(
    xresources,
    services_families,
    services_stack,
    res_root_stack,
    l_queues,
    nested=False,
):
    queues_r = []
    s_resources = res_root_stack.stack_template.resources
    for resource_name in s_resources:
        if isinstance(s_resources[resource_name], Queue):
            queues_r.append(s_resources[resource_name].title)
        elif issubclass(type(s_resources[resource_name]), ComposeXStack):
            handle_new_queues(
                xresources,
                services_families,
                services_stack,
                s_resources[resource_name],
                l_queues,
                nested=True,
            )

    for queue_name in xresources:
        if queue_name in queues_r:
            perms = generate_resource_permissions(queue_name, ACCESS_TYPES,
                                                  SQS_ARN.title)
            envvars = generate_resource_envvars(queue_name,
                                                xresources[queue_name],
                                                SQS_URL)
            apply_iam_based_resources(
                xresources[queue_name],
                services_families,
                services_stack,
                res_root_stack,
                envvars,
                perms,
                nested,
            )
            del l_queues[queue_name]
Example #4
0
def handle_new_keys(
    xresources,
    services_families,
    services_stack,
    res_root_stack,
    l_keys,
    nested=False,
):
    keys_r = []
    s_resources = res_root_stack.stack_template.resources
    for resource_name in s_resources:
        if isinstance(s_resources[resource_name], Key):
            keys_r.append(s_resources[resource_name].title)
        elif issubclass(type(s_resources[resource_name]), ComposeXStack):
            handle_new_keys(
                xresources,
                services_families,
                services_stack,
                s_resources[resource_name],
                l_keys,
                nested=True,
            )

    for key_name in xresources:
        if key_name in keys_r:
            perms = generate_resource_permissions(key_name, ACCESS_TYPES,
                                                  KMS_KEY_ARN_T)
            envvars = generate_resource_envvars(key_name, xresources[key_name],
                                                KMS_KEY_ARN_T)
            apply_iam_based_resources(
                xresources[key_name],
                services_families,
                services_stack,
                res_root_stack,
                envvars,
                perms,
                nested,
            )
            del l_keys[key_name]