-
Notifications
You must be signed in to change notification settings - Fork 203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor severity score model and fix incorrect suse scores #1636
Changes from 13 commits
db82a62
05d84c3
46f4b5a
c4636f4
86947a5
0ad0a19
00354da
287c834
16cb2f0
b2d1e20
b5e2883
4107451
9d0791f
a008c37
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,6 @@ | |
from rest_framework.response import Response | ||
from rest_framework.reverse import reverse | ||
|
||
from vulnerabilities.api import VulnerabilitySeveritySerializer | ||
from vulnerabilities.models import Package | ||
from vulnerabilities.models import Vulnerability | ||
from vulnerabilities.models import VulnerabilityReference | ||
|
@@ -41,11 +40,24 @@ class Meta: | |
fields = ["url", "reference_type", "reference_id"] | ||
|
||
|
||
class VulnerabilitySeverityV2Serializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = VulnerabilitySeverity | ||
fields = ["url", "value", "scoring_system", "scoring_elements", "published_at"] | ||
|
||
def to_representation(self, instance): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why we need There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added this just to preserve the response structure we're already using in APIv2 https://github.com/aboutcode-org/vulnerablecode/blob/8a68c97dfa369ad048de3ece14cc1b3cf40591cc/vulnerabilities/api_v2.py#L16C33-L16C64. IMO yes we should simpy send |
||
data = super().to_representation(instance) | ||
published_at = data.get("published_at", None) | ||
if not published_at: | ||
data.pop("published_at") | ||
return data | ||
|
||
|
||
class VulnerabilityV2Serializer(serializers.ModelSerializer): | ||
aliases = serializers.SerializerMethodField() | ||
weaknesses = WeaknessV2Serializer(many=True) | ||
references = VulnerabilityReferenceV2Serializer(many=True, source="vulnerabilityreference_set") | ||
severities = VulnerabilitySeveritySerializer(many=True) | ||
severities = VulnerabilitySeverityV2Serializer(many=True) | ||
|
||
class Meta: | ||
model = Vulnerability | ||
|
@@ -61,9 +73,6 @@ class Meta: | |
def get_aliases(self, obj): | ||
return [alias.alias for alias in obj.aliases.all()] | ||
|
||
def get_severities(self, obj): | ||
return obj.severities | ||
|
||
|
||
class VulnerabilityListSerializer(serializers.ModelSerializer): | ||
url = serializers.SerializerMethodField() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor nit: Why we are having a method here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In our old API,
references
used to contain the nestedseverity
, as severity and reference were related through a foreignkey relationship. In our new model we have dissociated reference and severity. To ensure we maintain compatibility for existing users of old API we're manually crafting the references to include the relevant severity.