示例#1
0
def get_peering_map(config: Sequence[dict]) -> dict:
    """
    Takes the config and yields a dictionary of accounts, regions,
    vpcs and the vpcs they should be peered with like so:
    Returns:
    {
        "415432961280": {
            "ap-southeast-2": {
                "vpc-e08fb484": [
                    "vpc-be8fb4da",
                    "vpc-7a83b81e",
                    "vpc-00a4011afa3b4e55f"
                ],
                "vpc-be8fb4da": [
                    "vpc-e08fb484",
                    "vpc-7a83b81e",
                    "vpc-00a4011afa3b4e55f"
                ],
                "vpc-7a83b81e": [
                    "vpc-e08fb484",
                    "vpc-be8fb4da",
                    "vpc-00a4011afa3b4e55f"
                ]
            },
            "ap-southeast-1": {
                "vpc-00a4011afa3b4e55f": [
                    "vpc-e08fb484",
                    "vpc-be8fb4da",
                    "vpc-7a83b81e"
                ]
            }
        }
    }

    :param config: A list containing dictionaries representing the configuration for the environment
    :type config: list
    :param metadata: A dictionary with the environment, owner, etc
    :type metadata: list
    :returns: A dictionary of accounts, regions, vpcs and configured peer vpcs
    :rtype: dict
    """
    peering_map = nested_dict()
    for requester in config:
        peering_map[requester['account_id']][requester['region']][
            requester['vpc_id']] = []
        for accepter in config:
            if accepter['vpc_id'] != requester['vpc_id']:
                peering_map[requester['account_id']][requester['region']][
                    requester['vpc_id']].append(accepter['vpc_id'])
    return peering_map
示例#2
0
文件: aws.py 项目: m1keil/peerd
import sys
from time import sleep

# Third Party
import boto3
import botocore
from botocore.config import Config

# Local
from peerd import LOGGER, nested_dict
from peerd.decorators import memoize

# Global data structures

# Global variablees
CLIENT_CACHE = nested_dict()
COMMON_PRINCIPAL_NAME: str = None
ROLE_SESSION_NAME: str = None
STS_CLIENT_CACHE = None


def aws_sts_client():
    """
    Uses default boto credentials locations, such as the instance metadata
    to return a sts client connection and caches it as a global variable for reuse.

    :returns: AWS STS client connection
    """
    global STS_CLIENT_CACHE

    if not STS_CLIENT_CACHE: