Commit 82b9c251 authored by ibuler's avatar ibuler

[Update] Merge it

parents 66b8e59a d563a11a
......@@ -44,4 +44,4 @@ class GatewayTestConnectionApi(SingleObjectMixin, APIView):
if ok:
return Response("ok")
else:
return Response({"failed": e}, status=404)
return Response({"error": e}, status=400)
......@@ -38,6 +38,9 @@ class AssetUserQuerySet(list):
if len(v) == 0:
return self
if k.find("__in") >= 0:
_k = k.split('__')[0]
in_kwargs[_k] = v
else:
in_kwargs[k] = v
for k in in_kwargs:
kwargs.pop(k)
......@@ -45,17 +48,16 @@ class AssetUserQuerySet(list):
if len(in_kwargs) == 0:
return self
for i in self:
matched = True
matched = False
for k, v in in_kwargs.items():
key = k.split('__')[0]
attr = getattr(i, key, None)
attr = getattr(i, k, None)
# 如果属性或者value中是uuid,则转换成string
if isinstance(v[0], uuid.UUID):
v = [str(i) for i in v]
if isinstance(attr, uuid.UUID):
attr = str(attr)
if attr not in v:
matched = False
if v in attr:
matched = True
if matched:
queryset.append(i)
return AssetUserQuerySet(queryset)
......
......@@ -3,9 +3,9 @@
import uuid
import random
import re
import paramiko
from django.db import models
from django.utils.translation import ugettext_lazy as _
......@@ -63,6 +63,9 @@ class Gateway(AssetUser):
def test_connective(self, local_port=None):
if local_port is None:
local_port = self.port
if not re.match(r'\w+$', self.password):
return False, _("Password should not contain special characters")
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
proxy = paramiko.SSHClient()
......
......@@ -139,7 +139,7 @@ $(document).ready(function(){
method: "POST",
body: JSON.stringify({'port': parseInt(data.port)}),
success_message: "{% trans 'Can be connected' %}",
fail_message: "{% trans 'The connection fails' %}"
{#fail_message: "{% trans 'The connection fails' %}"#}
})
});
</script>
......
This diff is collapsed.
......@@ -3,6 +3,7 @@
from rest_framework import viewsets, generics
from rest_framework import status
from rest_framework.response import Response
from django.conf import settings
from common.permissions import IsSuperUser, WithBootstrapToken
......@@ -17,6 +18,9 @@ class TerminalViewSet(viewsets.ModelViewSet):
queryset = Terminal.objects.filter(is_deleted=False)
serializer_class = serializers.TerminalSerializer
permission_classes = [IsSuperUser]
http_method_names = [
'get', 'put', 'patch', 'delete', 'head', 'options', 'trace'
]
class TerminalRegistrationApi(generics.CreateAPIView):
......@@ -29,6 +33,9 @@ class TerminalRegistrationApi(generics.CreateAPIView):
serializer = serializers.TerminalSerializer(
data=data, context={'request': request}
)
if not settings.SECURITY_SERVICE_ACCOUNT_REGISTRATION:
data = {"error": "service account registration disabled"}
return Response(data=data, status=status.HTTP_400_BAD_REQUEST)
serializer.is_valid(raise_exception=True)
terminal = serializer.save()
sa_serializer = serializer.sa_serializer_class(instance=terminal.user)
......
......@@ -28,9 +28,6 @@ class TerminalSerializer(serializers.ModelSerializer):
valid = super().is_valid(raise_exception=raise_exception)
if not valid:
return valid
if not settings.SECURITY_SERVICE_ACCOUNT_REGISTRATION:
error = {"error": "service account registration disabled"}
raise serializers.ValidationError(error)
data = {'name': self.validated_data.get('name')}
kwargs = {'data': data}
if self.instance and self.instance.user:
......
......@@ -114,7 +114,7 @@ def check_pid(pid):
""" Check For the existence of a unix pid. """
try:
os.kill(pid, 0)
except OSError:
except (OSError, ProcessLookupError):
return False
else:
return True
......@@ -231,6 +231,9 @@ def get_start_worker_kwargs(queue, num):
if os.getuid() == 0:
os.environ.setdefault('C_FORCE_ROOT', '1')
server_hostname = os.environ.get("SERVER_HOSTNAME")
if not server_hostname:
server_hostname = '%h'
cmd = [
'celery', 'worker',
......@@ -238,7 +241,7 @@ def get_start_worker_kwargs(queue, num):
'-l', 'INFO',
'-c', str(num),
'-Q', queue,
'-n', '{}@%h'.format(queue)
'-n', '{}@{}'.format(queue, server_hostname)
]
return {"cmd": cmd, "cwd": APPS_DIR}
......@@ -437,6 +440,12 @@ def stop_service(srv, sig=15):
print("Stop service: {}".format(s), end='')
pid = get_pid(s)
os.kill(pid, sig)
with LOCK:
process = processes.pop(s, None)
if process is None:
print("\033[31m No process found\033[0m")
continue
process.wait(1)
for i in range(STOP_TIMEOUT):
if i == STOP_TIMEOUT - 1:
print("\033[31m Error\033[0m")
......@@ -447,9 +456,6 @@ def stop_service(srv, sig=15):
time.sleep(1)
continue
with LOCK:
processes.pop(s, None)
if srv == "all":
stop_daemon_service()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment