mirror of https://github.com/jumpserver/jumpserver
				
				
				
			Merge branch 'v3' of github.com:jumpserver/jumpserver into v3
						commit
						3172e954a8
					
				| 
						 | 
				
			
			@ -1,4 +1,4 @@
 | 
			
		|||
from assets.models import Cloud
 | 
			
		||||
from assets.models import Cloud, Asset
 | 
			
		||||
from assets.serializers import CloudSerializer
 | 
			
		||||
 | 
			
		||||
from .asset import AssetViewSet
 | 
			
		||||
| 
						 | 
				
			
			@ -8,6 +8,7 @@ __all__ = ['CloudViewSet']
 | 
			
		|||
 | 
			
		||||
class CloudViewSet(AssetViewSet):
 | 
			
		||||
    model = Cloud
 | 
			
		||||
    perm_model = Asset
 | 
			
		||||
 | 
			
		||||
    def get_serializer_classes(self):
 | 
			
		||||
        serializer_classes = super().get_serializer_classes()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,4 +1,4 @@
 | 
			
		|||
from assets.models import Database
 | 
			
		||||
from assets.models import Database, Asset
 | 
			
		||||
from assets.serializers import DatabaseSerializer
 | 
			
		||||
 | 
			
		||||
from .asset import AssetViewSet
 | 
			
		||||
| 
						 | 
				
			
			@ -8,6 +8,7 @@ __all__ = ['DatabaseViewSet']
 | 
			
		|||
 | 
			
		||||
class DatabaseViewSet(AssetViewSet):
 | 
			
		||||
    model = Database
 | 
			
		||||
    perm_model = Asset
 | 
			
		||||
 | 
			
		||||
    def get_serializer_classes(self):
 | 
			
		||||
        serializer_classes = super().get_serializer_classes()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,6 +1,5 @@
 | 
			
		|||
 | 
			
		||||
from assets.serializers import DeviceSerializer
 | 
			
		||||
from assets.models import Device
 | 
			
		||||
from assets.models import Device, Asset
 | 
			
		||||
from .asset import AssetViewSet
 | 
			
		||||
 | 
			
		||||
__all__ = ['DeviceViewSet']
 | 
			
		||||
| 
						 | 
				
			
			@ -8,6 +7,7 @@ __all__ = ['DeviceViewSet']
 | 
			
		|||
 | 
			
		||||
class DeviceViewSet(AssetViewSet):
 | 
			
		||||
    model = Device
 | 
			
		||||
    perm_model = Asset
 | 
			
		||||
 | 
			
		||||
    def get_serializer_classes(self):
 | 
			
		||||
        serializer_classes = super().get_serializer_classes()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,4 +1,4 @@
 | 
			
		|||
from assets.models import Host
 | 
			
		||||
from assets.models import Host, Asset
 | 
			
		||||
from assets.serializers import HostSerializer
 | 
			
		||||
from .asset import AssetViewSet
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -7,6 +7,7 @@ __all__ = ['HostViewSet']
 | 
			
		|||
 | 
			
		||||
class HostViewSet(AssetViewSet):
 | 
			
		||||
    model = Host
 | 
			
		||||
    perm_model = Asset
 | 
			
		||||
 | 
			
		||||
    def get_serializer_classes(self):
 | 
			
		||||
        serializer_classes = super().get_serializer_classes()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,4 +1,4 @@
 | 
			
		|||
from assets.models import Web
 | 
			
		||||
from assets.models import Web, Asset
 | 
			
		||||
from assets.serializers import WebSerializer
 | 
			
		||||
 | 
			
		||||
from .asset import AssetViewSet
 | 
			
		||||
| 
						 | 
				
			
			@ -8,6 +8,7 @@ __all__ = ['WebViewSet']
 | 
			
		|||
 | 
			
		||||
class WebViewSet(AssetViewSet):
 | 
			
		||||
    model = Web
 | 
			
		||||
    perm_model = Asset
 | 
			
		||||
 | 
			
		||||
    def get_serializer_classes(self):
 | 
			
		||||
        serializer_classes = super().get_serializer_classes()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,11 +5,12 @@ from rest_framework.response import Response
 | 
			
		|||
from ops.models import Job, JobExecution
 | 
			
		||||
from ops.serializers.job import JobSerializer, JobExecutionSerializer
 | 
			
		||||
 | 
			
		||||
__all__ = ['JobViewSet', 'JobExecutionViewSet', 'JobRunVariableHelpAPIView', 'JobAssetDetail', ]
 | 
			
		||||
