Пример #1
0
def test_jsonfmt():
    output = utils.jsonfmt(SIMPLE_ORG_SPEC)
    assert isinstance(output, str)
    dt = datetime.datetime.utcnow()
    output = utils.jsonfmt(dt)
    assert isinstance(output, str)
    account = orgs.OrgAccount(
        orgs.Org(MASTER_ACCOUNT_ID, ORG_ACCESS_ROLE),
        name='account01',
        id='112233445566',
        email='*****@*****.**',
    )
    output = utils.jsonfmt(account, orgs.OrgObject.dump)
    assert isinstance(output, str)
Пример #2
0
def main(master_role, config_file):
    """
    Usage:

      cidrrunner -r MyIamRole -f ~/.config/cidr-runner.yaml
    """

    config = util.load_config(config_file)
    crawler = setup_crawler(
        master_role,
        accounts=config['accounts'],
        regions=config['regions'],
    )
    s3_bucket = util.setup_s3_bucket(config, crawler)
    base_obj_path = util.set_base_object_path()

    for payload_name in config['payloads']:
        #print('runnning payload: {}'.format(payload_name))

        obj_path = base_obj_path + '/' + payload_name + '.json'
        f = eval('payload.' + payload_name)
        execution = crawler.execute(f)

        text_stream = io.StringIO()
        for response in execution.responses:
            text_stream.write(jsonfmt(response.dump()) + '\n')
        s3_bucket.put_object(Key=obj_path, Body=text_stream.getvalue())
Пример #3
0
def main(master_role, account_role, regions, accounts,
        service, payload_file, payload, payload_arg):
    """
Arguments:

    \b
    PAYLOAD       Name of the payload function to run in each account
    PAYLOAD_ARG   The payload function argument(s) if any

Orgcrawler attempts to resolve payload function name from $PYTHON_PATH

Examples:

    \b
    orgcrawler -h
    orgcrawler -r OrgMasterRole orgcrawler.payloads.list_buckets
    orgcrawler -r OrgMasterRole --account-role S3Admin orgcrawler.payloads.list_buckets
    orgcrawler -r OrgMasterRole --service codecommit -f ~/my_payloads.py list_cc_repositories
    orgcrawler -r OrgMasterRole --service iam orgcrawler.payloads.get_account_aliases
    orgcrawler -r OrgMasterRole --accounts app-test,app-prod \\
            --regions us-east-1,us-west-2 orgcrawler.payloads.config_describe_rules
    """
    crawler_args = dict()
    if accounts:
        crawler_args['accounts'] = accounts.split(',')
    if service:
        crawler_args['regions'] = regions_for_service(service)
    elif regions:
        crawler_args['regions'] = regions.split(',')
    if account_role:
        crawler_args['account_access_role'] = account_role
    if payload_file:
        payload = get_payload_function_from_file(payload_file, payload)
    else:
        payload = get_payload_function_from_string(payload)

    crawler = setup_crawler(master_role, **crawler_args)
    execution = crawler.execute(payload, *payload_arg)
    click.echo(jsonfmt(format_responses(execution)))
Пример #4
0
def main(readwrite_role, task_spec_file, execute):
    '''
    Usage:

      taskrunner -f /path/to/task-spec.yaml

      taskrunner -f /path/to/task-spec.yaml -r MyIamRole --exec

    '''
    #print('readwrite_role:', readwrite_role)
    #print('task_spec_file:', task_spec_file)
    #print('execute:', execute)
    task_spec = tasks.validate_task_spec(task_spec_file)
    #print(yamlfmt(task_spec))
    org_access_role = task_spec['readonly_role']
    master_account_id = tasks.validate_master_account_id(
        org_access_role,
        task_spec['master_account_id'],
    )

    org = orgcrawler.orgs.Org(master_account_id, org_access_role)
    org.load()

    for task in task_spec['tasks']:

        kwargs = task.get('kwargs', dict())
        kwargs['dryrun'] = not execute
        #print('kwargs:\n{}'.format(yamlfmt(kwargs)))

        crawler = orgcrawler.crawlers.Crawler(
            org,
            access_role=readwrite_role,
            regions=task['regions'],
            accounts=task['accounts'],
        )
        crawler.load_account_credentials()
        payload = get_payload_function_from_string(task['payload'])
        execution = crawler.execute(payload, **kwargs)
        click.echo(jsonfmt(execution.dump()))
Пример #5
0
def main(master_role, account_role, regions, accounts, service, payload_file,
         payload, payload_arg):
    ''' Where 'PAYLOAD' is name of the payload function to run in each account,
    and 'PAYLOAD_ARG' is, you guessed it, any payload function argument(s).
    Orgcrawler attempts to resolve payload function name from $PYTHON_PATH '''

    crawler_args = dict()
    if accounts:
        crawler_args['accounts'] = accounts.split(',')
    if service:
        crawler_args['regions'] = regions_for_service(service)
    elif regions:
        crawler_args['regions'] = regions.split(',')
    if account_role:
        crawler_args['account_access_role'] = account_role
    if payload_file:
        payload = get_payload_function_from_file(payload_file, payload)
    else:
        payload = get_payload_function_from_string(payload)

    crawler = setup_crawler(master_role, **crawler_args)
    execution = crawler.execute(payload, *payload_arg)
    click.echo(jsonfmt(format_responses(execution)))
Пример #6
0
def jsonfmt(obj):
    return utils.jsonfmt(obj, orgs.OrgObject.dump)