示例#1
0
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__)
示例#2
0
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)
示例#3
0
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'
示例#4
0
class Tag(Thing):
    id = String(description='The ID of the tag.',
                validator=lambda x: '/' not in x,
                required=True)
    provider = URL(description='The provider URL.')
    device = NestedOn(Device, description='The device linked to this tag.')
    org = String(description='The organization that issued the tag.')
示例#5
0
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__)
示例#6
0
class Thing(Schema):
    type = String(description=_type_description)
    same_as = List(URL(dump_only=True), dump_only=True, data_key='sameAs')
    updated = DateTime('iso',
                       dump_only=True,
                       description=m.Thing.updated.comment)
    created = DateTime('iso',
                       dump_only=True,
                       description=m.Thing.created.comment)

    @post_load
    def remove_type(self, data: dict):
        data.pop('type', None)
示例#7
0
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__)
示例#8
0
class Manufacturer(Schema):
    __doc__ = m.Manufacturer.__doc__

    name = String(dump_only=True)
    url = URL(dump_only=True)
    logo = URL(dump_only=True)
示例#9
0
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'])
示例#10
0
class EraseBasic(EventWithOneDevice):
    __doc__ = m.EraseBasic.__doc__
    steps = NestedOn('Step', many=True)
    standards = f.List(EnumField(enums.ErasureStandards), dump_only=True)
    certificate = URL(dump_only=True)
示例#11
0
class Migrate(EventWithMultipleDevices):
    __doc__ = m.Migrate.__doc__
    other = URL()