|
|
|
@ -3,10 +3,16 @@
|
|
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
import http.client
|
|
|
|
import http.client
|
|
|
|
|
|
|
|
|
|
|
|
from django.http import HttpResponseBadRequest, JsonResponse, HttpResponse
|
|
|
|
from django.http import HttpResponseBadRequest, HttpResponse
|
|
|
|
from rules.contrib.views import permission_required, objectgetter
|
|
|
|
from rules.contrib.views import permission_required, objectgetter
|
|
|
|
|
|
|
|
|
|
|
|
from cvat.apps.iam.decorators import login_required
|
|
|
|
from rest_framework.permissions import IsAuthenticated
|
|
|
|
|
|
|
|
from rest_framework.response import Response
|
|
|
|
|
|
|
|
from rest_framework.request import Request
|
|
|
|
|
|
|
|
from rest_framework.decorators import api_view, permission_classes
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from drf_spectacular.utils import extend_schema
|
|
|
|
|
|
|
|
|
|
|
|
from cvat.apps.engine.log import slogger
|
|
|
|
from cvat.apps.engine.log import slogger
|
|
|
|
from cvat.apps.engine import models
|
|
|
|
from cvat.apps.engine import models
|
|
|
|
from cvat.apps.dataset_repo.models import GitData
|
|
|
|
from cvat.apps.dataset_repo.models import GitData
|
|
|
|
@ -14,9 +20,21 @@ import contextlib
|
|
|
|
|
|
|
|
|
|
|
|
import cvat.apps.dataset_repo.dataset_repo as CVATGit
|
|
|
|
import cvat.apps.dataset_repo.dataset_repo as CVATGit
|
|
|
|
import django_rq
|
|
|
|
import django_rq
|
|
|
|
import json
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
def _legacy_api_view(allowed_method_names=None):
|
|
|
|
|
|
|
|
# Currently, the views in this file use the legacy permission-checking
|
|
|
|
|
|
|
|
# approach, so this decorator disables the default DRF permission classes.
|
|
|
|
|
|
|
|
# TODO: migrate to DRF permissions, make the views compatible with drf-spectacular,
|
|
|
|
|
|
|
|
# and remove this decorator.
|
|
|
|
|
|
|
|
def decorator(view):
|
|
|
|
|
|
|
|
view = permission_classes([IsAuthenticated])(view)
|
|
|
|
|
|
|
|
view = api_view(allowed_method_names)(view)
|
|
|
|
|
|
|
|
view = extend_schema(exclude=True)(view)
|
|
|
|
|
|
|
|
return view
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return decorator
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@_legacy_api_view()
|
|
|
|
def check_process(request, rq_id):
|
|
|
|
def check_process(request, rq_id):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
queue = django_rq.get_queue('default')
|
|
|
|
queue = django_rq.get_queue('default')
|
|
|
|
@ -24,40 +42,40 @@ def check_process(request, rq_id):
|
|
|
|
|
|
|
|
|
|
|
|
if rq_job is not None:
|
|
|
|
if rq_job is not None:
|
|
|
|
if rq_job.is_queued or rq_job.is_started:
|
|
|
|
if rq_job.is_queued or rq_job.is_started:
|
|
|
|
return JsonResponse({"status": rq_job.get_status()})
|
|
|
|
return Response({"status": rq_job.get_status()})
|
|
|
|
elif rq_job.is_finished:
|
|
|
|
elif rq_job.is_finished:
|
|
|
|
return JsonResponse({"status": rq_job.get_status()})
|
|
|
|
return Response({"status": rq_job.get_status()})
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
return JsonResponse({"status": rq_job.get_status(), "stderr": rq_job.exc_info})
|
|
|
|
return Response({"status": rq_job.get_status(), "stderr": rq_job.exc_info})
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
return JsonResponse({"status": "unknown"})
|
|
|
|
return Response({"status": "unknown"})
|
|
|
|
except Exception as ex:
|
|
|
|
except Exception as ex:
|
|
|
|
slogger.glob.error("error occurred during checking repository request with rq id {}".format(rq_id), exc_info=True)
|
|
|
|
slogger.glob.error("error occurred during checking repository request with rq id {}".format(rq_id), exc_info=True)
|
|
|
|
return HttpResponseBadRequest(str(ex))
|
|
|
|
return HttpResponseBadRequest(str(ex))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
@_legacy_api_view(['POST'])
|
|
|
|
@permission_required(perm=['engine.task.create'],
|
|
|
|
@permission_required(perm=['engine.task.create'],
|
|
|
|
fn=objectgetter(models.Task, 'tid'), raise_exception=True)
|
|
|
|
fn=objectgetter(models.Task, 'tid'), raise_exception=True)
|
|
|
|
def create(request, tid):
|
|
|
|
def create(request: Request, tid):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
slogger.task[tid].info("create repository request")
|
|
|
|
slogger.task[tid].info("create repository request")
|
|
|
|
body = json.loads(request.body.decode('utf-8'))
|
|
|
|
body = request.data
|
|
|
|
path = body["path"]
|
|
|
|
path = body["path"]
|
|
|
|
export_format = body["format"]
|
|
|
|
export_format = body.get("format")
|
|
|
|
lfs = body["lfs"]
|
|
|
|
lfs = body["lfs"]
|
|
|
|
rq_id = "git.create.{}".format(tid)
|
|
|
|
rq_id = "git.create.{}".format(tid)
|
|
|
|
queue = django_rq.get_queue("default")
|
|
|
|
queue = django_rq.get_queue("default")
|
|
|
|
|
|
|
|
|
|
|
|
queue.enqueue_call(func = CVATGit.initial_create, args = (tid, path, export_format, lfs, request.user), job_id = rq_id)
|
|
|
|
queue.enqueue_call(func = CVATGit.initial_create, args = (tid, path, export_format, lfs, request.user), job_id = rq_id)
|
|
|
|
return JsonResponse({ "rq_id": rq_id })
|
|
|
|
return Response({ "rq_id": rq_id })
|
|
|
|
except Exception as ex:
|
|
|
|
except Exception as ex:
|
|
|
|
slogger.glob.error("error occurred during initial cloning repository request with rq id {}".format(rq_id), exc_info=True)
|
|
|
|
slogger.glob.error("error occurred during initial cloning repository request with rq id {}".format(rq_id), exc_info=True)
|
|
|
|
return HttpResponseBadRequest(str(ex))
|
|
|
|
return HttpResponseBadRequest(str(ex))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
@_legacy_api_view()
|
|
|
|
def push_repository(request, tid):
|
|
|
|
def push_repository(request: Request, tid):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
slogger.task[tid].info("push repository request")
|
|
|
|
slogger.task[tid].info("push repository request")
|
|
|
|
|
|
|
|
|
|
|
|
@ -65,7 +83,7 @@ def push_repository(request, tid):
|
|
|
|
queue = django_rq.get_queue('default')
|
|
|
|
queue = django_rq.get_queue('default')
|
|
|
|
queue.enqueue_call(func = CVATGit.push, args = (tid, request.user, request.scheme, request.get_host()), job_id = rq_id)
|
|
|
|
queue.enqueue_call(func = CVATGit.push, args = (tid, request.user, request.scheme, request.get_host()), job_id = rq_id)
|
|
|
|
|
|
|
|
|
|
|
|
return JsonResponse({ "rq_id": rq_id })
|
|
|
|
return Response({ "rq_id": rq_id })
|
|
|
|
except Exception as ex:
|
|
|
|
except Exception as ex:
|
|
|
|
with contextlib.suppress(Exception):
|
|
|
|
with contextlib.suppress(Exception):
|
|
|
|
slogger.task[tid].error("error occurred during pushing repository request",
|
|
|
|
slogger.task[tid].error("error occurred during pushing repository request",
|
|
|
|
@ -74,11 +92,11 @@ def push_repository(request, tid):
|
|
|
|
return HttpResponseBadRequest(str(ex))
|
|
|
|
return HttpResponseBadRequest(str(ex))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
@_legacy_api_view()
|
|
|
|
def get_repository(request, tid):
|
|
|
|
def get_repository(request: Request, tid):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
slogger.task[tid].info("get repository request")
|
|
|
|
slogger.task[tid].info("get repository request")
|
|
|
|
return JsonResponse(CVATGit.get(tid, request.user))
|
|
|
|
return Response(CVATGit.get(tid, request.user))
|
|
|
|
except Exception as ex:
|
|
|
|
except Exception as ex:
|
|
|
|
with contextlib.suppress(Exception):
|
|
|
|
with contextlib.suppress(Exception):
|
|
|
|
slogger.task[tid].error("error occurred during getting repository info request",
|
|
|
|
slogger.task[tid].error("error occurred during getting repository info request",
|
|
|
|
@ -86,12 +104,12 @@ def get_repository(request, tid):
|
|
|
|
|
|
|
|
|
|
|
|
return HttpResponseBadRequest(str(ex))
|
|
|
|
return HttpResponseBadRequest(str(ex))
|
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
@_legacy_api_view(['PATCH'])
|
|
|
|
@permission_required(perm=['engine.task.access'],
|
|
|
|
@permission_required(perm=['engine.task.access'],
|
|
|
|
fn=objectgetter(models.Task, 'tid'), raise_exception=True)
|
|
|
|
fn=objectgetter(models.Task, 'tid'), raise_exception=True)
|
|
|
|
def update_git_repo(request, tid):
|
|
|
|
def update_git_repo(request: Request, tid):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
body = json.loads(request.body.decode('utf-8'))
|
|
|
|
body = request.data
|
|
|
|
req_type = body["type"]
|
|
|
|
req_type = body["type"]
|
|
|
|
value = body["value"]
|
|
|
|
value = body["value"]
|
|
|
|
git_data_obj = GitData.objects.filter(task_id=tid)[0]
|
|
|
|
git_data_obj = GitData.objects.filter(task_id=tid)[0]
|
|
|
|
@ -114,7 +132,7 @@ def update_git_repo(request, tid):
|
|
|
|
return HttpResponseBadRequest(str(ex))
|
|
|
|
return HttpResponseBadRequest(str(ex))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
@_legacy_api_view()
|
|
|
|
def get_meta_info(request):
|
|
|
|
def get_meta_info(request):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
db_git_records = GitData.objects.all()
|
|
|
|
db_git_records = GitData.objects.all()
|
|
|
|
@ -122,7 +140,7 @@ def get_meta_info(request):
|
|
|
|
for db_git in db_git_records:
|
|
|
|
for db_git in db_git_records:
|
|
|
|
response[db_git.task_id] = db_git.status
|
|
|
|
response[db_git.task_id] = db_git.status
|
|
|
|
|
|
|
|
|
|
|
|
return JsonResponse(response, safe = False)
|
|
|
|
return Response(response)
|
|
|
|
except Exception as ex:
|
|
|
|
except Exception as ex:
|
|
|
|
slogger.glob.exception("error occurred during get meta request", exc_info = True)
|
|
|
|
slogger.glob.exception("error occurred during get meta request", exc_info = True)
|
|
|
|
return HttpResponseBadRequest(str(ex))
|
|
|
|
return HttpResponseBadRequest(str(ex))
|
|
|
|
|