Ansible ssh키 암복호화기능추가
All checks were successful
Build And Test / build-and-push (push) Successful in 2m49s
All checks were successful
Build And Test / build-and-push (push) Successful in 2m49s
This commit is contained in:
@ -1,3 +1,4 @@
|
||||
# views.py
|
||||
from rest_framework.views import APIView
|
||||
from rest_framework.response import Response
|
||||
from rest_framework import status
|
||||
@ -52,12 +53,13 @@ class SSHKeyUploadView(APIView):
|
||||
|
||||
user = request.user
|
||||
try:
|
||||
# ✅ 모델 메서드로 암호화 저장 처리
|
||||
user.save_private_key(private_key)
|
||||
user.encrypted_private_key_name = key_name
|
||||
user.save(update_fields=["encrypted_private_key", "encrypted_private_key_name"])
|
||||
return Response({"message": "SSH key 저장 완료."})
|
||||
return Response({"message": "SSH key 저장 완료."}, status=201)
|
||||
except Exception as e:
|
||||
return Response({"error": str(e)}, status=500)
|
||||
return Response({"error": f"암호화 또는 저장 실패: {str(e)}"}, status=500)
|
||||
|
||||
def delete(self, request):
|
||||
user = request.user
|
||||
@ -80,7 +82,6 @@ class SSHKeyInfoView(APIView):
|
||||
})
|
||||
|
||||
|
||||
# ✅ 실제 암호화된 키를 반환하는 API
|
||||
class SSHKeyRetrieveView(APIView):
|
||||
permission_classes = [IsAuthenticated]
|
||||
|
||||
@ -88,4 +89,10 @@ class SSHKeyRetrieveView(APIView):
|
||||
user = request.user
|
||||
if not user.encrypted_private_key:
|
||||
return Response({"error": "SSH 키가 등록되어 있지 않습니다."}, status=404)
|
||||
return Response({"ssh_key": user.encrypted_private_key})
|
||||
|
||||
try:
|
||||
# ✅ 모델 메서드로 복호화 처리
|
||||
decrypted_key = user.decrypt_private_key()
|
||||
return Response({"ssh_key": decrypted_key})
|
||||
except Exception as e:
|
||||
return Response({"error": f"복호화 실패: {str(e)}"}, status=500)
|
||||
|
Reference in New Issue
Block a user