Update 2025-12-17 20:47:56
This commit is contained in:
@@ -4,6 +4,7 @@ from datetime import datetime, timedelta
|
||||
from app.api.auth import get_current_user
|
||||
from app.schemas.auth import CurrentUser
|
||||
from app.services.temp_ssh_password_service import temp_ssh_password_manager
|
||||
from app.config import settings
|
||||
import os
|
||||
|
||||
router = APIRouter()
|
||||
@@ -21,15 +22,38 @@ async def get_ssh_credentials(current_user: CurrentUser = Depends(get_current_us
|
||||
Returns:
|
||||
SSH 연결 정보 및 임시 비밀번호
|
||||
"""
|
||||
# 1. 정적 자격증명 확인 (개발 환경 또는 정적 비밀번호 사용 시)
|
||||
if settings.SSH_PASSWORD:
|
||||
ssh_host = settings.SSH_HOST or "api.mouse84.com"
|
||||
ssh_port = settings.SSH_PORT
|
||||
ssh_username = settings.SSH_USERNAME or current_user.username
|
||||
|
||||
# 만료 시간 (24시간)
|
||||
expires_at = datetime.utcnow() + timedelta(hours=24)
|
||||
|
||||
return {
|
||||
"ssh_host": ssh_host,
|
||||
"ssh_port": ssh_port,
|
||||
"ssh_username": ssh_username,
|
||||
"ssh_password": settings.SSH_PASSWORD,
|
||||
"expires_at": expires_at.isoformat(),
|
||||
"expires_in_seconds": 86400
|
||||
}
|
||||
|
||||
# 2. 임시 비밀번호 생성 (기본 동작)
|
||||
|
||||
# .env 설정을 우선 사용 (username이 지정된 경우 해당 계정으로 임시 비밀번호 생성)
|
||||
target_username = settings.SSH_USERNAME or current_user.username
|
||||
|
||||
# 임시 비밀번호 생성 (1시간 유효)
|
||||
temp_password = temp_ssh_password_manager.generate_password(
|
||||
username=current_user.username,
|
||||
username=target_username,
|
||||
validity_hours=1
|
||||
)
|
||||
|
||||
# SSH 서버 정보 (외부 접속용)
|
||||
ssh_host = os.getenv("SSH_HOST", "api.mouse84.com") # 외부 DDNS
|
||||
ssh_port = int(os.getenv("SSH_PORT", "54054")) # 외부 포트 (내부 22로 포워딩)
|
||||
# SSH 서버 정보 (설정값 우선)
|
||||
ssh_host = settings.SSH_HOST or "api.mouse84.com"
|
||||
ssh_port = settings.SSH_PORT or 54054
|
||||
|
||||
# 만료 시간 계산
|
||||
expires_at = datetime.utcnow() + timedelta(hours=1)
|
||||
@@ -37,7 +61,7 @@ async def get_ssh_credentials(current_user: CurrentUser = Depends(get_current_us
|
||||
return {
|
||||
"ssh_host": ssh_host,
|
||||
"ssh_port": ssh_port,
|
||||
"ssh_username": current_user.username,
|
||||
"ssh_username": target_username,
|
||||
"ssh_password": temp_password,
|
||||
"expires_at": expires_at.isoformat(),
|
||||
"expires_in_seconds": 3600
|
||||
|
||||
Reference in New Issue
Block a user