def get_load_balancer_v2_listeners(client: botocore.client.BaseClient, load_balancer_arn: str) -> List[Dict]:
    paginator = client.get_paginator('describe_listeners')
    listeners: List[Dict] = []
    for page in paginator.paginate(LoadBalancerArn=load_balancer_arn):
        listeners.extend(page['Listeners'])

    return listeners
Esempio n. 2
0
def get_zone_record_sets(client: botocore.client.BaseClient,
                         zone_id: str) -> List[Dict]:
    resource_record_sets: List[Dict] = []
    paginator = client.get_paginator('list_resource_record_sets')
    pages = paginator.paginate(HostedZoneId=zone_id)
    for page in pages:
        resource_record_sets.extend(page['ResourceRecordSets'])
    return resource_record_sets
Esempio n. 3
0
def get_function_aliases(lambda_function: Dict,
                         client: botocore.client.BaseClient) -> List[Any]:
    aliases: List[Any] = []
    paginator = client.get_paginator('list_aliases')
    for page in paginator.paginate(
            FunctionName=lambda_function['FunctionName']):
        aliases.extend(page['Aliases'])

    return aliases
Esempio n. 4
0
def get_event_source_mappings(lambda_function: Dict,
                              client: botocore.client.BaseClient) -> List[Any]:
    event_source_mappings: List[Any] = []
    paginator = client.get_paginator('list_event_source_mappings')
    for page in paginator.paginate(
            FunctionName=lambda_function['FunctionName']):
        event_source_mappings.extend(page['EventSourceMappings'])

    return event_source_mappings
Esempio n. 5
0
def get_aliases(key: Dict, client: botocore.client.BaseClient) -> List[Any]:
    """
    Gets the KMS Key Aliases.
    """
    aliases: List[Any] = []
    paginator = client.get_paginator('list_aliases')
    for page in paginator.paginate(KeyId=key['KeyId']):
        aliases.extend(page['Aliases'])

    return aliases
Esempio n. 6
0
def get_grants(key: str, client: botocore.client.BaseClient) -> List[Any]:
    """
    Gets the KMS Key Grants.
    """
    grants: List[Any] = []
    paginator = client.get_paginator('list_grants')
    for page in paginator.paginate(KeyId=key['KeyId']):  # type: ignore
        grants.extend(page['Grants'])

    return grants
Esempio n. 7
0
def get_rest_api_resources(api: Dict, client: botocore.client.BaseClient) -> List[Any]:
    """
    Gets the collection of Resource resources.
    """
    resources: List[Any] = []
    paginator = client.get_paginator('get_resources')
    response_iterator = paginator.paginate(restApiId=api['id'])
    for page in response_iterator:
        resources.extend(page['items'])

    return resources
Esempio n. 8
0
def get_zones(
        client: botocore.client.BaseClient) -> List[Tuple[Dict, List[Dict]]]:
    paginator = client.get_paginator('list_hosted_zones')
    hosted_zones: List[Dict] = []
    for page in paginator.paginate():
        hosted_zones.extend(page['HostedZones'])

    results: List[Tuple[Dict, List[Dict]]] = []
    for hosted_zone in hosted_zones:
        record_sets = get_zone_record_sets(client, hosted_zone['Id'])
        results.append((hosted_zone, record_sets))
    return results
def get_load_balancer_v2_target_groups(client: botocore.client.BaseClient, load_balancer_arn: str) -> List[Dict]:
    paginator = client.get_paginator('describe_target_groups')
    target_groups: List[Dict] = []
    for page in paginator.paginate(LoadBalancerArn=load_balancer_arn):
        target_groups.extend(page['TargetGroups'])

    # Add instance data
    for target_group in target_groups:
        target_group['Targets'] = []
        target_health = client.describe_target_health(TargetGroupArn=target_group['TargetGroupArn'])
        for target_health_description in target_health['TargetHealthDescriptions']:
            target_group['Targets'].append(target_health_description['Target']['Id'])

    return target_groups
Esempio n. 10
0
def full_results(
    client: botocore.client.BaseClient,
    method: str,
    args: List[str],
    kwargs: Dict[str, Any],
) -> Dict[str, Any]:
    """Returns JSON results for an AWS botocore call. Flattens paginated results (if any)."""
    if client.can_paginate(method):
        paginator = client.get_paginator(method)
        full_result: Dict[str, Any] = paginator.paginate(
            *args, **kwargs
        ).build_full_result()
        return full_result
    else:
        single_result: Dict[str, Any] = getattr(client, method)(*args, **kwargs)
        return single_result
Esempio n. 11
0
def scan_s3_files(s3: botocore.client.BaseClient, bucket: str, prefix: str):
    print(f"Start scanning! - S3 Path: {bucket}/{prefix}")
    paginator: botocore.paginate.Paginator = s3.get_paginator("list_objects_v2")
    pages: botocore.paginate.PageIterator = paginator.paginate(Bucket=bucket, Prefix=prefix)
    path_key_list = list()    
    for idx, page in enumerate(pages):
        print(f"Page: {idx}")
        sum_val = 0
        if page.get("Contents"):
            for obj in page["Contents"]:
                sum_val += 1
                path_key_list.append(obj["Key"])
                print(f"Full path {bucket}/{obj['Key']}")
            
    print(f"Files are successfully scanned!")
    return path_key_list
Esempio n. 12
0
def get_grants(key: Dict, client: botocore.client.BaseClient) -> List[Any]:
    """
    Gets the KMS Key Grants.
    """
    grants: List[Any] = []
    paginator = client.get_paginator('list_grants')
    try:
        for page in paginator.paginate(KeyId=key['KeyId']):
            grants.extend(page['Grants'])
    except ClientError as e:
        if e.response['Error']['Code'] == 'AccessDeniedException':
            logger.warning(
                f'kms:list_grants on key_id {key["KeyId"]} failed with AccessDeniedException; continuing sync.',
                exc_info=True,
            )
        else:
            raise
    return grants