class SubscriptionLogSchema(Schema): uuid = fields.UUID(dump_only=True) status = fields.String() started_at = fields.DateTime() ended_at = fields.DateTime() attempts = fields.Integer() max_attempts = fields.Integer() event = fields.Dict() detail = fields.Dict()
class SourceSchema(BaseSourceSchema): auth = fields.Dict(keys=fields.String(validate=Length(min=1, max=64)), values=fields.String(validate=Length(min=1, max=64))) endpoint = fields.String( missing='https://graph.microsoft.com/v1.0/me/contacts', validate=Length(min=1, max=255), )
class BaseSourceSchema(BaseSchema): uuid = fields.UUID(dump_only=True) tenant_uuid = fields.UUID(dump_only=True) name = fields.String(validate=Length(min=1, max=512), required=True) first_matched_columns = fields.List( fields.String(validate=Length(min=1, max=128)), missing=[]) searched_columns = fields.List( fields.String(validate=Length(min=1, max=128)), missing=[]) format_columns = fields.Dict(validate=validate_string_dict, missing={})
class UserSubscriptionSchema(Schema): uuid = fields.UUID(dump_only=True) name = fields.String(validate=Length(max=128), required=True) service = fields.String(validate=Length(max=128), allow_none=False, required=True) events = fields.List(fields.String(validate=Length(max=128), allow_none=False), allow_none=False, required=True) config = ConfigField(allow_none=False, required=True) metadata_ = fields.Dict(load_from='metadata')
class SubscriptionSchema(Schema): uuid = fields.UUID(dump_only=True) name = fields.String(validate=Length(max=128), required=True) service = fields.String(validate=Length(max=128), allow_none=False, required=True) events = fields.List(fields.String(validate=Length(max=128), allow_none=False), allow_none=False, required=True) events_user_uuid = fields.String(validate=Length(equal=36), missing=None) events_wazo_uuid = fields.String(validate=Length(equal=36), missing=None) config = ConfigField(allow_none=False, required=True) owner_user_uuid = fields.String(validate=Length(equal=36), missing=None) metadata = fields.Dict()
class SubscriptionListParamsSchema(Schema): search_metadata = fields.Dict() @pre_load def aggregate_search_metadata(self, data): metadata = {} for search in data.getlist('search_metadata'): try: key, value = search.split(':', 1) except ValueError: continue metadata[key] = value result = dict(data) result['search_metadata'] = metadata return result
class UserSubscriptionSchema(Schema): class Meta: unknown = EXCLUDE uuid = fields.UUID(dump_only=True) name = fields.String(validate=Length(max=128), required=True) service = fields.String(validate=Length(max=128), allow_none=False, required=True) events = fields.List( fields.String(validate=Length(max=128), allow_none=False), allow_none=False, required=True, ) config = ConfigField(allow_none=False, required=True) metadata_ = fields.Dict(data_key='metadata')
class SubscriptionListParamsSchema(Schema): search_metadata = fields.Dict() recurse = fields.Boolean(missing=False) @pre_load def aggregate_search_metadata(self, data): metadata = {} for search in data.getlist('search_metadata'): try: key, value = search.split(':', 1) except ValueError: continue metadata[key] = value result = {} result['search_metadata'] = metadata if 'recurse' in data: result['recurse'] = data['recurse'] return result
class SubscriptionSchema(Schema): class Meta: unknown = EXCLUDE uuid = fields.UUID(dump_only=True) name = fields.String(validate=Length(max=128), required=True) service = fields.String(validate=Length(max=128), allow_none=False, required=True) events = fields.List( fields.String(validate=Length(max=128), allow_none=False), allow_none=False, required=True, ) events_user_uuid = fields.String(validate=Length(equal=36), missing=None) events_wazo_uuid = fields.String(validate=Length(equal=36), missing=None) config = ConfigField(allow_none=False, required=True) owner_user_uuid = fields.String(validate=Length(equal=36), missing=None) owner_tenant_uuid = fields.UUID(dump_only=True) # TODO(sileht): We should also add an events_tenant_uuid to filter # event on tenant_uuid. Currently if I have the # "webhookd.subscriptions.create" I can receive event of all tenants... metadata_ = fields.Dict(data_key="metadata")
class ConfigField(fields.Field): _default_options = fields.Dict(validate=validate_string_dict, allow_none=False, required=True) _options = { 'http': fields.Nested(HTTPSubscriptionConfigSchema, required=True) } def _deserialize(self, value, attr, data, **kwargs): service = data.get('service') try: concrete_options = self._options.get(service, self._default_options) except TypeError: raise ValidationError({ 'message': 'Invalid destination', 'constraint_id': 'destination-type', 'constraint': { 'type': 'string' }, }) return concrete_options.deserialize(value, attr, data, **kwargs)
class ServiceConfigSchema(BaseSchema): sources = fields.Nested(ResourceSchema, many=True, missing=[]) options = fields.Dict(missing={})