def __init__(self, execution_service: ExecutionService, config): self._execution_service = execution_service if config is None: self.notify_on_start = False self.notify_on_finish = False return self.notify_on_start = read_bool_from_config('notify_on_start', config, default=True) self.notify_on_finish = read_bool_from_config('notify_on_finish', config, default=True) destinations_config = read_list(config, 'destinations', []) if not destinations_config: LOGGER.warning( 'Execution callback destinations are missing! Please specify any' ) self.notify_on_start = False self.notify_on_finish = False return destinations = _init_destinations(destinations_config) self._communication_service = CommunicationsService(destinations) self.notification_fields = read_list( config, 'notification_fields', default=_DEFAULT_NOTIFICATION_FIELDS)
def _resolve_excluded_files(config, key, file_dir): raw_patterns = model_helper.read_list(config, key) if raw_patterns is None: patterns = [] else: patterns = [resolve_env_vars(e) for e in strip(raw_patterns)] return FileMatcher(patterns, file_dir)
def _reload(self): config = self._original_config self.param = config.get('param') self.no_value = read_boolean('no_value', config, False) self.description = config.get('description') self.required = read_boolean('required', config, False) self.min = config.get('min') self.max = config.get('max') self.secure = read_boolean('secure', config, False) self.separator = config.get('separator', ',') self.multiple_arguments = read_boolean('multiple_arguments', config, default=False) self.default = _resolve_default(config.get('default'), self._username, self._audit_name) self.file_dir = config.get('file_dir') self.file_type = config.get('file_type', '').strip().lower() self.file_extensions = strip(model_helper.read_list(config, 'file_extensions')) self.type = self._read_type(config) self.constant = read_boolean('constant', config, False) self._validate_config() values_provider = self._create_values_provider( config.get('values'), self.type, self.constant) self._values_provider = values_provider self._reload_values()
def from_json(conf_path): if os.path.exists(conf_path): file_content = file_utils.read_file(conf_path) else: file_content = "{}" config = ServerConfig() json_object = json.loads(file_content) address = "0.0.0.0" port = 5000 ssl = json_object.get("ssl") if ssl is not None: key_path = model_helper.read_obligatory(ssl, 'key_path', ' for ssl') cert_path = model_helper.read_obligatory(ssl, 'cert_path', ' for ssl') config.ssl = True config.ssl_key_path = key_path config.ssl_cert_path = cert_path port = 5443 if json_object.get("address"): address = json_object.get("address") config.address = address if json_object.get("port"): port = json_object.get("port") config.port = port if json_object.get('title'): config.title = json_object.get('title') auth_config = json_object.get('auth') if auth_config: config.authenticator = create_authenticator(auth_config) allowed_users = auth_config.get('allowed_users') auth_type = config.authenticator.auth_type if auth_type == 'google_oauth' and allowed_users is None: raise Exception('auth.allowed_users field is mandatory for ' + auth_type) def_trusted_ips = [] def_admins = [] else: allowed_users = '*' def_trusted_ips = ['127.0.0.1', '::1'] def_admins = def_trusted_ips config.trusted_ips = strip(read_list(json_object, 'trusted_ips', default=def_trusted_ips)) admin_users = _parse_admin_users(json_object, default_admins=def_admins) config.authorizer = _create_authorizer(allowed_users, admin_users) config.alerts_config = parse_alerts_config(json_object) config.logging_config = parse_logging_config(json_object) return config
def _parse_admin_users(json_object, default_admins=None): admins = strip(read_list(json_object, 'admin_users', default=default_admins)) if '*' in admins: LOGGER.warning('Any user is allowed to access admin page, be careful!') return [ANY_USER] return admins
def _parse_code_editor_users(json_object, admin_users): full_code_editor_users = strip( read_list(json_object, 'code_editors', default=admin_users)) if (isinstance(full_code_editor_users, list) and '*' in full_code_editor_users) \ or full_code_editor_users == '*': return [ANY_USER] return full_code_editor_users
def __init__(self, alerts_config): if alerts_config: destinations_config = read_list(alerts_config, 'destinations', []) else: destinations_config = [] destinations = _init_destinations(destinations_config) self._communication_service = CommunicationsService(destinations)
def _parse_history_users(json_object): full_history_users = strip( read_list(json_object, 'full_history', default=[])) if (isinstance(full_history_users, list) and '*' in full_history_users) \ or full_history_users == '*': return [ANY_USER] return full_history_users
def _parse_admin_users(json_object, default_admins=None): admins = strip( read_list(json_object, 'admin_users', default=default_admins)) if '*' in admins: LOGGER.warning('Any user is allowed to access admin page, be careful!') return [ANY_USER] return admins
def read_weekdays(incoming_schedule_config): weekdays = model_helper.read_list(incoming_schedule_config, 'weekdays') if not weekdays: raise InvalidScheduleException('At least one weekday should be specified') weekdays = [day.lower().strip() for day in weekdays] for day in weekdays: if day not in ALLOWED_WEEKDAYS: raise InvalidScheduleException('Unknown weekday: ' + day) return sorted(weekdays, key=lambda x: ALLOWED_WEEKDAYS.index(x))
def __init__(self, execution_service: ExecutionService, config): self._execution_service = execution_service if config is None: self.notify_on_start = False self.notify_on_finish = False return self.notify_on_start = read_bool_from_config('notify_on_start', config, default=True) self.notify_on_finish = read_bool_from_config('notify_on_finish', config, default=True) destinations_config = read_list(config, 'destinations', []) if not destinations_config: LOGGER.warning('Execution callback destinations are missing! Please specify any') self.notify_on_start = False self.notify_on_finish = False return destinations = _init_destinations(destinations_config) self._communication_service = CommunicationsService(destinations) self.notification_fields = read_list(config, 'notification_fields', default=_DEFAULT_NOTIFICATION_FIELDS)
def _parse_admin_users(json_object, default_admins=None): return strip(read_list(json_object, 'admin_users', default=default_admins))
def _resolve_file_extensions(config, key): result = model_helper.read_list(config, key) if result is None: return [] return [normalize_extension(e) for e in strip(result)]
def test_simple_list(self): values_dict = {'list_key': [1, 2, 3]} list_value = read_list(values_dict, 'list_key') self.assertEqual(list_value, [1, 2, 3])
def test_single_value(self): values_dict = {'list_key': 'hello'} list_value = read_list(values_dict, 'list_key') self.assertEqual(list_value, ['hello'])
def test_default_value_when_specified(self): values_dict = {'another_key': 'hello'} list_value = read_list(values_dict, 'list_key', [True, False]) self.assertEqual(list_value, [True, False])
def from_json(conf_path, temp_folder): if os.path.exists(conf_path): file_content = file_utils.read_file(conf_path) else: file_content = "{}" config = ServerConfig() json_object = json.loads(file_content) address = "0.0.0.0" port = 5000 ssl = json_object.get("ssl") if ssl is not None: key_path = model_helper.read_obligatory(ssl, 'key_path', ' for ssl') cert_path = model_helper.read_obligatory(ssl, 'cert_path', ' for ssl') config.ssl = True config.ssl_key_path = key_path config.ssl_cert_path = cert_path port = 5443 if json_object.get("address"): address = json_object.get("address") config.address = address if json_object.get("port"): port = json_object.get("port") config.port = port if json_object.get('title'): config.title = json_object.get('title') access_config = json_object.get('access') if access_config: allowed_users = access_config.get('allowed_users') user_groups = model_helper.read_dict(access_config, 'groups') else: allowed_users = None user_groups = {} auth_config = json_object.get('auth') if auth_config: config.authenticator = create_authenticator(auth_config, temp_folder) auth_type = config.authenticator.auth_type if auth_type == 'google_oauth' and allowed_users is None: raise Exception('auth.allowed_users field is mandatory for ' + auth_type) def_trusted_ips = [] def_admins = [] else: def_trusted_ips = ['127.0.0.1', '::1'] def_admins = def_trusted_ips if access_config: config.trusted_ips = strip( read_list(access_config, 'trusted_ips', default=def_trusted_ips)) admin_users = _parse_admin_users(access_config, default_admins=def_admins) else: config.trusted_ips = def_trusted_ips admin_users = def_admins config.allowed_users = _prepare_allowed_users(allowed_users, admin_users, user_groups) config.alerts_config = parse_alerts_config(json_object) config.logging_config = parse_logging_config(json_object) config.user_groups = user_groups config.admin_users = admin_users config.max_request_size_mb = read_int_from_config('max_request_size', json_object, default=10) return config
def from_json(conf_path, temp_folder): if os.path.exists(conf_path): file_content = file_utils.read_file(conf_path) else: file_content = "{}" config = ServerConfig() json_object = json.loads(file_content) address = "0.0.0.0" port = 5000 ssl = json_object.get("ssl") if ssl is not None: key_path = model_helper.read_obligatory(ssl, 'key_path', ' for ssl') cert_path = model_helper.read_obligatory(ssl, 'cert_path', ' for ssl') config.ssl = True config.ssl_key_path = key_path config.ssl_cert_path = cert_path port = 5443 if json_object.get("address"): address = json_object.get("address") config.address = address if json_object.get("port"): port = json_object.get("port") config.port = port if json_object.get('title'): config.title = json_object.get('title') config.enable_script_titles = read_bool_from_config('enable_script_titles', json_object, default=True) access_config = json_object.get('access') if access_config: allowed_users = access_config.get('allowed_users') user_groups = model_helper.read_dict(access_config, 'groups') user_header_name = access_config.get('user_header_name') else: allowed_users = None user_groups = {} user_header_name = None auth_config = json_object.get('auth') if auth_config: config.authenticator = create_authenticator(auth_config, temp_folder) auth_type = config.authenticator.auth_type if auth_type == 'google_oauth' and allowed_users is None: raise Exception('access.allowed_users field is mandatory for ' + auth_type) def_trusted_ips = [] def_admins = [] else: def_trusted_ips = ['127.0.0.1', '::1'] def_admins = def_trusted_ips if access_config: trusted_ips = strip( read_list(access_config, 'trusted_ips', default=def_trusted_ips)) admin_users = _parse_admin_users(access_config, default_admins=def_admins) full_history_users = _parse_history_users(access_config) code_editor_users = _parse_code_editor_users(access_config, admin_users) else: trusted_ips = def_trusted_ips admin_users = def_admins full_history_users = [] code_editor_users = def_admins security = model_helper.read_dict(json_object, 'security') config.allowed_users = _prepare_allowed_users(allowed_users, admin_users, user_groups) config.alerts_config = json_object.get('alerts') config.callbacks_config = json_object.get('callbacks') config.logging_config = parse_logging_config(json_object) config.user_groups = user_groups config.admin_users = admin_users config.full_history_users = full_history_users config.code_editor_users = code_editor_users config.user_header_name = user_header_name config.ip_validator = TrustedIpValidator(trusted_ips) config.max_request_size_mb = read_int_from_config('max_request_size', json_object, default=10) config.secret_storage_file = json_object.get( 'secret_storage_file', os.path.join(temp_folder, 'secret.dat')) config.xsrf_protection = _parse_xsrf_protection(security) return config
def from_json(conf_path, temp_folder): if os.path.exists(conf_path): file_content = file_utils.read_file(conf_path) else: file_content = "{}" config = ServerConfig() json_object = json.loads(file_content) address = "0.0.0.0" port = 5000 ssl = json_object.get("ssl") if ssl is not None: key_path = model_helper.read_obligatory(ssl, 'key_path', ' for ssl') cert_path = model_helper.read_obligatory(ssl, 'cert_path', ' for ssl') config.ssl = True config.ssl_key_path = key_path config.ssl_cert_path = cert_path port = 5443 if json_object.get("address"): address = json_object.get("address") config.address = address if json_object.get("port"): port = json_object.get("port") config.port = port if json_object.get('title'): config.title = json_object.get('title') access_config = json_object.get('access') if access_config: allowed_users = access_config.get('allowed_users') user_groups = model_helper.read_dict(access_config, 'groups') else: allowed_users = None user_groups = {} auth_config = json_object.get('auth') if auth_config: config.authenticator = create_authenticator(auth_config, temp_folder) auth_type = config.authenticator.auth_type if auth_type == 'google_oauth' and allowed_users is None: raise Exception('auth.allowed_users field is mandatory for ' + auth_type) def_trusted_ips = [] def_admins = [] else: def_trusted_ips = ['127.0.0.1', '::1'] def_admins = def_trusted_ips if access_config: config.trusted_ips = strip(read_list(access_config, 'trusted_ips', default=def_trusted_ips)) admin_users = _parse_admin_users(access_config, default_admins=def_admins) else: config.trusted_ips = def_trusted_ips admin_users = def_admins config.allowed_users = _prepare_allowed_users(allowed_users, admin_users, user_groups) config.alerts_config = json_object.get('alerts') config.callbacks_config = json_object.get('callbacks') config.logging_config = parse_logging_config(json_object) config.user_groups = user_groups config.admin_users = admin_users config.max_request_size_mb = read_int_from_config('max_request_size', json_object, default=10) return config
def test_empty_single_value(self): values_dict = {'list_key': ''} list_value = read_list(values_dict, 'list_key') self.assertEqual(list_value, [''])
def _parse_admin_users(json_object): default_admins = ['127.0.0.1'] admin_users = read_list(json_object, 'admin_users', default_admins) return strip(admin_users)
def test_default_value_when_missing(self): values_dict = {'another_key': 'hello'} list_value = read_list(values_dict, 'list_key') self.assertEqual(list_value, [])