Skip to content
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

feat: add chinese sca #1683

Merged
merged 6 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions dongtai_common/migrations/0004_auto_20230731_1556.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 3.2.20 on 2023-07-31 15:56

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("dongtai_common", "0003_auto_20230728_1444"),
]

operations = [
migrations.AddField(
model_name="iastassetvulv2",
name="vul_detail_zh",
field=models.TextField(blank=True),
),
migrations.AddField(
model_name="iastassetvulv2",
name="vul_name_zh",
field=models.CharField(blank=True, max_length=255),
),
]
2 changes: 2 additions & 0 deletions dongtai_common/models/asset_vul_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

class IastAssetVulV2(models.Model):
vul_name = models.CharField(max_length=255, blank=True)
vul_name_zh = models.CharField(max_length=255, blank=True)
vul_detail = models.TextField()
vul_detail_zh = models.TextField(blank=True)
# 漏洞类型等级
level = models.IntegerField(
choices=AssetRiskLevel.choices,
Expand Down
15 changes: 14 additions & 1 deletion dongtai_common/serializers/assetvulv2.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
from rest_framework import serializers

from dongtai_common.models.asset_vul_v2 import IastAssetVulV2
from dongtai_web.dongtai_sca.scan.utils import get_sca_language_profile


class PackageVulSerializer(serializers.ModelSerializer):
vul_name = serializers.SerializerMethodField()
vul_detail = serializers.SerializerMethodField()
level_name = serializers.CharField(source="get_level_display")
level_id = serializers.IntegerField(source="level")

class Meta:
model = IastAssetVulV2
fields = "__all__"
exclude = ["vul_name_zh", "vul_detail_zh"]

def get_vul_name(self, obj: IastAssetVulV2) -> str:
if get_sca_language_profile()["language"] == "zh":
return obj.vul_name_zh or obj.vul_name
return obj.vul_name

def get_vul_detail(self, obj: IastAssetVulV2) -> str:
if get_sca_language_profile()["language"] == "zh":
return obj.vul_detail_zh or obj.vul_detail
return obj.vul_detail
6 changes: 5 additions & 1 deletion dongtai_conf/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@
"exchange": "dongtai-replay-vul-scan",
"routing_key": "dongtai-replay-vul-scan",
},
"dongtai_web.dongtai_sca.scan.utils.update_one_sca": {
"dongtai_web.dongtai_sca.scan.tasks.update_one_sca": {
"exchange": "dongtai-sca-task",
"routing_key": "dongtai-sca-task",
},
"dongtai_web.dongtai_sca.scan.tasks.new_update_one_sca": {
"exchange": "dongtai-sca-task",
"routing_key": "dongtai-sca-task",
},
Expand Down
2 changes: 1 addition & 1 deletion dongtai_protocol/report/handler/sca_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from dongtai_common.utils import const
from dongtai_protocol.report.handler.report_handler_interface import IReportHandler
from dongtai_protocol.report.report_handler_factory import ReportHandler
from dongtai_web.dongtai_sca.scan.utils import new_update_one_sca, update_one_sca
from dongtai_web.dongtai_sca.scan.tasks import new_update_one_sca, update_one_sca

logger = logging.getLogger("dongtai.openapi")

Expand Down
12 changes: 10 additions & 2 deletions dongtai_web/dongtai_sca/common/dataclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,19 @@
# Be careful with potentially nullable types when using them temporarily.


@dataclass_json
@dataclass
class I18nStr:
en: str = ""
zh: str | None = None


@dataclass_json
@dataclass
class Reference:
type: str = ""
url: str = ""
language: str = ""


@dataclass_json
Expand All @@ -29,8 +37,8 @@ class VulInfo:
vul_id: str = ""
cvss_v3: str = ""
cwe: tuple[str, ...] = ()
title: str = ""
description: str = ""
title: I18nStr = field(default_factory=I18nStr)
description: I18nStr = field(default_factory=I18nStr)
references: tuple[Reference, ...] = ()
severity: str = ""
published_time: datetime | None = field(
Expand Down
Loading