[Update] 增加修改system user auth 的api

pull/1068/head
ibuler 2018-03-09 12:53:08 +08:00
parent 9162f4a226
commit 9ffb079c8f
3 changed files with 34 additions and 13 deletions

View File

@ -40,23 +40,22 @@ class SystemUserViewSet(BulkModelViewSet):
permission_classes = (IsSuperUserOrAppUser,)
class SystemUserAuthInfoApi(generics.RetrieveAPIView):
class SystemUserAuthInfoApi(generics.RetrieveUpdateAPIView):
"""
Get system user auth info
"""
queryset = SystemUser.objects.all()
permission_classes = (IsSuperUserOrAppUser,)
serializer_class = serializers.SystemUserAuthSerializer
def retrieve(self, request, *args, **kwargs):
system_user = self.get_object()
data = {
'id': system_user.id,
'name': system_user.name,
'username': system_user.username,
'password': system_user.password,
'private_key': system_user.private_key,
}
return Response(data)
def update(self, request, *args, **kwargs):
password = request.data.pop("password", None)
private_key = request.data.pop("private_key", None)
instance = self.get_object()
if password or private_key:
instance.set_auth(password=password, private_key=private_key)
return super().update(request, *args, **kwargs)
class SystemUserPushApi(generics.RetrieveAPIView):

View File

@ -36,6 +36,21 @@ class SystemUserSerializer(serializers.ModelSerializer):
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):
"""
查看授权的资产系统用户的数据结构这个和AssetSerializer不同字段少

View File

@ -27,7 +27,14 @@ sys.path.append(PROJECT_DIR)
try:
from config import config as CONFIG
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
# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/
@ -177,7 +184,7 @@ LOGGING = {
'level': 'DEBUG',
'class': 'logging.FileHandler',
'formatter': 'main',
'filename': os.path.join(CONFIG.LOG_DIR, 'jumpserver.log')
'filename': os.path.join(PROJECT_DIR, 'logs', 'jumpserver.log')
},
'ansible_logs': {
'level': 'DEBUG',