class TradeDocument(Thing): __doc__ = m.TradeDocument.__doc__ id = Integer(description=m.TradeDocument.id.comment, dump_only=True) date = DateTime(required=False, description=m.TradeDocument.date.comment) id_document = SanitizedStr(data_key='documentId', default='', description=m.TradeDocument.id_document.comment) description = SanitizedStr(default='', description=m.TradeDocument.description.comment, validate=validate.Length(max=500)) file_name = SanitizedStr(data_key='filename', default='', description=m.TradeDocument.file_name.comment, validate=validate.Length(max=100)) file_hash = SanitizedStr(data_key='hash', default='', description=m.TradeDocument.file_hash.comment, validate=validate.Length(max=64)) url = URL(description=m.TradeDocument.url.comment) lot = NestedOn('Lot', only_query='id', description=m.TradeDocument.lot.__doc__) trading = SanitizedStr(dump_only=True, description='') weight = Float(required=False, description=m.TradeDocument.weight.comment) total_weight = Float(required=False, description=m.TradeDocument.weight.comment)
class DataWipeDocument(Thing): __doc__ = m.DataWipeDocument.__doc__ id = Integer(description=m.DataWipeDocument.id.comment, dump_only=True) url = URL(required=False, description=m.DataWipeDocument.url.comment) success = Boolean(required=False, default=False, description=m.DataWipeDocument.success.comment) software = SanitizedStr(description=m.DataWipeDocument.software.comment) date = DateTime(data_key='endTime', required=False, description=m.DataWipeDocument.date.comment) id_document = SanitizedStr( data_key='documentId', required=False, default='', description=m.DataWipeDocument.id_document.comment) file_name = SanitizedStr(data_key='filename', default='', description=m.DataWipeDocument.file_name.comment, validate=validate.Length(max=100)) file_hash = SanitizedStr(data_key='hash', default='', description=m.DataWipeDocument.file_hash.comment, validate=validate.Length(max=64)) @post_load def get_trade_document(self, data): data['document_type'] = 'DataWipeDocument'
class Agent(Thing): id = ma_fields.UUID(dump_only=True) name = SanitizedStr(validate=ma_validate.Length(max=STR_SM_SIZE)) tax_id = SanitizedStr(lower=True, validate=ma_validate.Length(max=STR_SM_SIZE), data_key='taxId') country = EnumField(enums.Country) telephone = Phone() email = Email()
class Lot(Thing): id = f.UUID(dump_only=True) name = SanitizedStr(validate=f.validate.Length(max=STR_SIZE), required=True) description = SanitizedStr(description=m.Lot.description.comment) closed = f.Boolean(missing=False, description=m.Lot.closed.comment) devices = NestedOn(s_device.Device, many=True, dump_only=True) children = NestedOn('Lot', many=True, dump_only=True) parents = NestedOn('Lot', many=True, dump_only=True) url = URL(dump_only=True, description=m.Lot.url.__doc__)
class Tag(Thing): id = SanitizedStr(lower=True, description=m.Tag.id.comment, validator=without_slash, required=True) provider = URL(description=m.Tag.provider.comment, validator=without_slash) device = NestedOn(Device, dump_only=True) org = NestedOn(Organization, collection_class=OrderedSet, only_query='id') secondary = SanitizedStr(lower=True, description=m.Tag.secondary.comment) printable = Boolean(dump_only=True, decsription=m.Tag.printable.__doc__) url = URL(dump_only=True, description=m.Tag.url.__doc__)
class Live(EventWithOneDevice): __doc__ = m.Live.__doc__ ip = IP(dump_only=True) subdivision_confidence = Integer(dump_only=True, data_key='subdivisionConfidence') subdivision = EnumField(Subdivision, dump_only=True) country = EnumField(Country, dump_only=True) city = SanitizedStr(lower=True, dump_only=True) city_confidence = Integer(dump_only=True, data_key='cityConfidence') isp = SanitizedStr(lower=True, dump_only=True) organization = SanitizedStr(lower=True, dump_only=True) organization_type = SanitizedStr(lower=True, dump_only=True, data_key='organizationType')
class Allocate(EventWithMultipleDevices): __doc__ = m.Allocate.__doc__ to = NestedOn(s_user.User, description='The user the devices are allocated to.') organization = SanitizedStr(validate=Length(max=STR_SIZE), description='The organization where the ' 'user was when this happened.')
class Install(EventWithOneDevice): __doc__ = m.Install.__doc__ name = SanitizedStr(validate=Length(min=4, max=STR_BIG_SIZE), required=True, description='The name of the OS installed.') elapsed = TimeDelta(precision=TimeDelta.SECONDS, required=True) address = Integer(validate=OneOf({8, 16, 32, 64, 128, 256}))
class Deallocate(EventWithMultipleDevices): __doc__ = m.Deallocate.__doc__ from_rel = Nested( s_user.User, data_key='from', description='The user where the devices are not allocated to anymore.') organization = SanitizedStr(validate=Length(max=STR_SIZE), description='The organization where the ' 'user was when this happened.')
class Trade(EventWithMultipleDevices): __doc__ = m.Trade.__doc__ shipping_date = DateTime(data_key='shippingDate') invoice_number = SanitizedStr(validate=Length(max=STR_SIZE), data_key='invoiceNumber') price = NestedOn(Price) to = NestedOn(s_agent.Agent, only_query='id', required=True, comment=m.Trade.to_comment) confirms = NestedOn(Organize)
class Processor(Component): __doc__ = m.Processor.__doc__ speed = Float(validate=Range(min=0.1, max=15), unit=UnitCodes.ghz, description=m.Processor.speed.comment) cores = Integer(validate=Range(min=1, max=10), description=m.Processor.cores.comment) threads = Integer(validate=Range(min=1, max=20), description=m.Processor.threads.comment) address = Integer(validate=OneOf({8, 16, 32, 64, 128, 256}), description=m.Processor.address.comment) abi = SanitizedStr(lower=True, description=m.Processor.abi.comment)
class User(Thing): id = UUID(dump_only=True) email = Email(required=True) password = SanitizedStr(load_only=True, required=True) individuals = NestedOn(Individual, many=True, dump_only=True) name = SanitizedStr() token = String( dump_only=True, description= 'Use this token in an Authorization header to access the app.' 'The token can change overtime.') inventories = NestedOn(Inventory, many=True, dump_only=True) code = String(dump_only=True, description='Code of inactive accounts') def __init__(self, only=None, exclude=('token', ), prefix='', many=False, context=None, load_only=(), dump_only=(), partial=False): """Instantiates the User. By default we exclude token from both load/dump so they are not taken / set in normal usage by mistake. """ super().__init__(only, exclude, prefix, many, context, load_only, dump_only, partial) @post_dump def base64encode_token(self, data: dict): """Encodes the token to base64 so clients don't have to.""" if 'token' in data: # In many cases we don't dump the token (ex. relationships) # Framework needs ':' at the end data['token'] = auth.Auth.encode(data['token']) return data
class Event(Thing): __doc__ = m.Event.__doc__ id = UUID(dump_only=True) name = SanitizedStr(default='', validate=Length(max=STR_BIG_SIZE), description=m.Event.name.comment) closed = Boolean(missing=True, description=m.Event.closed.comment) severity = EnumField(Severity, description=m.Event.severity.comment) description = SanitizedStr(default='', description=m.Event.description.comment) start_time = DateTime(data_key='startTime', description=m.Event.start_time.comment) end_time = DateTime(data_key='endTime', description=m.Event.end_time.comment) snapshot = NestedOn('Snapshot', dump_only=True) agent = NestedOn(s_agent.Agent, description=m.Event.agent_id.comment) author = NestedOn(s_user.User, dump_only=True, exclude=('token', )) components = NestedOn(s_device.Component, dump_only=True, many=True) parent = NestedOn(s_device.Computer, dump_only=True, description=m.Event.parent_id.comment) url = URL(dump_only=True, description=m.Event.url.__doc__)
class Deliverynote(Thing): id = f.UUID(dump_only=True) document_id = SanitizedStr(validate=f.validate.Length(max=STR_SIZE), required=True, data_key='documentID') creator = NestedOn(s_user.User, dump_only=True) supplier_email = SanitizedStr(validate=f.validate.Length(max=STR_SIZE), load_only=True, required=True, data_key='supplierEmail') supplier = NestedOn(s_user.User, dump_only=True) receiver = NestedOn(s_user.User, dump_only=True) date = f.DateTime('iso', required=True) amount = f.Integer(validate=f.validate.Range(min=0, max=100), description=m.Deliverynote.amount.__doc__) expected_devices = f.List(f.Dict, required=True, data_key='expectedDevices') transferred_devices = f.List(f.Integer(), required=False, data_key='transferredDevices') transfer_state = EnumField(TransferState, description=m.Lot.transfer_state.comment)
class TestDataStorage(Test): __doc__ = m.TestDataStorage.__doc__ length = EnumField(TestDataStorageLength, required=True) status = SanitizedStr(lower=True, validate=Length(max=STR_SIZE), required=True) lifetime = TimeDelta(precision=TimeDelta.HOURS) assessment = Boolean() reallocated_sector_count = Integer(data_key='reallocatedSectorCount') power_cycle_count = Integer(data_key='powerCycleCount') reported_uncorrectable_errors = Integer( data_key='reportedUncorrectableErrors') command_timeout = Integer(data_key='commandTimeout') current_pending_sector_count = Integer( data_key='currentPendingSectorCount') offline_uncorrectable = Integer(data_key='offlineUncorrectable') remaining_lifetime_percentage = Integer( data_key='remainingLifetimePercentage')
class Device(Thing): __doc__ = m.Device.__doc__ id = Integer(description=m.Device.id.comment, dump_only=True) hid = SanitizedStr(lower=True, dump_only=True, description=m.Device.hid.comment) tags = NestedOn('Tag', many=True, collection_class=OrderedSet, description='A set of tags that identify the device.') model = SanitizedStr(lower=True, validate=Length(max=STR_BIG_SIZE), description=m.Device.model.comment) manufacturer = SanitizedStr(lower=True, validate=Length(max=STR_SIZE), description=m.Device.manufacturer.comment) serial_number = SanitizedStr(lower=True, validate=Length(max=STR_BIG_SIZE), data_key='serialNumber') brand = SanitizedStr(validate=Length(max=STR_BIG_SIZE), description=m.Device.brand.comment) generation = Integer(validate=Range(1, 100), description=m.Device.generation.comment) weight = Float(validate=Range(0.1, 5), unit=UnitCodes.kgm, description=m.Device.weight.comment) width = Float(validate=Range(0.1, 5), unit=UnitCodes.m, description=m.Device.width.comment) height = Float(validate=Range(0.1, 5), unit=UnitCodes.m, description=m.Device.height.comment) depth = Float(validate=Range(0.1, 5), unit=UnitCodes.m, description=m.Device.depth.comment) events = NestedOn('Event', many=True, dump_only=True, description=m.Device.events.__doc__) events_one = NestedOn('Event', many=True, load_only=True, collection_class=OrderedSet) problems = NestedOn('Event', many=True, dump_only=True, description=m.Device.problems.__doc__) url = URL(dump_only=True, description=m.Device.url.__doc__) lots = NestedOn( 'Lot', many=True, dump_only=True, description='The lots where this device is directly under.') rate = NestedOn('AggregateRate', dump_only=True, description=m.Device.rate.__doc__) price = NestedOn('Price', dump_only=True, description=m.Device.price.__doc__) trading = EnumField(states.Trading, dump_only=True, description=m.Device.trading.__doc__) physical = EnumField(states.Physical, dump_only=True, description=m.Device.physical.__doc__) physical_possessor = NestedOn('Agent', dump_only=True, data_key='physicalPossessor') production_date = DateTime('iso', description=m.Device.updated.comment, data_key='productionDate') working = NestedOn('Event', many=True, dump_only=True, description=m.Device.working.__doc__) @pre_load def from_events_to_events_one(self, data: dict): """ Not an elegant way of allowing submitting events to a device (in the context of Snapshots) without creating an ``events`` field at the model (which is not possible). :param data: :return: """ # Note that it is secure to allow uploading events_one # as the only time an user can send a device object is # in snapshots. data['events_one'] = data.pop('events', []) return data @post_load def validate_snapshot_events(self, data): """Validates that only snapshot-related events can be uploaded.""" from ereuse_devicehub.resources.event.models import EraseBasic, Test, Rate, Install, \ Benchmark for event in data['events_one']: if not isinstance(event, (Install, EraseBasic, Rate, Test, Benchmark)): raise ValidationError('You cannot upload {}'.format(event), field_names=['events'])
class Foo(Schema): foo = SanitizedStr(lower=True)
class Membership(Thing): organization = NestedOn(Organization) individual = NestedOn('Individual') id = SanitizedStr(lower=True, validate=ma_validate.Length(max=STR_SIZE))