Exemplo n.º 1
0
class LicenseSchema(AutoSchema):
    _id = fields.Integer(dump_only=True, attribute='id')
    end = StrictDateTimeField(load_as_tz_aware=False, attribute='end_date')
    start = StrictDateTimeField(load_as_tz_aware=False, attribute='start_date')
    lictype = NullToBlankString(attribute='type')

    class Meta:
        model = License
        fields = ('_id', 'id', 'product', 'start', 'end', 'lictype', 'notes')
Exemplo n.º 2
0
class HostSchema(AutoSchema):
    _id = fields.Integer(dump_only=True, attribute='id')
    id = fields.Integer()
    _rev = fields.String(default='', dump_only=True)
    ip = fields.String(default='')
    description = fields.String(required=True)  # Explicitly set required=True
    default_gateway = NullToBlankString(attribute="default_gateway_ip",
                                        required=False)
    name = fields.String(dump_only=True, attribute='ip', default='')
    os = fields.String(default='')
    owned = fields.Boolean(default=False)
    owner = PrimaryKeyRelatedField('username',
                                   attribute='creator',
                                   dump_only=True)
    services = fields.Integer(attribute='open_service_count', dump_only=True)
    vulns = fields.Integer(attribute='vulnerability_count', dump_only=True)
    credentials = fields.Integer(attribute='credentials_count', dump_only=True)
    hostnames = MutableField(
        PrimaryKeyRelatedField('name',
                               many=True,
                               attribute="hostnames",
                               dump_only=True,
                               default=[]), fields.List(fields.String))
    metadata = SelfNestedField(MetadataSchema())
    type = fields.Function(lambda obj: 'Host', dump_only=True)
    service_summaries = fields.Method('get_service_summaries', dump_only=True)
    versions = fields.Method('get_service_version', dump_only=True)
    important = fields.Boolean(default=False)
    severity_counts = SelfNestedField(HostCountSchema(), dump_only=True)

    class Meta:
        model = Host
        fields = ('id', '_id', '_rev', 'ip', 'description', 'mac',
                  'credentials', 'default_gateway', 'metadata', 'name', 'os',
                  'owned', 'owner', 'services', 'vulns', 'hostnames', 'type',
                  'service_summaries', 'versions', 'important',
                  'severity_counts')

    def get_service_summaries(self, obj):
        return [
            service.summary for service in obj.services
            if service.status == 'open'
        ]

    def get_service_version(self, obj):
        return [
            service.version for service in obj.services
            if service.status == 'open'
        ]
Exemplo n.º 3
0
 class NullToBlankSchema(Schema):
     string = NullToBlankString(missing='test')