def test_provision_uai_auth(self, mock_local_session, mock_session, mock_func_utils, mock_build_pkg): mock_session.get_subscription_id.return_value = 'mock-id' mock_local_session.return_value = mock_session mock_func_utils.get_function_name.return_value = 'mock-func-name' mock_build_pkg.return_value = MagicMock() user_assigned = { "identity": { "type": "UserAssigned", "id": "mock-id", "client_id": "mock-client-id" } } with patch.dict(MAILER_CONFIG_AZURE, {"function_properties": user_assigned}): deploy.provision(MAILER_CONFIG_AZURE) mock_func_utils.FunctionAppInfrastructureParameters.assert_called_with( app_insights=ANY, service_plan=ANY, storage_account=ANY, function_app={ 'resource_group_name': 'cloud-custodian', 'identity': { 'type': 'UserAssigned', 'id': 'mock-id', 'client_id': 'mock-client-id' }, 'name': 'mock-func-name' }) mock_func_utils.deploy_function_app.assert_called_once() mock_func_utils.publish_functions_package.assert_called_once()
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_provision_embedded_auth(self, mock_local_session, mock_session, mock_func_utils, mock_build_pkg): mock_session.get_subscription_id.return_value = 'mock-id' mock_local_session.return_value = mock_session mock_func_utils.get_function_name.return_value = 'mock-func-name' mock_build_pkg.return_value = MagicMock() deploy.provision(MAILER_CONFIG_AZURE) mock_func_utils.FunctionAppInfrastructureParameters.assert_called_with( app_insights=ANY, service_plan=ANY, storage_account=ANY, function_app={ 'resource_group_name': 'cloud-custodian', 'identity': { 'type': 'Embedded' }, 'name': 'mock-func-name' }) mock_func_utils.deploy_function_app.assert_called_once() mock_func_utils.publish_functions_package.assert_called_once()