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
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()
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()
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()
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())
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 ]
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()
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()
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() ]
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 ]
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()
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() )
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_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() )
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() )
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() )
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() )
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) ]
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) ]
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 ""
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()
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 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()
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() )