Beispiel #1
0
def run(config, tag, bucket, account, debug=False):
    """Run across a set of accounts and buckets."""
    logging.basicConfig(
        level=logging.INFO,
        format="%(asctime)s: %(name)s:%(levelname)s %(message)s")
    logging.getLogger('botocore').setLevel(level=logging.WARNING)

    if debug:

        def invoke(f, *args, **kw):
            if f.func_name == 'process_keyset':
                print("skip keyset")
                return
            return f(*args, **kw)

        worker.invoke = invoke

    with open(config) as fh:
        data = json.load(fh)
        for account_info in data:
            if tag and tag not in account_info.get('tags', ()):
                continue
            if account and account_info['name'] not in account:
                continue
            if bucket:
                account_info['buckets'] = bucket
            worker.invoke(worker.process_account, account_info)
Beispiel #2
0
def run(config, tag, bucket, account, debug=False):
    """Run across a set of accounts and buckets."""
    logging.basicConfig(
        level=logging.INFO,
        format="%(asctime)s: %(name)s:%(levelname)s %(message)s")
    logging.getLogger('botocore').setLevel(level=logging.WARNING)

    if debug:
        def invoke(f, *args, **kw):
            if f.func_name == 'process_keyset':
                print("skip keyset")
                return
            return f(*args, **kw)
        worker.invoke = invoke

    with open(config) as fh:
        data = json.load(fh)
        for account_info in data:
            if tag and tag not in account_info.get('tags', ()):
                continue
            if account and account_info['name'] not in account:
                continue
            if bucket:
                account_info['buckets'] = bucket
            worker.invoke(worker.process_account, account_info)
Beispiel #3
0
def run(config, tag, bucket, account, not_bucket, not_account, debug, region):
    """Run across a set of accounts and buckets."""
    logging.basicConfig(
        level=logging.INFO,
        format="%(asctime)s: %(name)s:%(levelname)s %(message)s")
    logging.getLogger('botocore').setLevel(level=logging.WARNING)

    if debug:

        def invoke(f, *args, **kw):
            # if f.func_name == 'process_keyset':
            #    key_count = len(args[-1])
            #    print("debug skip keyset %d" % key_count)
            #    return
            return f(*args, **kw)

        worker.invoke = invoke

    with open(config) as fh:
        data = utils.yaml_load(fh.read())
        for account_info in data.get('accounts', ()):
            if tag and tag not in account_info.get('tags', ()):
                continue
            if account and account_info['name'] not in account:
                continue
            if not_account and account_info['name'] in not_account:
                continue
            if 'inventory' in data and 'inventory' not in account_info:
                account_info['inventory'] = data['inventory']
            if 'visitors' in data and 'visitors' not in account_info:
                account_info['visitors'] = data['visitors']
            if 'object-reporting' in data and 'object-reporting' not in account_info:
                account_info['object-reporting'] = data['object-reporting']
                account_info['object-reporting'][
                    'record-prefix'] = datetime.utcnow().strftime('%Y/%m/%d')
            if bucket:
                account_info['buckets'] = bucket
            if not_bucket:
                account_info['not-buckets'] = not_bucket
            if region:
                account_info['regions'] = region

            try:
                worker.invoke(worker.process_account, account_info)
            except Exception:
                if not debug:
                    raise
                import pdb, traceback, sys
                traceback.print_exc()
                pdb.post_mortem(sys.exc_info()[-1])
                raise
Beispiel #4
0
def run(config, tag, bucket, account, not_bucket, not_account, debug, region):
    """Run across a set of accounts and buckets."""
    logging.basicConfig(
        level=logging.INFO,
        format="%(asctime)s: %(name)s:%(levelname)s %(message)s")
    logging.getLogger('botocore').setLevel(level=logging.WARNING)

    if debug:
        def invoke(f, *args, **kw):
            # if f.func_name == 'process_keyset':
            #    key_count = len(args[-1])
            #    print("debug skip keyset %d" % key_count)
            #    return
            return f(*args, **kw)
        worker.invoke = invoke

    with open(config) as fh:
        data = utils.yaml_load(fh.read())
        for account_info in data.get('accounts', ()):
            if tag and tag not in account_info.get('tags', ()):
                continue
            if account and account_info['name'] not in account:
                continue
            if not_account and account_info['name'] in not_account:
                continue
            if 'inventory' in data and 'inventory' not in account_info:
                account_info['inventory'] = data['inventory']
            if 'visitors' in data and 'visitors' not in account_info:
                account_info['visitors'] = data['visitors']
            if 'object-reporting' in data and 'object-reporting' not in account_info:
                account_info['object-reporting'] = data['object-reporting']
                account_info['object-reporting'][
                    'record-prefix'] = datetime.utcnow().strftime('%Y/%m/%d')
            if bucket:
                account_info['buckets'] = bucket
            if not_bucket:
                account_info['not-buckets'] = not_bucket
            if region:
                account_info['regions'] = region

            try:
                worker.invoke(worker.process_account, account_info)
            except Exception:
                if not debug:
                    raise
                import pdb, traceback, sys
                traceback.print_exc()
                pdb.post_mortem(sys.exc_info()[-1])
                raise