Пример #1
0
def elbs(with_tags=True):
    """
    http://botocore.readthedocs.io/en/latest/reference/services/elb.html#ElasticLoadBalancing.Client.describe_load_balancers
    """
    elbs = (botocore_client.get(
        "elb", "describe_load_balancers", [],
        {}).extract_key("LoadBalancerDescriptions").flatten().values())

    if not with_tags:
        return elbs

    elbs_with_tags = []
    for elb in elbs:
        tags = (botocore_client.get(
            service_name="elb",
            method_name="describe_tags",
            call_args=[],
            call_kwargs={
                "LoadBalancerNames": [elb["LoadBalancerName"]]
            },
            regions=[elb["__pytest_meta"]["region"]],
        ).extract_key("TagDescriptions").flatten().values())
        # This check is probably unneeded
        if len(tags) >= 1:
            tags = tags[0]
        if "Tags" in tags:
            elb["Tags"] = tags["Tags"]
        elbs_with_tags.append(elb)

    return elbs_with_tags
Пример #2
0
def ec2_vpcs():
    "https://botocore.readthedocs.io/en/latest/reference/services/ec2.html#EC2.Client.describe_vpcs"
    return botocore_client.get(
        'ec2', 'describe_vpcs', [], {})\
        .extract_key('Vpcs')\
        .flatten()\
        .values()
Пример #3
0
def ec2_security_groups():
    "http://botocore.readthedocs.io/en/latest/reference/services/ec2.html#EC2.Client.describe_security_groups"
    return botocore_client.get(
        'ec2', 'describe_security_groups', [], {})\
        .extract_key('SecurityGroups')\
        .flatten()\
        .values()
Пример #4
0
def iam_managed_policies(username):
    "http://botocore.readthedocs.io/en/latest/reference/services/iam.html#IAM.Client.list_attached_user_policies"
    return botocore_client.get(
        'iam', 'list_attached_user_policies', [], {'UserName': username})\
        .extract_key('AttachedPolicies')\
        .flatten()\
        .values()
Пример #5
0
def redshift_clusters():
    "botocore.readthedocs.io/en/latest/reference/services/redshift.html#Redshift.Client.describe_clusters"
    return botocore_client.get(
        'redshift', 'describe_clusters', [], {})\
        .extract_key('Clusters')\
        .flatten()\
        .values()
def elbs():
    """
    http://botocore.readthedocs.io/en/latest/reference/services/elb.html#ElasticLoadBalancing.Client.describe_load_balancers
    """
    return (botocore_client.get(
        "elb", "describe_load_balancers", [],
        {}).extract_key("LoadBalancerDescriptions").flatten().values())
Пример #7
0
def iam_users():
    "http://botocore.readthedocs.io/en/latest/reference/services/iam.html#IAM.Client.list_users"
    return botocore_client.get(
        'iam', 'list_users', [], {})\
        .extract_key('Users')\
        .flatten()\
        .values()
def iam_mfa_devices(users):
    "botocore.readthedocs.io/en/latest/reference/services/iam.html#IAM.Client.list_mfa_devices"
    return [
        botocore_client.get("iam", "list_mfa_devices", [], {
            "UserName": user["UserName"]
        }).extract_key("MFADevices").values()[0] for user in users
    ]
Пример #9
0
def iam_user_groups(username):
    "http://botocore.readthedocs.io/en/latest/reference/services/iam.html#IAM.Client.list_groups_for_user"
    return botocore_client.get(
        'iam', 'list_groups_for_user', [], {'UserName': username})\
        .extract_key('Groups')\
        .flatten()\
        .values()
Пример #10
0
def iam_access_keys_for_user(username):
    "https://botocore.readthedocs.io/en/latest/reference/services/iam.html#IAM.Client.list_access_keys"
    return botocore_client.get(
        'iam', 'list_access_keys', [], {'UserName': username})\
        .extract_key('AccessKeyMetadata')\
        .flatten()\
        .values()
Пример #11
0
def rds_db_instances_vpc_security_groups():
    "http://botocore.readthedocs.io/en/latest/reference/services/ec2.html#EC2.Client.describe_security_groups"
    return [
        botocore_client.get(
            service_name="ec2",
            method_name="describe_security_groups",
            call_args=[],
            call_kwargs={
                "Filters": [{
                    "Name":
                    "group-id",
                    "Values": [
                        sg["VpcSecurityGroupId"]
                        for sg in instance["VpcSecurityGroups"]
                        if sg["Status"] == "active"
                    ],
                }]
            },
            profiles=[instance["__pytest_meta"]["profile"]],
            regions=[instance["__pytest_meta"]["region"]],
            result_from_error=lambda e, call: {"SecurityGroups": []},
        )  # treat not found as empty list
        .extract_key("SecurityGroups").flatten().values()
        for instance in rds_db_instances()
    ]
Пример #12
0
def iam_mfa_devices(users):
    "botocore.readthedocs.io/en/latest/reference/services/iam.html#IAM.Client.list_mfa_devices"
    return [
        botocore_client.get('iam', 'list_mfa_devices', [], {
            'UserName': user['UserName']
        }).extract_key('MFADevices').values()[0] for user in users
    ]
Пример #13
0
def iam_role_inline_policies(rolename):
    "http://botocore.readthedocs.io/en/latest/reference/services/iam.html#IAM.Client.list_role_policies"
    return botocore_client.get(
        'iam', 'list_role_policies', [], {'RoleName': rolename})\
        .extract_key('PolicyNames')\
        .flatten()\
        .values()
