Beispiel #1
0
 def load_policy_set(self, data, config=None):
     filename = self.write_policy_file(data)
     if config:
         e = Config.empty(**config)
     else:
         e = Config.empty()
     return policy.load(e, filename)
Beispiel #2
0
 def load_policy_set(self, data, config=None):
     filename = self.write_policy_file(data, format="json")
     if config:
         e = Config.empty(**config)
     else:
         e = Config.empty()
     return policy.load(e, filename)
def main():
    logging.basicConfig(level=logging.INFO)
    logging.getLogger('botocore').setLevel(logging.WARNING)

    parser = setup_parser()
    options = parser.parse_args()
    options.log_group = None
    options.cache = None

    factory = SessionFactory(
        options.region, options.profile, options.assume_role)

    session = factory()
    client = session.client('cloudwatch')

    load_resources()
    policies = load(options, options.config)

    if options.start and options.end:
        start = options.start
        end = options.end
    elif options.days:
        end = datetime.utcnow()
        start = end - timedelta(options.days)
    data = {}
    for p in policies:
        logging.info('Getting %s metrics', p)
        data[p.name] = p.get_metrics(start, end, options.period)
    print dumps(data, indent=2)
def main():
    logging.basicConfig(level=logging.INFO)
    logging.getLogger('botocore').setLevel(logging.WARNING)

    parser = setup_parser()
    options = parser.parse_args()
    options.log_group = None
    options.cache = None

    factory = SessionFactory(options.region, options.profile,
                             options.assume_role)

    session = factory()
    client = session.client('cloudwatch')

    load_resources()
    policies = load(options, options.config)

    if options.start and options.end:
        start = options.start
        end = options.end
    elif options.days:
        end = datetime.utcnow()
        start = end - timedelta(options.days)
    data = {}
    for p in policies:
        logging.info('Getting %s metrics', p)
        data[p.name] = p.get_metrics(start, end, options.period)
    print dumps(data, indent=2)
Beispiel #5
0
 def load_policy_set(self, data, config=None):
     filename = self.write_policy_file(data)
     if config:
         config['account_id'] = ACCOUNT_ID
         e = Config.empty(**config)
     else:
         e = Config.empty(account_id=ACCOUNT_ID)
     return policy.load(e, filename)
Beispiel #6
0
 def load_policy_set(self, data, config=None):
     t = tempfile.NamedTemporaryFile()
     t.write(yaml.dump(data, Dumper=yaml.SafeDumper))
     t.flush()
     self.addCleanup(t.close)
     if config:
         e = Config.empty(**config)
     else:
         e = Config.empty()
     return policy.load(e, t.name)
Beispiel #7
0
 def load_policy_set(self, data, config=None):
     t = tempfile.NamedTemporaryFile()
     t.write(yaml.dump(data, Dumper=yaml.SafeDumper))
     t.flush()
     self.addCleanup(t.close)
     if config:
         e = Config.empty(**config)
     else:
         e = Config.empty()
     return policy.load(e, t.name)
Beispiel #8
0
def dispatch_event(event, context):
    log.info("Processing event\n %s", format_event(event))

    error = event.get('detail', {}).get('errorCode')
    if error:
        log.debug("Skipping failed operation: %s" % error)
        return

    event['debug'] = True
    policies = load(Config.empty(), 'config.json', format='json')
    for p in policies:
        p.push(event, context)
Beispiel #9
0
def dispatch_event(event, context):
    log.info("Processing event\n %s", format_event(event))

    error = event.get('detail', {}).get('errorCode')
    if error:
        log.debug("Skipping failed operation: %s" % error)
        return

    event['debug'] = True
    policies = load(Config.empty(), 'config.json', format='json')
    for p in policies:
        p.push(event, context)
Beispiel #10
0
def main():
    parser = setup_parser()
    options = parser.parse_args()

    level = options.verbose and logging.DEBUG or logging.INFO
    logging.basicConfig(
        level=level, format="%(asctime)s: %(name)s:%(levelname)s %(message)s")
    logging.getLogger('botocore').setLevel(logging.ERROR)

    config = policy.load(options, options.config)
    try:
        options.command(options, config)
    except Exception:
        if not options.debug:
            raise
        import traceback
        import pdb
        import sys
        traceback.print_exc()
        pdb.post_mortem(sys.exc_info()[-1])
Beispiel #11
0
def main():
    parser = setup_parser()
    options = parser.parse_args()

    level = options.verbose and logging.DEBUG or logging.INFO
    logging.basicConfig(
        level=level,
        format="%(asctime)s: %(name)s:%(levelname)s %(message)s")
    logging.getLogger('botocore').setLevel(logging.ERROR)

    config = policy.load(options, options.config)
    try:
        options.command(options, config)
    except Exception:
        if not options.debug:
            raise
        import traceback
        import pdb
        import sys
        traceback.print_exc()
        pdb.post_mortem(sys.exc_info()[-1])
def test_doc_examples(provider_name, provider):

    policies, duplicate_names = get_doc_policies(provider.resources)

    with tempfile.NamedTemporaryFile(suffix='.json', delete=False) as fh:
        atexit.register(os.unlink, fh.name)

        fh.write(json.dumps({'policies': list(policies.values())}).encode('utf8'))
        fh.flush()
        collection = load(Config.empty(), fh.name)
        assert isinstance(collection, PolicyCollection)

    assert not duplicate_names

    for p in policies.values():
        # Note max name size here is 54 if it a lambda policy given
        # our default prefix custodian- to stay under 64 char limit on
        # lambda function names.  This applies to AWS and GCP, and
        # afaict Azure.
        if len(p['name']) >= 54 and 'mode' in p:
            raise ValueError(
                "doc policy exceeds name limit policy:%s" % (p['name']))
Beispiel #13
0
 def _load_policies(options):
     collection = policy.load(options, options.config)
     policies = collection.filter(options.policy_filter)
     return f(options, policies)
Beispiel #14
0
 def _load_policies(options):
     collection = policy.load(options, options.config)
     policies = collection.filter(options.policy_filter)
     return f(options, policies)
 def _load_policies(options):
     config = Config()
     config.from_cli(options)
     collection = policy.load(options, options.config)
     return f(config, collection)