mirror of https://github.com/jumpserver/jumpserver
[Update] 增加修改system user auth 的api
parent
9162f4a226
commit
9ffb079c8f
|
@ -40,23 +40,22 @@ class SystemUserViewSet(BulkModelViewSet):
|
||||||
permission_classes = (IsSuperUserOrAppUser,)
|
permission_classes = (IsSuperUserOrAppUser,)
|
||||||
|
|
||||||
|
|
||||||
class SystemUserAuthInfoApi(generics.RetrieveAPIView):
|
class SystemUserAuthInfoApi(generics.RetrieveUpdateAPIView):
|
||||||
"""
|
"""
|
||||||
Get system user auth info
|
Get system user auth info
|
||||||
"""
|
"""
|
||||||
queryset = SystemUser.objects.all()
|
queryset = SystemUser.objects.all()
|
||||||
permission_classes = (IsSuperUserOrAppUser,)
|
permission_classes = (IsSuperUserOrAppUser,)
|
||||||
|
serializer_class = serializers.SystemUserAuthSerializer
|
||||||
|
|
||||||
def retrieve(self, request, *args, **kwargs):
|
def update(self, request, *args, **kwargs):
|
||||||
system_user = self.get_object()
|
password = request.data.pop("password", None)
|
||||||
data = {
|
private_key = request.data.pop("private_key", None)
|
||||||
'id': system_user.id,
|
instance = self.get_object()
|
||||||
'name': system_user.name,
|
|
||||||
'username': system_user.username,
|
if password or private_key:
|
||||||
'password': system_user.password,
|
instance.set_auth(password=password, private_key=private_key)
|
||||||
'private_key': system_user.private_key,
|
return super().update(request, *args, **kwargs)
|
||||||
}
|
|
||||||
return Response(data)
|
|
||||||
|
|
||||||
|
|
||||||
class SystemUserPushApi(generics.RetrieveAPIView):
|
class SystemUserPushApi(generics.RetrieveAPIView):
|
||||||
|
|
|
@ -36,6 +36,21 @@ class SystemUserSerializer(serializers.ModelSerializer):
|
||||||
return len(obj.assets)
|
return len(obj.assets)
|
||||||
|
|
||||||
|
|
||||||
|
class SystemUserAuthSerializer(serializers.ModelSerializer):
|
||||||
|
"""
|
||||||
|
系统用户认证信息
|
||||||
|
"""
|
||||||
|
password = serializers.CharField(max_length=1024)
|
||||||
|
private_key = serializers.CharField(max_length=4096)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = SystemUser
|
||||||
|
fields = [
|
||||||
|
"id", "name", "username", "protocol",
|
||||||
|
"password", "private_key",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
class AssetSystemUserSerializer(serializers.ModelSerializer):
|
class AssetSystemUserSerializer(serializers.ModelSerializer):
|
||||||
"""
|
"""
|
||||||
查看授权的资产系统用户的数据结构,这个和AssetSerializer不同,字段少
|
查看授权的资产系统用户的数据结构,这个和AssetSerializer不同,字段少
|
||||||
|
|
|
@ -27,7 +27,14 @@ sys.path.append(PROJECT_DIR)
|
||||||
try:
|
try:
|
||||||
from config import config as CONFIG
|
from config import config as CONFIG
|
||||||
except ImportError:
|
except ImportError:
|
||||||
CONFIG = type('_', (), {'__getattr__': lambda arg1, arg2: None})()
|
msg = """
|
||||||
|
|
||||||
|
Error: No config file found.
|
||||||
|
|
||||||
|
You can run `cp config_example.py config.py`, and edit it.
|
||||||
|
"""
|
||||||
|
raise ImportError(msg)
|
||||||
|
# CONFIG = type('_', (), {'__getattr__': lambda arg1, arg2: None})()
|
||||||
|
|
||||||
# Quick-start development settings - unsuitable for production
|
# Quick-start development settings - unsuitable for production
|
||||||
# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/
|
# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/
|
||||||
|
@ -177,7 +184,7 @@ LOGGING = {
|
||||||
'level': 'DEBUG',
|
'level': 'DEBUG',
|
||||||
'class': 'logging.FileHandler',
|
'class': 'logging.FileHandler',
|
||||||
'formatter': 'main',
|
'formatter': 'main',
|
||||||
'filename': os.path.join(CONFIG.LOG_DIR, 'jumpserver.log')
|
'filename': os.path.join(PROJECT_DIR, 'logs', 'jumpserver.log')
|
||||||
},
|
},
|
||||||
'ansible_logs': {
|
'ansible_logs': {
|
||||||
'level': 'DEBUG',
|
'level': 'DEBUG',
|
||||||
|
|
Loading…
Reference in New Issue