Пример #14
0
def autoscaling_launch_configurations():
    """
    http://botocore.readthedocs.io/en/latest/reference/services/autoscaling.html#AutoScaling.Client.describe_launch_configurations
    """
    return (botocore_client.get(
        "autoscaling", "describe_launch_configurations", [],
        {}).extract_key("LaunchConfigurations").flatten().values())
def ec2_vpcs():
    "https://botocore.readthedocs.io/en/latest/reference/services/ec2.html#EC2.Client.describe_vpcs"
    return (
        botocore_client.get("ec2", "describe_vpcs", [], {})
        .extract_key("Vpcs")
        .flatten()
        .values()
    )
Пример #16
0
def iam_users():
    "http://botocore.readthedocs.io/en/latest/reference/services/iam.html#IAM.Client.list_users"
    return (
        botocore_client.get("iam", "list_users", [], {})
        .extract_key("Users")
        .flatten()
        .values()
    )
Пример #17
0
def iam_user_groups(username):
    "http://botocore.readthedocs.io/en/latest/reference/services/iam.html#IAM.Client.list_groups_for_user"
    return (
        botocore_client.get("iam", "list_groups_for_user", [], {"UserName": username})
        .extract_key("Groups")
        .flatten()
        .values()
    )
Пример #18
0
def iam_inline_policies(username):
    "http://botocore.readthedocs.io/en/latest/reference/services/iam.html#IAM.Client.list_user_policies"
    return (
        botocore_client.get("iam", "list_user_policies", [], {"UserName": username})
        .extract_key("PolicyNames")
        .flatten()
        .values()
    )
Пример #19
0
def iam_access_keys_for_user(username):
    "https://botocore.readthedocs.io/en/latest/reference/services/iam.html#IAM.Client.list_access_keys"
    return (
        botocore_client.get("iam", "list_access_keys", [], {"UserName": username})
        .extract_key("AccessKeyMetadata")
        .flatten()
        .values()
    )
Пример #20
0
def s3_buckets():
    "http://botocore.readthedocs.io/en/latest/reference/services/s3.html#S3.Client.list_buckets"
    return (
        botocore_client.get("s3", "list_buckets", [], {})
        .extract_key("Buckets")
        .flatten()
        .values()
    )
Пример #21
0
def iam_user_group_inline_policies(username):
    "http://botocore.readthedocs.io/en/latest/reference/services/iam.html#IAM.Client.list_group_policies"
    return [
        botocore_client.get('iam', 'list_group_policies', [], {
            'GroupName': group['GroupName']
        }).extract_key('PolicyNames').flatten().values()
        for group in iam_user_groups(username)
    ]
Пример #22
0
def rds_db_security_groups():
    "http://botocore.readthedocs.io/en/latest/reference/services/rds.html#RDS.Client.describe_db_security_groups"
    sgs = []

    for response in botocore_client.get('rds', 'describe_db_security_groups', [], {}).values():
        sgs.extend(response['DBSecurityGroups'])

    return sgs
def redshift_clusters():
    "botocore.readthedocs.io/en/latest/reference/services/redshift.html#Redshift.Client.describe_clusters"
    return (
        botocore_client.get("redshift", "describe_clusters", [], {})
        .extract_key("Clusters")
        .flatten()
        .values()
    )
def iam_user_group_managed_policies(username):
    "http://botocore.readthedocs.io/en/latest/reference/services/iam.html#IAM.Client.list_attached_group_policies"
    return [
        botocore_client.get("iam", "list_attached_group_policies", [], {
            "GroupName": group["GroupName"]
        }).extract_key("AttachedPolicies").flatten().values()
        for group in iam_user_groups(username)
    ]
Пример #25
0
def redshift_cluster_security_groups():
    "http://botocore.readthedocs.io/en/latest/reference/services/redshift.html#Redshift.Client.describe_cluster_security_groups"  # NOQA
    return botocore_client.get(
        'redshift',
        'describe_cluster_security_groups', [], {},
        result_from_error=lambda error, call: {
            'ClusterSecurityGroups': []
        }).extract_key('ClusterSecurityGroups').flatten().values()
def iam_generate_credential_report():
    "http://botocore.readthedocs.io/en/latest/reference/services/iam.html#IAM.Client.generate_credential_report"
    results = botocore_client.get("iam",
                                  "generate_credential_report", [], {},
                                  do_not_cache=True).results
    if len(results):
        return results[0].get("State")
    return ""
Пример #27
0
def elasticache_clusters():
    """
    http://botocore.readthedocs.io/en/latest/reference/services/elasticache.html#ElastiCache.Client.describe_cache_clusters
    """
    return botocore_client.get(
        'elasticache', 'describe_cache_clusters', [], {})\
        .extract_key('CacheClusters')\
        .flatten()\
        .values()
Пример #28
0
def autoscaling_launch_configurations():
    """
    http://botocore.readthedocs.io/en/latest/reference/services/autoscaling.html#AutoScaling.Client.describe_launch_configurations
    """
    return botocore_client.get(
        'autoscaling', 'describe_launch_configurations', [], {})\
        .extract_key('LaunchConfigurations')\
        .flatten()\
        .values()
Пример #29
0
def elbs():
    """
    http://botocore.readthedocs.io/en/latest/reference/services/elb.html#ElasticLoadBalancing.Client.describe_load_balancers
    """
    return botocore_client.get(
        'elb', 'describe_load_balancers', [], {})\
        .extract_key('LoadBalancerDescriptions')\
        .flatten()\
        .values()
Пример #30
0
def zones():
    """
    https://botocore.amazonaws.com/v1/documentation/api/latest/reference/services/route53.html#Route53.Client.list_hosted_zones
    """
    return (
        botocore_client.get("route53", "list_hosted_zones", [], {})
        .extract_key("HostedZones")
        .flatten()
        .values()
    )