aws-sh-controls-mngr.py
def dump(region, verbose):
    """
    For each susbscribed standard, collects and dumps each security hub control and
    its status to standard output.

    The same file structure is used when applying changes to it.
    """
    if verbose:
        click.secho("Collect controls settings for the security hub", bold=True)

    client = boto3.client('securityhub', region_name=region)

    subs = client.get_enabled_standards()

    all_controls = {}
    for s in subs["StandardsSubscriptions"]:
        standard = reusable_arn(arn=s['StandardsArn'], region=region)
        all_controls[standard] = {}
        all_controls[standard]['subscription_arn'] = reusable_arn(
            arn=s['StandardsSubscriptionArn'],
            region=region,
        )
        all_controls[standard]['status'] = s['StandardsStatus']

        controls = client.describe_standards_controls(
            StandardsSubscriptionArn=s["StandardsSubscriptionArn"]
        )

        if verbose:
            click.secho(f"\n\nControls for {standard}", bold=True)
            # print(json.dumps(controls, indent=2, cls=DateTimeEncoder))

        details = {}
        for c in controls["Controls"]:
            details[c['ControlId']] = {
                "arn": reusable_arn(
                    arn=c['StandardsControlArn'],
                    region=region,
                ),
                "title": c['Title'],
                "description": c['Description'],
                "severity": c['SeverityRating'],
                "status": c['ControlStatus'],
                "disabled_reason": c['DisabledReason'] if 'DisabledReason' in c else "n/a",
            }
            if verbose:
                click.echo(f"{c['ControlId']}|{c['ControlStatus']}|{c['StandardsControlArn']}|{c['Title']}")
        all_controls[standard]['controls']= details
    
    click.echo(yaml.dump(all_controls, sort_keys=False))

    For each susbscribed standard, collects and dumps each security hub control and
    its status to standard output.

    The same file structure is used when applying changes to it.
    
For each susbscribed standard, collects and dumps each security hub control and
its status to standard output.

The same file structure is used when applying changes to it.
For each susbscribed standard collects and dumps each security hub control and its status to standard output . The same file structure is used when applying changes to it .
def dump(region, verbose):
    if verbose:
        click.secho("Collect controls settings for the security hub", bold=True)
    client = boto3.client('securityhub', region_name=region)
    subs = client.get_enabled_standards()
    all_controls = {}
    for s in subs["StandardsSubscriptions"]:
        standard = reusable_arn(arn=s['StandardsArn'], region=region)
        all_controls[standard] = {}
        all_controls[standard]['subscription_arn'] = reusable_arn(
            arn=s['StandardsSubscriptionArn'],
            region=region,
        )
        all_controls[standard]['status'] = s['StandardsStatus']
        controls = client.describe_standards_controls(
            StandardsSubscriptionArn=s["StandardsSubscriptionArn"]
        )
        if verbose:
            click.secho(f"\n\nControls for {standard}", bold=True)
        details = {}
        for c in controls["Controls"]:
            details[c['ControlId']] = {
                "arn": reusable_arn(
                    arn=c['StandardsControlArn'],
                    region=region,
                ),
                "title": c['Title'],
                "description": c['Description'],
                "severity": c['SeverityRating'],
                "status": c['ControlStatus'],
                "disabled_reason": c['DisabledReason'] if 'DisabledReason' in c else "n/a",
            }
            if verbose:
                click.echo(f"{c['ControlId']}|{c['ControlStatus']}|{c['StandardsControlArn']}|{c['Title']}")
        all_controls[standard]['controls']= details
    click.echo(yaml.dump(all_controls, sort_keys=False))
def dump ( region , verbose ) : if verbose : click . secho ( "Collect controls settings for the security hub" , bold = True ) client = boto3 . client ( 'securityhub' , region_name = region ) subs = client . get_enabled_standards ( ) all_controls = { } for s in subs [ "StandardsSubscriptions" ] : standard = reusable_arn ( arn = s [ 'StandardsArn' ] , region = region ) all_controls [ standard ] = { } all_controls [ standard ] [ 'subscription_arn' ] = reusable_arn ( arn = s [ 'StandardsSubscriptionArn' ] , region = region , ) all_controls [ standard ] [ 'status' ] = s [ 'StandardsStatus' ] controls = client . describe_standards_controls ( StandardsSubscriptionArn = s [ "StandardsSubscriptionArn" ] ) if verbose : click . secho ( f"\n\nControls for {standard}" , bold = True ) details = { } for c in controls [ "Controls" ] : details [ c [ 'ControlId' ] ] = { "arn" : reusable_arn ( arn = c [ 'StandardsControlArn' ] , region = region , ) , "title" : c [ 'Title' ] , "description" : c [ 'Description' ] , "severity" : c [ 'SeverityRating' ] , "status" : c [ 'ControlStatus' ] , "disabled_reason" : c [ 'DisabledReason' ] if 'DisabledReason' in c else "n/a" , } if verbose : click . echo ( f"{c['ControlId']}|{c['ControlStatus']}|{c['StandardsControlArn']}|{c['Title']}" ) all_controls [ standard ] [ 'controls' ] = details click . echo ( yaml . dump ( all_controls , sort_keys = False ) )
For each susbscribed standard, collects and dumps each security hub control and
its status to standard output.
For each susbscribed standard collects and dumps each security hub control and its status to standard output .
"""
    For each susbscribed standard, collects and dumps each security hub control and
    its status to standard output.

    The same file structure is used when applying changes to it.
    """ # print(json.dumps(controls, indent=2, cls=DateTimeEncoder))
region
verbose