mirror of https://github.com/jumpserver/jumpserver
fix: 修改访问swagger会产生的错误
parent
f9cf2a243b
commit
b9717eece3
|
@ -1,3 +1,5 @@
|
|||
import uuid
|
||||
|
||||
from common.exceptions import JMSException
|
||||
from orgs.models import Organization
|
||||
from .. import models
|
||||
|
@ -7,6 +9,8 @@ class ApplicationAttrsSerializerViewMixin:
|
|||
|
||||
def get_serializer_class(self):
|
||||
serializer_class = super().get_serializer_class()
|
||||
if getattr(self, 'swagger_fake_view', False):
|
||||
return serializer_class
|
||||
app_type = self.request.query_params.get('type')
|
||||
app_category = self.request.query_params.get('category')
|
||||
type_options = list(dict(models.Category.get_all_type_serializer_mapper()).keys())
|
||||
|
@ -38,12 +42,16 @@ class ApplicationAttrsSerializerViewMixin:
|
|||
if app_type:
|
||||
# action: create / update / list / retrieve / metadata
|
||||
attrs_cls = models.Category.get_type_serializer_cls(app_type)
|
||||
class_name = 'ApplicationDynamicSerializer{}'.format(app_type.title())
|
||||
elif app_category:
|
||||
# action: list / retrieve / metadata
|
||||
attrs_cls = models.Category.get_category_serializer_cls(app_category)
|
||||
class_name = 'ApplicationDynamicSerializer{}'.format(app_category.title())
|
||||
else:
|
||||
attrs_cls = models.Category.get_no_password_serializer_cls()
|
||||
return type('ApplicationDynamicSerializer', (serializer_class,), {'attrs': attrs_cls()})
|
||||
class_name = 'ApplicationDynamicSerializer'
|
||||
cls = type(class_name, (serializer_class,), {'attrs': attrs_cls()})
|
||||
return cls
|
||||
|
||||
|
||||
class SerializeApplicationToTreeNodeMixin:
|
||||
|
|
|
@ -115,7 +115,6 @@ class AssetTaskCreateApi(generics.CreateAPIView):
|
|||
class AssetGatewayListApi(generics.ListAPIView):
|
||||
permission_classes = (IsOrgAdminOrAppUser,)
|
||||
serializer_class = serializers.GatewayWithAuthSerializer
|
||||
model = Asset
|
||||
|
||||
def get_queryset(self):
|
||||
asset_id = self.kwargs.get('pk')
|
||||
|
|
|
@ -57,6 +57,7 @@ INSTALLED_APPS = [
|
|||
'django_filters',
|
||||
'bootstrap3',
|
||||
'captcha',
|
||||
'django_prometheus',
|
||||
'django_celery_beat',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.admin',
|
||||
|
@ -69,6 +70,7 @@ INSTALLED_APPS = [
|
|||
|
||||
|
||||
MIDDLEWARE = [
|
||||
'django_prometheus.middleware.PrometheusBeforeMiddleware',
|
||||
'django.middleware.security.SecurityMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.middleware.locale.LocaleMiddleware',
|
||||
|
@ -84,6 +86,7 @@ MIDDLEWARE = [
|
|||
'orgs.middleware.OrgMiddleware',
|
||||
'authentication.backends.oidc.middleware.OIDCRefreshIDTokenMiddleware',
|
||||
'authentication.backends.cas.middleware.CASMiddleware',
|
||||
'django_prometheus.middleware.PrometheusAfterMiddleware',
|
||||
]
|
||||
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ from django.urls import path, include, re_path
|
|||
from django.conf import settings
|
||||
from django.conf.urls.static import static
|
||||
from django.conf.urls.i18n import i18n_patterns
|
||||
from django.http import HttpResponse
|
||||
from django.views.i18n import JavaScriptCatalog
|
||||
|
||||
from . import views, api
|
||||
|
@ -54,7 +55,41 @@ apps = [
|
|||
]
|
||||
|
||||
|
||||
def test_metric(request):
|
||||
import random
|
||||
data = ""
|
||||
components = ['koko', 'guacamole', 'omnidb']
|
||||
status = ['normal', 'high', 'critical', 'total']
|
||||
|
||||
data += "# JumpServer 各组件状态个数汇总\n"
|
||||
for com in components:
|
||||
data += f"## 组件: {com}\n"
|
||||
for s in status:
|
||||
key = 'jumpserver_components_status_total{component_type="%s", status="%s"}' % (com, s)
|
||||
value = round(10 * random.random() * 10, 2)
|
||||
data += f"{key} {value}\n"
|
||||
|
||||
data += "\n# JumpServer 各组件在线会话数汇总\n"
|
||||
for com in components:
|
||||
for item in ['session_active']:
|
||||
key = 'jumpserver_components_%s_total{component_type="%s"}' % (item, com)
|
||||
value = round(40 * random.random() * 10, 2)
|
||||
data += f"{key} {value}\n"
|
||||
|
||||
data += "\n# JumpServer 各组件节点一些指标\n"
|
||||
for item in ['cpu1_load', 'memory_used_percent', 'disk_used_percent', 'session_active']:
|
||||
data += f"## 指标: {item}\n"
|
||||
for com in components:
|
||||
for instance in ['node1', 'node2', 'node3']:
|
||||
key = 'jumpserver_components_%s{component_type="%s", component="%s"}' % (item, com, instance)
|
||||
value = round(20 * random.random() * 10, 2)
|
||||
data += f"{key} {value}\n"
|
||||
return HttpResponse(data, content_type='text/plain; version=0.0.4; charset=utf-8')
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
# path('prometheus/', include('django_prometheus.urls')),
|
||||
path('prometheus/metrics', test_metric),
|
||||
path('', views.IndexView.as_view(), name='index'),
|
||||
path('api/v1/', include(api_v1)),
|
||||
path('api/v2/', include(api_v2)),
|
||||
|
|
|
@ -128,6 +128,7 @@ class CommandExecutionSerializer(serializers.ModelSerializer):
|
|||
'result', 'is_finished', 'log_url', 'date_created',
|
||||
'date_finished'
|
||||
]
|
||||
ref_name = 'OpsCommandExecution'
|
||||
|
||||
@staticmethod
|
||||
def get_log_url(obj):
|
||||
|
|
|
@ -72,6 +72,8 @@ class UserGroupGrantedNodeAssetsApi(ListAPIView):
|
|||
search_fields = ['hostname', 'ip', 'comment']
|
||||
|
||||
def get_queryset(self):
|
||||
if getattr(self, 'swagger_fake_view', False):
|
||||
return Asset.objects.none()
|
||||
user_group_id = self.kwargs.get('pk', '')
|
||||
node_id = self.kwargs.get("node_id")
|
||||
node = Node.objects.get(id=node_id)
|
||||
|
|
|
@ -31,6 +31,8 @@ class UserDirectGrantedAssetsApi(ListAPIView):
|
|||
search_fields = ['hostname', 'ip', 'comment']
|
||||
|
||||
def get_queryset(self):
|
||||
if getattr(self, 'swagger_fake_view', False):
|
||||
return Asset.objects.none()
|
||||
user = self.user
|
||||
assets = get_user_direct_granted_assets(user)\
|
||||
.prefetch_related('platform')\
|
||||
|
@ -45,6 +47,8 @@ class UserFavoriteGrantedAssetsApi(ListAPIView):
|
|||
search_fields = ['hostname', 'ip', 'comment']
|
||||
|
||||
def get_queryset(self):
|
||||
if getattr(self, 'swagger_fake_view', False):
|
||||
return Asset.objects.none()
|
||||
user = self.user
|
||||
assets = FavoriteAsset.get_user_favorite_assets(user)\
|
||||
.prefetch_related('platform')\
|
||||
|
@ -101,6 +105,8 @@ class UserAllGrantedAssetsApi(ForAdminMixin, ListAPIView):
|
|||
search_fields = ['hostname', 'ip', 'comment']
|
||||
|
||||
def get_queryset(self):
|
||||
if getattr(self, 'swagger_fake_view', False):
|
||||
return Asset.objects.none()
|
||||
queryset = get_user_granted_all_assets(self.user)
|
||||
queryset = queryset.prefetch_related('platform')
|
||||
return queryset.only(*self.only_fields)
|
||||
|
@ -123,6 +129,8 @@ class UserGrantedNodeAssetsApi(UserNodeGrantStatusDispatchMixin, ListAPIView):
|
|||
pagination_node: Node
|
||||
|
||||
def get_queryset(self):
|
||||
if getattr(self, 'swagger_fake_view', False):
|
||||
return Asset.objects.none()
|
||||
node_id = self.kwargs.get("node_id")
|
||||
node = Node.objects.get(id=node_id)
|
||||
self.pagination_node = node
|
||||
|
|
|
@ -62,6 +62,8 @@ class Action:
|
|||
|
||||
@classmethod
|
||||
def value_to_choices(cls, value):
|
||||
if isinstance(value, list):
|
||||
return value
|
||||
value = int(value)
|
||||
choices = [cls.NAME_MAP[i] for i, j in cls.DB_CHOICES if value & i == i]
|
||||
return choices
|
||||
|
|
|
@ -16,3 +16,4 @@ class SystemUserSerializer(serializers.ModelSerializer):
|
|||
'auto_push', 'cmd_filters', 'sudo', 'shell', 'comment',
|
||||
'sftp_root', 'date_created', 'created_by'
|
||||
]
|
||||
ref_name = 'PermedSystemUserSerializer'
|
||||
|
|
|
@ -68,3 +68,4 @@ class TaskSerializer(BulkModelSerializer):
|
|||
fields = '__all__'
|
||||
model = Task
|
||||
list_serializer_class = AdaptedBulkListSerializer
|
||||
ref_name = 'TerminalTaskSerializer'
|
||||
|
|
Loading…
Reference in New Issue