def main(): parser = get_c7n_mailer_parser() args = parser.parse_args() mailer_config = get_and_validate_mailer_config(args) args_dict = vars(args) logger = get_logger(debug=args_dict.get('debug', False)) module_dir = path.dirname(path.abspath(__file__)) default_templates = [ path.abspath(path.join(module_dir, 'msg-templates')), path.abspath(path.join(module_dir, '..', 'msg-templates')), path.abspath('.') ] templates = args_dict.get('templates', None) if templates: default_templates.append( path.abspath(path.expanduser(path.expandvars(templates)))) mailer_config['templates_folders'] = default_templates provider = get_provider(mailer_config) if args_dict.get('update_lambda'): if args_dict.get('debug'): print( '\n** --debug is only supported with --run, not --update-lambda **\n' ) return if args_dict.get('max_num_processes'): print('\n** --max-num-processes is only supported ' 'with --run, not --update-lambda **\n') return if provider == Providers.Azure: azure_deploy.provision(mailer_config) elif provider == Providers.AWS: deploy.provision(mailer_config, functools.partial(session_factory, mailer_config)) if args_dict.get('run'): max_num_processes = args_dict.get('max_num_processes') # Select correct processor if provider == Providers.Azure: processor = MailerAzureQueueProcessor(mailer_config, logger) elif provider == Providers.AWS: aws_session = session_factory(mailer_config) processor = MailerSqsQueueProcessor(mailer_config, aws_session, logger) # Execute if max_num_processes: run_mailer_in_parallel(processor, max_num_processes) else: processor.run()
def test_get_providers(self): self.assertEqual(utils.get_provider({'queue_url': 'asq://'}), utils.Providers.Azure) self.assertEqual(utils.get_provider({'queue_url': 'sqs://'}), utils.Providers.AWS)