def main(input): logging.info("Running Azure Cloud Custodian Policy") context = { 'config_file': join(dirname(__file__), 'config.json'), 'auth_file': join(dirname(__file__), 'auth.json') } event = None if type(input) is HttpRequest: event = input.get_json() logging.info(event) # handshake with event grid subscription creation if 'data' in event[0] and 'validationCode' in event[0]['data']: code = event[0]['data']['validationCode'] response = {"validationResponse": code} return func.HttpResponse(body=json.dumps(response, indent=2), status_code=200) handler.run(event, context) if type(input) is HttpRequest: return func.HttpResponse("OK")
def main(input): logging.info("Running Azure Cloud Custodian Policy") context = { 'config_file': join(dirname(__file__), 'config.json'), 'auth_file': join(dirname(__file__), 'auth.json') } handler.run(None, context)
def main(input): logging.info("Running Azure Cloud Custodian Policy") context = { 'config_file': join(dirname(__file__), 'config.json'), 'auth_file': join(dirname(__file__), 'auth.json') } events = None if type(input) is QueueMessage: events = [input.get_json()] handler.run(events, context)
def main(input): logging.info("Running Azure Cloud Custodian Policy") context = { 'config_file': join(dirname(__file__), 'config.json'), 'auth_file': join(dirname(__file__), 'auth.json') } if type(input) is HttpRequest: context['event'] = input.get_json() handler.run(None, context) if type(input) is HttpRequest: return func.HttpResponse("OK")
def main(input): logging.info("Running Azure Cloud Custodian Policy") context = { 'config_file': join(dirname(__file__), 'config.json'), 'auth_file': join(dirname(__file__), 'auth.json') } if type(input) is HttpRequest: context['event'] = input.get_json() handler.run(None, context) if type(input) is HttpRequest: return func.HttpResponse("OK")
def main(input): logging.info("Running Azure Cloud Custodian Policy") context = { 'config_file': join(dirname(__file__), 'config.json'), 'auth_file': join(dirname(__file__), 'auth.json') } event = None if type(input) is QueueMessage: if input.dequeue_count > max_dequeue_count: return event = input.get_json() handler.run(event, context)
def main(input): logging.info("Running Azure Cloud Custodian Policy") context = { 'config_file': join(dirname(__file__), 'config.json'), 'auth_file': join(dirname(__file__), 'auth.json') } event = None if type(input) is QueueMessage: if input.dequeue_count > max_dequeue_count: return event = input.get_json() handler.run(event, context)
def test_run_empty_policy(self): context = { 'config_file': join(dirname(__file__), 'data', 'test_config_empty.json'), 'auth_file': join(dirname(__file__), 'data', 'test_auth_file.json') } self.assertFalse(run(None, context))
def test_run_empty_policy(self): context = { 'config_file': join(dirname(__file__), 'files', 'test_config_empty.json'), 'auth_file': join(dirname(__file__), 'files', 'test_auth_file.json') } self.assertFalse(run(None, context))
def main(input): logging.info("Running Azure Cloud Custodian Policy") context = { 'config_file': join(function_directory, 'config.json'), 'auth_file': join(function_directory, 'auth.json') } event = None subscription_id = None if isinstance(input, QueueMessage): if input.dequeue_count > max_dequeue_count: return event = input.get_json() subscription_id = ResourceIdParser.get_subscription_id(event['subject']) handler.run(event, context, subscription_id)
def main(input): logging.info("Running Azure Cloud Custodian Policy") context = { 'config_file': join(dirname(__file__), 'config.json'), 'auth_file': join(dirname(__file__), 'auth.json') } event = None subscription_id = None if type(input) is QueueMessage: if input.dequeue_count > max_dequeue_count: return event = input.get_json() subscription_id = ResourceIdParser.get_subscription_id(event['subject']) handler.run(event, context, subscription_id)
def test_run(self, push_mock, _1, initialize_mock): context = { 'config_file': join(dirname(__file__), 'data', 'test_config.json'), 'auth_file': join(dirname(__file__), 'data', 'test_auth_file.json') } self.assertTrue(run(None, context, CUSTOM_SUBSCRIPTION_ID)) push_mock.assert_called_once() self.assertEqual(push_mock.call_args_list[0], call(None, context)) initialize_mock.assert_called_once() self.assertEqual(initialize_mock.call_args_list[0][0][0]['account_id'], CUSTOM_SUBSCRIPTION_ID) self.assertEqual(initialize_mock.call_args_list[0][0][0]['authorization_file'], context['auth_file']) self.assertEqual(initialize_mock.call_args_list[0][0][0]['test_option'], "test_value")
def test_run(self, push_mock, _1, initialize_mock): context = { 'config_file': join(dirname(__file__), 'files', 'test_config.json'), 'auth_file': join(dirname(__file__), 'files', 'test_auth_file.json') } self.assertTrue(run(None, context, CUSTOM_SUBSCRIPTION_ID)) push_mock.assert_called_once() self.assertEqual(push_mock.call_args_list[0], call(None, context)) initialize_mock.assert_called_once() self.assertEqual(initialize_mock.call_args_list[0][0][0]['account_id'], CUSTOM_SUBSCRIPTION_ID) self.assertEqual(initialize_mock.call_args_list[0][0][0]['authorization_file'], context['auth_file']) self.assertEqual(initialize_mock.call_args_list[0][0][0]['test_option'], "test_value")