perf: some swagger api (#15203)

* perf: some swagger api

* perf: update deps

* perf: Update Dockerfile with new base image tag

---------

Co-authored-by: ibuler <ibuler@qq.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
This commit is contained in:
fit2bot
2025-04-15 11:43:36 +08:00
committed by GitHub
parent 8b9fe3c72b
commit 5390fbacec
20 changed files with 1287 additions and 1158 deletions

View File

@@ -97,10 +97,10 @@ class AssetFilterSet(BaseFilterSet):
return queryset.filter(protocols__name__in=value).distinct()
class AssetViewSet(SuggestionMixin, OrgBulkModelViewSet):
"""
API endpoint that allows Asset to be viewed or edited.
class BaseAssetViewSet(OrgBulkModelViewSet):
"""
API endpoint that allows Asset to be viewed or edited.
"""
model = Asset
filterset_class = AssetFilterSet
search_fields = ("name", "address", "comment")
@@ -143,6 +143,19 @@ class AssetViewSet(SuggestionMixin, OrgBulkModelViewSet):
return retrieve_cls
return cls
def create(self, request, *args, **kwargs):
if request.path.find('/api/v1/assets/assets/') > -1:
error = _('Cannot create asset directly, you should create a host or other')
return Response({'error': error}, status=400)
if not settings.XPACK_LICENSE_IS_VALID and self.model.objects.order_by().count() >= 5000:
error = _('The number of assets exceeds the limit of 5000')
return Response({'error': error}, status=400)
return super().create(request, *args, **kwargs)
class AssetViewSet(SuggestionMixin, BaseAssetViewSet):
@action(methods=["GET"], detail=True, url_path="platform")
def platform(self, *args, **kwargs):
asset = super().get_object()
@@ -197,17 +210,6 @@ class AssetViewSet(SuggestionMixin, OrgBulkModelViewSet):
Protocol.objects.bulk_create(objs)
return Response(status=status.HTTP_200_OK)
def create(self, request, *args, **kwargs):
if request.path.find('/api/v1/assets/assets/') > -1:
error = _('Cannot create asset directly, you should create a host or other')
return Response({'error': error}, status=400)
if not settings.XPACK_LICENSE_IS_VALID and self.model.objects.order_by().count() >= 5000:
error = _('The number of assets exceeds the limit of 5000')
return Response({'error': error}, status=400)
return super().create(request, *args, **kwargs)
def filter_bulk_update_data(self):
bulk_data = []
skip_assets = []

View File

@@ -1,12 +1,12 @@
from assets.models import Cloud, Asset
from assets.serializers import CloudSerializer
from .asset import AssetViewSet
from .asset import BaseAssetViewSet
__all__ = ['CloudViewSet']
class CloudViewSet(AssetViewSet):
class CloudViewSet(BaseAssetViewSet):
model = Cloud
perm_model = Asset

View File

@@ -1,12 +1,12 @@
from assets.models import Custom, Asset
from assets.serializers import CustomSerializer
from .asset import AssetViewSet
from .asset import BaseAssetViewSet
__all__ = ['CustomViewSet']
class CustomViewSet(AssetViewSet):
class CustomViewSet(BaseAssetViewSet):
model = Custom
perm_model = Asset

View File

@@ -1,12 +1,12 @@
from assets.models import Database, Asset
from assets.serializers import DatabaseSerializer
from .asset import AssetViewSet
from .asset import BaseAssetViewSet
__all__ = ['DatabaseViewSet']
class DatabaseViewSet(AssetViewSet):
class DatabaseViewSet(BaseAssetViewSet):
model = Database
perm_model = Asset

View File

@@ -1,11 +1,11 @@
from assets.serializers import DeviceSerializer
from assets.models import Device, Asset
from .asset import AssetViewSet
from assets.serializers import DeviceSerializer
from .asset import BaseAssetViewSet
__all__ = ['DeviceViewSet']
class DeviceViewSet(AssetViewSet):
class DeviceViewSet(BaseAssetViewSet):
model = Device
perm_model = Asset

View File

@@ -1,12 +1,12 @@
from assets.models import DirectoryService, Asset
from assets.serializers import DSSerializer
from .asset import AssetViewSet
from .asset import BaseAssetViewSet
__all__ = ['DSViewSet']
class DSViewSet(AssetViewSet):
class DSViewSet(BaseAssetViewSet):
model = DirectoryService
perm_model = Asset

View File

@@ -1,12 +1,12 @@
from assets.models import GPT, Asset
from assets.serializers import GPTSerializer
from .asset import AssetViewSet
from .asset import BaseAssetViewSet
__all__ = ['GPTViewSet']
class GPTViewSet(AssetViewSet):
class GPTViewSet(BaseAssetViewSet):
model = GPT
perm_model = Asset

View File

@@ -1,11 +1,11 @@
from assets.models import Host, Asset
from assets.serializers import HostSerializer
from .asset import AssetViewSet
from .asset import BaseAssetViewSet
__all__ = ['HostViewSet']
class HostViewSet(AssetViewSet):
class HostViewSet(BaseAssetViewSet):
model = Host
perm_model = Asset

View File

@@ -1,12 +1,12 @@
from assets.models import Web, Asset
from assets.serializers import WebSerializer
from .asset import AssetViewSet
from .asset import BaseAssetViewSet
__all__ = ['WebViewSet']
class WebViewSet(AssetViewSet):
class WebViewSet(BaseAssetViewSet):
model = Web
perm_model = Asset