class AuthConfigSchema(BaseSchema): host = fields.String(validate=Length(min=1, max=1024), missing='localhost') port = fields.Integer(validate=Range(min=1, max=65535), missing=9497) key_file = fields.String(validate=Length(min=1, max=1024), allow_none=True) username = fields.String(validate=Length(min=1, max=512), allow_none=True) password = fields.String(validate=Length(min=1, max=512), allow_none=True) verify_certificate = VerifyCertificateField(missing=True) timeout = fields.Float(validate=Range(min=0, max=3660)) version = fields.String(validate=Length(min=1, max=16), missing='0.1') @validates_schema def validate_auth_info(self, data): key_file = data.get('key_file') username = data.get('username') if key_file and username: raise exceptions.ValidationError( 'a "key_file" or a "username" and "password" must be specified', ) if key_file or username: return raise exceptions.ValidationError( 'a "key_file" or a "username" and "password" must be specified', )
class ConfdConfigSchema(BaseSchema): host = fields.String(validate=Length(min=1, max=1024), missing='localhost') port = fields.Integer(validate=Range(min=1, max=65535), missing=9486) verify_certificate = VerifyCertificateField(missing=True) timeout = fields.Float(validate=Range(min=0, max=3660)) https = fields.Boolean(missing=True) version = fields.String(validate=Length(min=1, max=16), missing='1.1')
class MarketListRequestSchema(Schema): direction = fields.String(validate=OneOf(['asc', 'desc']), missing='asc') order = fields.String(validate=Length(min=1), missing='name') limit = fields.Integer(validate=Range(min=0), missing=None) offset = fields.Integer(validate=Range(min=0), missing=0) search = fields.String(missing=None) installed = fields.Boolean()
class BaseAuthConfigSchema(BaseSchema): host = fields.String(validate=Length(min=1, max=1024), missing='localhost') port = fields.Integer(validate=Range(min=1, max=65535), missing=443) https = fields.Boolean(missing=True) verify_certificate = VerifyCertificateField(missing=True) prefix = fields.String(allow_none=True, missing='/api/auth') version = fields.String(validate=Length(min=1, max=16), missing='0.1') timeout = fields.Float(validate=Range(min=0, max=3660))
class SourceSchema(BaseSourceSchema): lookup_url = fields.URL(required=True) list_url = fields.URL(allownone=True, missing=None) verify_certificate = VerifyCertificateField(missing=True) delimiter = fields.String(Length(min=1, max=1), missing=',') timeout = fields.Float(Range(min=0), missing=10.0) unique_column = fields.String(Length(min=1, max=128), allownone=True, missing=None)
class LDAPConfig(BaseSchema): tenant_uuid = fields.String(dump_only=True, default=None) host = fields.String(validate=Length(max=512), required=True, default=None) port = fields.Integer(required=True, default=None) protocol_version = fields.Integer(validate=Range(min=2, max=3), missing=3, default=None) protocol_security = fields.String( validate=OneOf(['ldaps', 'tls']), allow_none=True, default=None, ) bind_dn = fields.String(validate=Length(max=256), allow_none=True, default=None) user_base_dn = fields.String(validate=Length(max=256), required=True, default=None) user_login_attribute = fields.String(validate=Length(max=64), required=True, default=None) user_email_attribute = fields.String(validate=Length(max=64), required=True, default=None) search_filters = fields.String(allow_none=True, default=None)
class SourceSchema(BaseSourceSchema): ldap_uri = fields.String(validate=Length(min=1, max=256), required=True) ldap_base_dn = fields.String(validate=Length(min=1, max=1024), required=True) ldap_username = fields.String(validate=Length(min=1), missing=None) ldap_password = fields.String(validate=Length(min=1), missing=None) ldap_custom_filter = fields.String(validate=Length(min=1, max=1024), missing=None) ldap_network_timeout = fields.Float(validate=Range(min=0), default=0.3) ldap_timeout = fields.Float(validate=Range(min=0), default=1.0) unique_column = fields.String(validate=Length(min=1, max=128), allow_none=True, missing=None) unique_column_format = fields.String(validate=OneOf( ['string', 'binary_uuid']), missing='string')
class CDRListRequestSchema(CDRListingBase): direction = fields.String(validate=OneOf(['asc', 'desc']), missing='desc') order = fields.String( validate=OneOf(set(CDRSchema().fields) - {'end', 'tags', 'recordings'}), missing='start', ) limit = fields.Integer(validate=Range(min=0), missing=1000) offset = fields.Integer(validate=Range(min=0), missing=None) distinct = fields.String(validate=OneOf(['peer_exten']), missing=None) recorded = fields.Boolean(missing=None) format = fields.String(validate=OneOf(['csv', 'json']), missing=None) @post_load def map_order_field(self, in_data, **kwargs): mapped_order = CDRSchema().fields[in_data['order']].attribute if mapped_order: in_data['order'] = mapped_order return in_data
class TokenRequestSchema(BaseSchema): backend = fields.String(missing='wazo_user') expiration = fields.Integer(validate=Range(min=1)) access_type = fields.String(validate=OneOf(['online', 'offline'])) client_id = fields.String(validate=Length(min=1, max=1024)) refresh_token = fields.String() tenant_id = fields.String() domain_name = fields.String() @validates_schema def check_access_type_usage(self, data, **kwargs): access_type = data.get('access_type') if access_type != 'offline': return refresh_token = data.get('refresh_token') if refresh_token: raise ValidationError( 'cannot use the "access_type" "offline" with a refresh token' ) client_id = data.get('client_id') if not client_id: raise ValidationError( '"client_id" must be specified when using "access_type" is "offline"' ) @validates_schema def check_backend_type_for_tenant_id_and_domain_name(self, data, **kwargs): backend = data.get('backend') if not backend == 'ldap_user': return tenant_id = data.get('tenant_id') domain_name = data.get('domain_name') if tenant_id and domain_name: raise ValidationError( '"tenant_id" and "domain_name" must be mutually exclusive' ) if not tenant_id and not domain_name: raise ValidationError( '"tenant_id" or "domain_name" must be specified when using the "ldap_user" backend' ) @validates_schema def check_refresh_token_usage(self, data, **kwargs): refresh_token = data.get('refresh_token') if not refresh_token: return client_id = data.get('client_id') if not client_id: raise ValidationError( '"client_id" must be specified when using a "refresh_token"' )
class RetentionSchema(Schema): tenant_uuid = fields.UUID(dump_only=True) cdr_days = fields.Integer(validate=Range(min=0), missing=None) export_days = fields.Integer(validate=Range(min=0), missing=None) recording_days = fields.Integer(validate=Range(min=0), missing=None) default_cdr_days = fields.Integer(dump_only=True) default_export_days = fields.Integer(dump_only=True) default_recording_days = fields.Integer(dump_only=True) @validates_schema def validate_days(self, data, **kwargs): cdr_days = data.get('cdr_days') recording_days = data.get('recording_days') if cdr_days is None or recording_days is None: return if recording_days > cdr_days: raise ValidationError( '"recording_days" must be higher or equal than "cdr_days"', field_name='recording_days', )
class QueueStatisticsQoSRequestSchema(_StatisticsListRequestSchema): interval = fields.String(validate=OneOf(['hour', 'day', 'month'])) qos_thresholds = fields.List(fields.Integer(validate=Range(min=0)), missing=[]) @pre_load def convert_qos_thresholds_to_list(self, data, **kwargs): result = data.copy() if not isinstance(result, dict): result = result.to_dict() if data.get('qos_thresholds'): result['qos_thresholds'] = list( set(data['qos_thresholds'].split(','))) return result @post_load def sort_qos_thresholds(self, data, **kwargs): result = data.copy() if data.get('qos_thresholds'): result['qos_thresholds'] = sorted(data['qos_thresholds']) return result
class CDRListingBase(Schema): from_ = fields.DateTime(data_key='from', attribute='start', missing=None) until = fields.DateTime(attribute='end', missing=None) search = fields.String(missing=None) call_direction = fields.String( validate=OneOf(['internal', 'inbound', 'outbound']), missing=None ) number = fields.String(validate=Regexp(NUMBER_REGEX), missing=None) tags = fields.List(fields.String(), missing=[]) user_uuid = fields.List(fields.String(), missing=[], attribute='user_uuids') from_id = fields.Integer(validate=Range(min=0), attribute='start_id', missing=None) recurse = fields.Boolean(missing=False) @pre_load def convert_tags_and_user_uuid_to_list(self, data, **kwargs): result = data.to_dict() if data.get('tags'): result['tags'] = data['tags'].split(',') if data.get('user_uuid'): result['user_uuid'] = data['user_uuid'].split(',') return result
class PluginMetadataSchema(Schema): version_fields = ['version', 'max_wazo_version', 'min_wazo_version'] current_version = None name = fields.String(validate=Regexp(_PLUGIN_NAME_REGEXP), required=True) namespace = fields.String(validate=Regexp(_PLUGIN_NAMESPACE_REGEXP), required=True) version = fields.String(required=True) plugin_format_version = fields.Integer( validate=Range(min=0, max=_MAX_PLUGIN_FORMAT_VERSION), missing=_DEFAULT_PLUGIN_FORMAT_VERSION) max_wazo_version = fields.String() min_wazo_version = fields.String() depends = fields.Nested(MarketInstallOptionsSchema, many=True, unknown=EXCLUDE) @pre_load def ensure_string_versions(self, data): for field in self.version_fields: if field not in data: continue value = data[field] if not isinstance(value, (float, int)): continue data[field] = str(value) return data def on_bind_field(self, field_name, field_obj): if field_name == 'max_wazo_version': self._set_max_wazo_version_parameters(field_obj) elif field_name == 'min_wazo_version': self._set_min_wazo_version_parameters(field_obj) def _set_max_wazo_version_parameters(self, field_obj): field_obj.validators = [Range(min=self.current_version)] def _set_min_wazo_version_parameters(self, field_obj): field_obj.validators = [Range(max=self.current_version)]
def _set_min_wazo_version_parameters(self, field_obj): field_obj.validators = [Range(max=self.current_version)]
class QueueStatisticsListRequestSchema(_StatisticsListRequestSchema): qos_threshold = fields.Integer(validate=Range(min=0))