def resources(self) -> [ListResourcesResponse]: """Get a list of these resources""" resources = [] # https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ec2.html#EC2.Paginator.DescribeSnapshots paginator = self.client.get_paginator("describe_snapshots") # Apply a filter, otherwise we get public EBS snapshots too, from randos on the internet. page_iterator = paginator.paginate( Filters=[{ "Name": "owner-id", "Values": [self.current_account_id] }]) for page in page_iterator: these_resources = page["Snapshots"] for resource in these_resources: snapshot_id = resource.get("SnapshotId") kms_key_id = resource.get("KmsKeyId") volume_id = resource.get("VolumeId") arn = f"arn:aws:ec2:{self.region}:{self.current_account_id}:snapshot/{snapshot_id}" list_resources_response = ListResourcesResponse( service=self.service, account_id=self.current_account_id, arn=arn, region=self.region, resource_type=self.resource_type, name=snapshot_id) resources.append(list_resources_response) return resources
def resources(self) -> [ListResourcesResponse]: """Get a list of these resources""" resources = [] paginator = self.client.get_paginator("list_queues") page_iterator = paginator.paginate() for page in page_iterator: these_resources = page.get("QueueUrls") if these_resources: for resource in these_resources: # queue URL takes the format: # "https://{REGION_ENDPOINT}/queue.|api-domain|/{YOUR_ACCOUNT_NUMBER}/{YOUR_QUEUE_NAME}" # Let's split it according to /, and the name is the last item on the list queue_url = resource name = queue_url.split("/")[-1] arn = f"arn:aws:sqs:{self.region}:{self.current_account_id}:{name}" list_resources_response = ListResourcesResponse( service=self.service, account_id=self.current_account_id, arn=arn, region=self.region, resource_type=self.resource_type, name=name, note=queue_url) resources.append(list_resources_response) return resources
def resources(self) -> [ListResourcesResponse]: """Get a list of these resources""" resources = [] paginator = self.client.get_paginator("list_roles") page_iterator = paginator.paginate() for page in page_iterator: roles = page["Roles"] for role in roles: path = role.get("Path") arn = role.get("Arn") name = role.get("RoleName") # Special case: Ignore Service Linked Roles if path.startswith("/aws-service-role/"): # if path == "/service-role/" or path.startswith("/aws-service-role/"): continue list_resources_response = ListResourcesResponse( service=self.service, account_id=self.current_account_id, arn=arn, region=self.region, resource_type=self.resource_type, name=name) resources.append(list_resources_response) return resources
def filter_with_aliases(all_key_arns) -> list: keys = [] key_arns_with_aliases = [] aws_managed_key_arns = [] paginator = self.client.get_paginator("list_aliases") page_iterator = paginator.paginate() for page in page_iterator: these_resources = page["Aliases"] for resource in these_resources: alias = resource.get("AliasName") key_id = resource.get("TargetKeyId") arn = resource.get("AliasArn") if alias.startswith("alias/aws") or alias.startswith( "aws/"): aws_managed_key_arns.append(arn) if key_id: aws_managed_key_arns.append( f"arn:aws:kms:{self.region}:{self.current_account_id}:key/{key_id}" ) continue else: # keys.append(alias) arn = f"arn:aws:{self.service}:{self.region}:{self.current_account_id}:{self.resource_type}/{key_id}" list_resources_response = ListResourcesResponse( service=self.service, account_id=self.current_account_id, arn=arn, region=self.region, resource_type=self.resource_type, name=key_id, note=alias) keys.append(list_resources_response) key_arns_with_aliases.append(arn) # If the key does not have an alias, return the key ID for some_key_arn in all_key_arns: if some_key_arn not in key_arns_with_aliases and some_key_arn not in aws_managed_key_arns: key_id = get_resource_path_from_arn(some_key_arn) arn = f"arn:aws:{self.service}:{self.region}:{self.current_account_id}:{self.resource_type}/{key_id}" list_resources_response = ListResourcesResponse( service=self.service, account_id=self.current_account_id, arn=arn, region=self.region, resource_type=self.resource_type, name=key_id) keys.append(list_resources_response) return keys
def resources(self) -> [ListResourcesResponse]: """Get a list of these resources""" resources = [] response = self.client.list_domain_names() if response.get("DomainNames"): for domain_name in response.get("DomainNames"): name = domain_name.get("DomainName") arn = f"arn:aws:{self.service}:{self.region}:{self.current_account_id}:{self.resource_type}/{name}" list_resources_response = ListResourcesResponse( service=self.service, account_id=self.current_account_id, arn=arn, region=self.region, resource_type=self.resource_type, name=name) # resources.append(domain_name.get("DomainName")) resources.append(list_resources_response) return resources
def resources(self) -> [ListResourcesResponse]: """Get a list of these resources""" resources = [] paginator = self.client.get_paginator("list_identities") page_iterator = paginator.paginate() for page in page_iterator: these_resources = page["Identities"] for resource in these_resources: arn = f"arn:aws:ses:{self.region}:{self.current_account_id}:identity/{resource}" list_resources_response = ListResourcesResponse( service=self.service, account_id=self.current_account_id, arn=arn, region=self.region, resource_type=self.resource_type, name=resource) resources.append(list_resources_response) return resources
def resources(self) -> [ListResourcesResponse]: """Get a list of these resources""" response = self.client.list_buckets() resources = [] for resource in response.get("Buckets"): name = resource.get("Name") arn = f"arn:aws:{self.service}:::{name}" list_resources_response = ListResourcesResponse( service=self.service, account_id=self.current_account_id, arn=arn, region=self.region, resource_type=self.resource_type, name=name) resources.append(list_resources_response) return resources
def resources(self) -> [ListResourcesResponse]: """Get a list of these resources""" resources = [] paginator = self.client.get_paginator('list_functions') page_iterator = paginator.paginate() for page in page_iterator: functions = page["Functions"] for function in functions: name = function.get("FunctionName") arn = function.get("FunctionArn") list_resources_response = ListResourcesResponse( service=self.service, account_id=self.current_account_id, arn=arn, region=self.region, resource_type=self.resource_type, name=name) resources.append(list_resources_response) return resources
def resources(self) -> [ListResourcesResponse]: """Get a list of these resources""" resources = [] layers = self.layers for layer_name in layers: layer_arns = self.layer_version_arns(layer_name) for arn in layer_arns: list_resources_response = ListResourcesResponse( service=self.service, account_id=self.current_account_id, arn=arn, region=self.region, resource_type=self.resource_type, name=layer_name) resources.append(list_resources_response) return resources
def resources(self) -> [ListResourcesResponse]: """Get a list of these resources""" resources = [] paginator = self.client.get_paginator("describe_db_snapshots") page_iterator = paginator.paginate() for page in page_iterator: these_resources = page["DBSnapshots"] for resource in these_resources: snapshot_identifier = resource.get("DBSnapshotIdentifier") instance_identifier = resource.get("DBInstanceIdentifier") arn = resource.get("DBSnapshotArn") snapshot_name = get_resource_path_from_arn(arn) # arn:${Partition}:rds:${Region}:${Account}:snapshot:${SnapshotName} list_resources_response = ListResourcesResponse( service=self.service, account_id=self.current_account_id, arn=arn, region=self.region, resource_type=self.resource_type, name=snapshot_name) resources.append(list_resources_response) return resources
def resources(self) -> [ListResourcesResponse]: """Get a list of these resources""" resources = [] paginator = self.client.get_paginator("list_vaults") page_iterator = paginator.paginate() for page in page_iterator: these_resources = page["VaultList"] for resource in these_resources: name = resource.get("VaultName") arn = resource.get("VaultARN") list_resources_response = ListResourcesResponse( service=self.service, account_id=self.current_account_id, arn=arn, region=self.region, resource_type=self.resource_type, name=name) resources.append(list_resources_response) return resources
def resources(self) -> [ListResourcesResponse]: """Get a list of these resources""" these_resources = [] paginator = self.client.get_paginator('list_topics') page_iterator = paginator.paginate() for page in page_iterator: resources = page["Topics"] for resource in resources: arn = resource.get("TopicArn") name = get_resource_string(arn) list_resources_response = ListResourcesResponse( service=self.service, account_id=self.current_account_id, arn=arn, region=self.region, resource_type=self.resource_type, name=name) these_resources.append(list_resources_response) return these_resources
def resources(self) -> [ListResourcesResponse]: """Get a list of these resources""" resources = [] response = self.client.describe_images( Owners=[self.current_account_id]) these_resources = response["Images"] for resource in these_resources: image_id = resource.get("ImageId") name = resource.get("Name") volume_id = resource.get("VolumeId") arn = f"arn:aws:ec2:{self.region}:{self.current_account_id}:{self.resource_type}/{image_id}" list_resources_response = ListResourcesResponse( service=self.service, account_id=self.current_account_id, arn=arn, region=self.region, resource_type=self.resource_type, name=image_id) resources.append(list_resources_response) return resources
def resources(self) -> [ListResourcesResponse]: """Get a list of these resources""" resources = [] paginator = self.client.get_paginator("describe_file_systems") page_iterator = paginator.paginate() for page in page_iterator: these_resources = page["FileSystems"] for resource in these_resources: fs_id = resource.get("FileSystemId") arn = resource.get("FileSystemArn") list_resources_response = ListResourcesResponse( service=self.service, account_id=self.current_account_id, arn=arn, region=self.region, resource_type=self.resource_type, name=fs_id) resources.append(list_resources_response) return resources
def resources(self) -> [ListResourcesResponse]: """Get a list of these resources""" resources = [] paginator = self.client.get_paginator("list_certificate_authorities") page_iterator = paginator.paginate() for page in page_iterator: these_resources = page["CertificateAuthorities"] for resource in these_resources: arn = resource.get("Arn") status = resource.get("Status") ca_type = resource.get("Type") name = get_resource_path_from_arn(arn) list_resources_response = ListResourcesResponse( service=self.service, account_id=self.current_account_id, arn=arn, region=self.region, resource_type=self.resource_type, name=name) if status == "ACTIVE": resources.append(list_resources_response) return resources