mirror of
https://github.com/jumpserver/jumpserver.git
synced 2026-07-11 09:25:03 +00:00
fix:remove unused task log APIs
This commit is contained in:
@@ -104,7 +104,6 @@ user_accessible_urls = known_unauth_urls + [
|
||||
"/api/v1/authentication/passkeys/",
|
||||
"/api/v1/orgs/orgs/current/",
|
||||
"/api/v1/tickets/apply-asset-tickets/",
|
||||
"/api/v1/ops/celery/task/00000000-0000-0000-0000-000000000000/task-execution/00000000-0000-0000-0000-000000000000/log/",
|
||||
"/api/v1/assets/favorite-assets/",
|
||||
"/api/v1/authentication/connection-token/",
|
||||
"/api/v1/ops/jobs/",
|
||||
@@ -116,13 +115,11 @@ user_accessible_urls = known_unauth_urls + [
|
||||
"/api/v1/users/profile/permissions/",
|
||||
"/api/v1/tickets/apply-login-asset-tickets/",
|
||||
"/api/v1/resources/",
|
||||
"/api/v1/ops/celery/task/00000000-0000-0000-0000-000000000000/task-execution/00000000-0000-0000-0000-000000000000/result/",
|
||||
"/api/v1/notifications/site-messages/",
|
||||
"/api/v1/notifications/site-messages/unread-total/",
|
||||
"/api/v1/assets/assets/suggestions/",
|
||||
"/api/v1/search/",
|
||||
"/api/v1/notifications/user-msg-subscription/",
|
||||
"/api/v1/ops/ansible/job-execution/00000000-0000-0000-0000-000000000000/log/",
|
||||
"/api/v1/tickets/apply-login-tickets/",
|
||||
"/api/v1/ops/variables/form-data/",
|
||||
"/api/v1/ops/variables/help/",
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
import os
|
||||
import re
|
||||
from collections import defaultdict
|
||||
|
||||
from celery.result import AsyncResult
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.utils.translation import gettext as _
|
||||
from django_celery_beat.models import PeriodicTask
|
||||
@@ -12,84 +10,21 @@ from django_filters import rest_framework as drf_filters
|
||||
from rest_framework import generics, viewsets, mixins, status
|
||||
from rest_framework.response import Response
|
||||
|
||||
from common.api import LogTailApi, CommonApiMixin
|
||||
from common.api import CommonApiMixin
|
||||
from common.drf.filters import BaseFilterSet
|
||||
from common.exceptions import JMSException
|
||||
from common.permissions import IsValidUser
|
||||
from common.utils.timezone import local_now
|
||||
from ops.celery import app
|
||||
from ..ansible.utils import get_ansible_task_log_path
|
||||
from ..celery.utils import get_celery_task_log_path
|
||||
from ..models import CeleryTaskExecution, CeleryTask
|
||||
from ..serializers import CeleryResultSerializer, CeleryPeriodTaskSerializer
|
||||
from ..serializers import CeleryPeriodTaskSerializer
|
||||
from ..serializers.celery import CeleryTaskSerializer, CeleryTaskExecutionSerializer
|
||||
|
||||
__all__ = [
|
||||
'CeleryTaskExecutionLogApi', 'CeleryResultApi', 'CeleryPeriodTaskViewSet',
|
||||
'AnsibleTaskLogApi', 'CeleryTaskViewSet', 'CeleryTaskExecutionViewSet'
|
||||
'CeleryPeriodTaskViewSet', 'CeleryTaskViewSet',
|
||||
'CeleryTaskExecutionViewSet'
|
||||
]
|
||||
|
||||
|
||||
class CeleryTaskExecutionLogApi(LogTailApi):
|
||||
permission_classes = (IsValidUser,)
|
||||
task = None
|
||||
task_id = ''
|
||||
pattern = re.compile(r'Task .* succeeded in \d+\.\d+s.*')
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
self.task_id = str(kwargs.get('pk'))
|
||||
self.task = AsyncResult(self.task_id)
|
||||
return super().get(request, *args, **kwargs)
|
||||
|
||||
def filter_line(self, line):
|
||||
if self.pattern.match(line):
|
||||
line = self.pattern.sub(line, '')
|
||||
return line
|
||||
|
||||
def get_log_path(self):
|
||||
new_path = get_celery_task_log_path(self.task_id)
|
||||
if new_path and os.path.isfile(new_path):
|
||||
return new_path
|
||||
try:
|
||||
task = CeleryTaskExecution.objects.get(id=self.task_id)
|
||||
except CeleryTaskExecution.DoesNotExist:
|
||||
return None
|
||||
return task.full_log_path
|
||||
|
||||
def is_file_finish_write(self):
|
||||
return self.task.ready()
|
||||
|
||||
def get_no_file_message(self, request):
|
||||
if self.mark == 'undefined':
|
||||
return '.'
|
||||
else:
|
||||
return _('Waiting task start')
|
||||
|
||||
|
||||
class AnsibleTaskLogApi(LogTailApi):
|
||||
permission_classes = (IsValidUser,)
|
||||
|
||||
def get_log_path(self):
|
||||
new_path = get_ansible_task_log_path(self.kwargs.get('pk'))
|
||||
if new_path and os.path.isfile(new_path):
|
||||
return new_path
|
||||
|
||||
def get_no_file_message(self, request):
|
||||
if self.mark == 'undefined':
|
||||
return '.'
|
||||
else:
|
||||
return _('Waiting task start')
|
||||
|
||||
|
||||
class CeleryResultApi(generics.RetrieveAPIView):
|
||||
permission_classes = (IsValidUser,)
|
||||
serializer_class = CeleryResultSerializer
|
||||
|
||||
def get_object(self):
|
||||
pk = self.kwargs.get('pk')
|
||||
return AsyncResult(str(pk))
|
||||
|
||||
|
||||
class CeleryPeriodTaskViewSet(CommonApiMixin, viewsets.ModelViewSet):
|
||||
queryset = PeriodicTask.objects.all()
|
||||
serializer_class = CeleryPeriodTaskSerializer
|
||||
|
||||
@@ -9,17 +9,11 @@ from ops.celery import app
|
||||
from ops.models import CeleryTask, CeleryTaskExecution
|
||||
|
||||
__all__ = [
|
||||
'CeleryResultSerializer', 'CeleryTaskExecutionSerializer',
|
||||
'CeleryPeriodTaskSerializer', 'CeleryTaskSerializer'
|
||||
'CeleryTaskExecutionSerializer', 'CeleryPeriodTaskSerializer',
|
||||
'CeleryTaskSerializer'
|
||||
]
|
||||
|
||||
|
||||
class CeleryResultSerializer(serializers.Serializer):
|
||||
id = serializers.UUIDField()
|
||||
result = serializers.JSONField()
|
||||
state = serializers.CharField(max_length=16)
|
||||
|
||||
|
||||
class CeleryPeriodTaskSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = PeriodicTask
|
||||
|
||||
@@ -27,14 +27,7 @@ urlpatterns = [
|
||||
path('variables/help/', api.JobRunVariableHelpAPIView.as_view(), name='variable-help'),
|
||||
path('job-execution/task-detail/<uuid:task_id>/', api.JobExecutionTaskDetail.as_view(), name='task-detail'),
|
||||
path('username-hints/', api.UsernameHintsAPI.as_view(), name='username-hints'),
|
||||
path('ansible/job-execution/<uuid:pk>/log/', api.AnsibleTaskLogApi.as_view(), name='job-execution-log'),
|
||||
path('classified-hosts/', api.ClassifiedHostsAPI.as_view(), name='classified-hosts'),
|
||||
|
||||
path('celery/task/<uuid:name>/task-execution/<uuid:pk>/log/', api.CeleryTaskExecutionLogApi.as_view(),
|
||||
name='celery-task-execution-log'),
|
||||
path('celery/task/<uuid:name>/task-execution/<uuid:pk>/result/', api.CeleryResultApi.as_view(),
|
||||
name='celery-task-execution-result'),
|
||||
|
||||
]
|
||||
|
||||
urlpatterns += (router.urls + bulk_router.urls)
|
||||
|
||||
Reference in New Issue
Block a user