__all__ = ['JobViewSet', 'JobExecutionViewSet', 'JobRunVariableHelpAPIView', 'JobAssetDetail', 'JobExecutionTaskDetail']
 | 
			
		||||
 | 
			
		||||
from ops.tasks import run_ops_job_execution
 | 
			
		||||
from ops.variables import JMS_JOB_VARIABLE_HELP
 | 
			
		||||
from orgs.mixins.api import OrgBulkModelViewSet
 | 
			
		||||
from orgs.utils import tmp_to_org, get_current_org_id, get_current_org
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def set_task_to_serializer_data(serializer, task):
 | 
			
		||||
| 
						 | 
				
			
			@ -93,3 +94,20 @@ class JobAssetDetail(APIView):
 | 
			
		|||
        if execution_id:
 | 
			
		||||
            execution = get_object_or_404(JobExecution, id=execution_id)
 | 
			
		||||
            return Response(data=execution.assent_result_detail)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class JobExecutionTaskDetail(APIView):
 | 
			
		||||
    rbac_perms = ()
 | 
			
		||||
    permission_classes = ()
 | 
			
		||||
 | 
			
		||||
    def get(self, request, **kwargs):
 | 
			
		||||
        org = get_current_org()
 | 
			
		||||
        task_id = request.query_params.get('task_id')
 | 
			
		||||
        if task_id:
 | 
			
		||||
            with tmp_to_org(org):
 | 
			
		||||
                execution = get_object_or_404(JobExecution, task_id=task_id)
 | 
			
		||||
                return Response(data={
 | 
			
		||||
                    'is_finished': execution.is_finished,
 | 
			
		||||
                    'is_success': execution.is_success,
 | 
			
		||||
                    'time_cost': execution.time_cost,
 | 
			
		||||
                })
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -25,6 +25,7 @@ router.register(r'task-executions', api.CeleryTaskExecutionViewSet, 'task-execut
 | 
			
		|||
urlpatterns = [
 | 
			
		||||
    path('variables/help/', api.JobRunVariableHelpAPIView.as_view(), name='variable-help'),
 | 
			
		||||
    path('job-execution/asset-detail/', api.JobAssetDetail.as_view(), name='asset-detail'),
 | 
			
		||||
    path('job-execution/task-detail/', api.JobExecutionTaskDetail.as_view(), name='task-detail'),
 | 
			
		||||
    path('ansible/job-execution/<uuid:pk>/log/', api.AnsibleTaskLogApi.as_view(), name='job-execution-log'),
 | 
			
		||||
 | 
			
		||||
    path('celery/task/<uuid:name>/task-execution/<uuid:pk>/log/', api.CeleryTaskExecutionLogApi.as_view(),
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -67,11 +67,12 @@ class TaskLogWebsocket(AsyncJsonWebsocketConsumer):
 | 
			
		|||
                            task_end_mark.append(1)
 | 
			
		||||
                    elif len(task_end_mark) == 2:
 | 
			
		||||
                        logger.debug('Task log end: {}'.format(task_id))
 | 
			
		||||
                        await self.send_json({'event': 'end', 'task': task_id})
 | 
			
		||||
                        break
 | 
			
		||||
                    await asyncio.sleep(0.2)
 | 
			
		||||
        except OSError as e:
 | 
			
		||||
            logger.warn('Task log path open failed: {}'.format(e))
 | 
			
		||||
        await self.close()
 | 
			
		||||
        # await self.close()
 | 
			
		||||
 | 
			
		||||
    async def disconnect(self, close_code):
 | 
			
		||||
        self.disconnected = True
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -36,6 +36,11 @@ exclude_permissions = (
 | 
			
		|||
    ('assets', 'gathereduser', 'add,delete,change', 'gathereduser'),
 | 
			
		||||
    ('assets', 'accountbackupplanexecution', 'delete,change', 'accountbackupplanexecution'),
 | 
			
		||||
    ('assets', 'gathereduser', 'add,delete,change', 'gathereduser'),
 | 
			
		||||
    ('assets', 'web', '*', '*'),
 | 
			
		||||
    ('assets', 'host', '*', '*'),
 | 
			
		||||
    ('assets', 'cloud', '*', '*'),
 | 
			
		||||
    ('assets', 'device', '*', '*'),
 | 
			
		||||
    ('assets', 'database', '*', '*'),
 | 
			
		||||
    ('assets', 'protocol', '*', '*'),
 | 
			
		||||
    ('assets', 'systemuser', '*', '*'),
 | 
			
		||||
    ('assets', 'baseautomation', '*', '*'),
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue