cook: check disabled service in recipes (#72335)

This commit is contained in:
Benjamin Dauvergne 2022-12-15 12:55:17 +01:00
parent bc8e7a3867
commit 82b7e01caf
2 changed files with 17 additions and 1 deletions

View File

@ -304,8 +304,16 @@ class Command(BaseCommand):
connection.set_tenant(current_tenant)
def check_action(self, action, action_args):
if not hasattr(self, action.replace('-', '_')):
method_name = action.replace('-', '_')
if not hasattr(self, method_name):
raise CommandError('Error: Unknown action %s' % action)
if method_name.startswith('create_'):
service_class_name = method_name.split('create_', 1)[1]
for service_class in AVAILABLE_SERVICES:
if service_class.__name__.lower() == service_class_name:
if not service_class.is_enabled():
raise CommandError(f'{action}: service class "{service_class.__name__}" is disabled')
break
if 'url' in action_args.keys():
try:
validate_service_url(action_args['url'])

View File

@ -99,6 +99,14 @@ def test_check_action_invalid_certificat(command, monkeypatch):
assert 'no valid certificate for https://test.org/' in str(e_info.value)
def test_check_action_disabled_service(command, cook):
recipe = {'steps': [{'create-bijoe': {'url': 'https://entrouvert.org/', 'title': 'Statistiques'}}]}
with pytest.raises(CommandError, match='service class "BiJoe" is disabled'):
cook(recipe)
command.create_bijoe = Mock()
cook(recipe, permissive=True)
def test_handle(command):
kwargs = {'verbosity': 0, 'timeout': 'timeout value', 'permissive': 'permissive value'}
command.run_cook = Mock()