Add config validation for action log archiving

This commit is contained in:
Joseph Schorr 2017-07-10 13:09:33 +03:00
parent fa21e42ffb
commit 176c26e3f7
3 changed files with 75 additions and 0 deletions

View file

@ -21,6 +21,7 @@ from util.config.validators.validate_github import GitHubLoginValidator, GitHubT
from util.config.validators.validate_oidc import OIDCLoginValidator
from util.config.validators.validate_timemachine import TimeMachineValidator
from util.config.validators.validate_access import AccessSettingsValidator
from util.config.validators.validate_actionlog_achiving import ActionLogAchivingValidator
logger = logging.getLogger(__name__)
@ -57,6 +58,7 @@ VALIDATORS = {
OIDCLoginValidator.name: OIDCLoginValidator.validate,
TimeMachineValidator.name: TimeMachineValidator.validate,
AccessSettingsValidator.name: AccessSettingsValidator.validate,
ActionLogAchivingValidator.name: ActionLogAchivingValidator.validate,
}
def validate_service_for_config(service, config, password=None):

View file

@ -0,0 +1,51 @@
import pytest
from util.config.validators import ConfigValidationException
from util.config.validators.validate_actionlog_achiving import ActionLogAchivingValidator
from test.fixtures import *
@pytest.mark.parametrize('unvalidated_config', [
({}),
({'ACTION_LOG_ARCHIVE_PATH': 'foo'}),
({'ACTION_LOG_ARCHIVE_LOCATION': ''}),
])
def test_skip_validate_actionlog(unvalidated_config, app):
validator = ActionLogAchivingValidator()
validator.validate(unvalidated_config, None, None)
@pytest.mark.parametrize('config, expected_error', [
({'FEATURE_ACTION_LOG_ROTATION': True}, 'Missing action log archive path'),
({'FEATURE_ACTION_LOG_ROTATION': True,
'ACTION_LOG_ARCHIVE_PATH': ''}, 'Missing action log archive path'),
({'FEATURE_ACTION_LOG_ROTATION': True,
'ACTION_LOG_ARCHIVE_PATH': 'foo'}, 'Missing action log archive storage location'),
({'FEATURE_ACTION_LOG_ROTATION': True,
'ACTION_LOG_ARCHIVE_PATH': 'foo',
'ACTION_LOG_ARCHIVE_LOCATION': ''}, 'Missing action log archive storage location'),
({'FEATURE_ACTION_LOG_ROTATION': True,
'ACTION_LOG_ARCHIVE_PATH': 'foo',
'ACTION_LOG_ARCHIVE_LOCATION': 'invalid'},
'Action log archive storage location `invalid` not found in storage config'),
])
def test_invalid_config(config, expected_error, app):
validator = ActionLogAchivingValidator()
with pytest.raises(ConfigValidationException) as ipe:
validator.validate(config, None, None)
assert ipe.value.message == expected_error
def test_valid_config(app):
config = {
'FEATURE_ACTION_LOG_ROTATION': True,
'ACTION_LOG_ARCHIVE_PATH': 'somepath',
'ACTION_LOG_ARCHIVE_LOCATION': 'somelocation',
'DISTRIBUTED_STORAGE_CONFIG': {
'somelocation': {},
},
}
validator = ActionLogAchivingValidator()
validator.validate(config, None, None)

View file

@ -0,0 +1,22 @@
from util.config.validators import BaseValidator, ConfigValidationException
class ActionLogAchivingValidator(BaseValidator):
name = "actionlogachiving"
@classmethod
def validate(cls, config, user, user_password):
""" Validates the action log archiving configuration. """
if not config.get('FEATURE_ACTION_LOG_ROTATION', False):
return
if not config.get('ACTION_LOG_ARCHIVE_PATH'):
raise ConfigValidationException('Missing action log archive path')
if not config.get('ACTION_LOG_ARCHIVE_LOCATION'):
raise ConfigValidationException('Missing action log archive storage location')
location = config['ACTION_LOG_ARCHIVE_LOCATION']
storage_config = config.get('DISTRIBUTED_STORAGE_CONFIG') or {}
if location not in storage_config:
msg = 'Action log archive storage location `%s` not found in storage config' % location
raise ConfigValidationException(msg)