|
| 1 | +# |
| 2 | +# Copyright (c) nexB Inc. and others. All rights reserved. |
| 3 | +# VulnerableCode is a trademark of nexB Inc. |
| 4 | +# SPDX-License-Identifier: Apache-2.0 |
| 5 | +# See http://www.apache.org/licenses/LICENSE-2.0 for the license text. |
| 6 | +# See https://github.com/nexB/vulnerablecode for support or download. |
| 7 | +# See https://aboutcode.org for more information about nexB OSS projects. |
| 8 | +# |
| 9 | + |
| 10 | +from ninja import ModelSchema |
| 11 | +from typing import List |
| 12 | + |
| 13 | +from fedcode import models |
| 14 | + |
| 15 | + |
| 16 | +class RemoteActor(ModelSchema): |
| 17 | + class Meta: |
| 18 | + model = models.RemoteActor |
| 19 | + fields = ["url", "username", "created_at", "updated_at"] |
| 20 | + |
| 21 | + |
| 22 | +class Repository(ModelSchema): |
| 23 | + """ |
| 24 | + A git repository used as a backing storage for Package and vulnerability data |
| 25 | + """ |
| 26 | + class Meta: |
| 27 | + model = models.Repository |
| 28 | + exclude = ["id", "admin"] |
| 29 | + |
| 30 | + |
| 31 | +class Vulnerability(ModelSchema): |
| 32 | + repo: Repository |
| 33 | + |
| 34 | + class Meta: |
| 35 | + model = models.Vulnerability |
| 36 | + exclude = ["id"] |
| 37 | + |
| 38 | + |
| 39 | +class Reputation(ModelSchema): |
| 40 | + """ |
| 41 | + https://www.w3.org/TR/activitystreams-vocabulary/#dfn-like |
| 42 | + https://www.w3.org/ns/activitystreams#Dislike |
| 43 | + """ |
| 44 | + class Meta: |
| 45 | + model = models.Reputation |
| 46 | + fields = ["voter", "positive"] |
| 47 | + |
| 48 | + |
| 49 | +class Note(ModelSchema): |
| 50 | + """ |
| 51 | + A Note is a message send by a Person or Package. |
| 52 | + The content is either a plain text message or structured YAML. |
| 53 | + If the author is a Package actor then the content is always YAML |
| 54 | + If the author is a Person actor then the content is always plain text |
| 55 | + https://www.w3.org/TR/activitystreams-vocabulary/#dfn-note |
| 56 | + """ |
| 57 | + reputation: List[Reputation] |
| 58 | + reply_to: "Note" |
| 59 | + |
| 60 | + class Meta: |
| 61 | + model = models.Note |
| 62 | + exclude = ["id"] |
| 63 | + |
| 64 | + |
| 65 | +Note.model_rebuild() |
| 66 | + |
| 67 | + |
| 68 | +class Package(ModelSchema): |
| 69 | + """ |
| 70 | + A software package identified by its package url ( PURL ) ignoring versions |
| 71 | + """ |
| 72 | + remote_actor: RemoteActor |
| 73 | + notes: List[Note] |
| 74 | + |
| 75 | + class Meta: |
| 76 | + model = models.Package |
| 77 | + exclude = ["id", "service"] |
0 commit comments