v0.0.36 | Upbit API 자격증명 관리 기능 추가
All checks were successful
Build And Test / build-and-push (push) Successful in 2m31s
All checks were successful
Build And Test / build-and-push (push) Successful in 2m31s
- CustomUser 모델에 Upbit access/secret key 암호화 필드 추가 - UpbitCredentialsView: 자격증명 저장/조회(마스킹)/삭제 API - UpbitSecretKeyView: 복호화된 키 조회 API (내부 서비스 호출용) - 마이그레이션 파일 추가 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@ -141,6 +141,10 @@ class CustomUser(AbstractBaseUser, PermissionsMixin):
|
||||
social_id = models.CharField(max_length=255, blank=True, null=True, verbose_name="소셜 고유 ID")
|
||||
profile_image = models.URLField(max_length=500, blank=True, null=True, verbose_name="프로필 이미지 URL")
|
||||
|
||||
# 📈 Upbit API 자격증명 필드
|
||||
encrypted_upbit_access_key = models.BinaryField(blank=True, null=True, verbose_name="Upbit Access Key (암호화)")
|
||||
encrypted_upbit_secret_key = models.BinaryField(blank=True, null=True, verbose_name="Upbit Secret Key (암호화)")
|
||||
|
||||
# ☁️ NHN Cloud 자격증명 필드
|
||||
nhn_tenant_id = models.CharField(max_length=64, blank=True, null=True, verbose_name="NHN Cloud Tenant ID")
|
||||
nhn_username = models.EmailField(blank=True, null=True, verbose_name="NHN Cloud Username")
|
||||
@ -218,6 +222,38 @@ class CustomUser(AbstractBaseUser, PermissionsMixin):
|
||||
'nhn_tenant_id', 'nhn_username', 'encrypted_nhn_api_password', 'nhn_storage_account'
|
||||
])
|
||||
|
||||
# 📈 Upbit API 키 암복호화
|
||||
def encrypt_upbit_key(self, key: str) -> bytes:
|
||||
"""Upbit API 키 암호화"""
|
||||
cipher = Fernet(self.get_encryption_key())
|
||||
return cipher.encrypt(key.encode())
|
||||
|
||||
def decrypt_upbit_access_key(self) -> str:
|
||||
"""Upbit Access Key 복호화"""
|
||||
if self.encrypted_upbit_access_key:
|
||||
cipher = Fernet(self.get_encryption_key())
|
||||
return cipher.decrypt(self.encrypted_upbit_access_key).decode()
|
||||
return ""
|
||||
|
||||
def decrypt_upbit_secret_key(self) -> str:
|
||||
"""Upbit Secret Key 복호화"""
|
||||
if self.encrypted_upbit_secret_key:
|
||||
cipher = Fernet(self.get_encryption_key())
|
||||
return cipher.decrypt(self.encrypted_upbit_secret_key).decode()
|
||||
return ""
|
||||
|
||||
def save_upbit_credentials(self, access_key: str, secret_key: str):
|
||||
"""Upbit API 자격증명 저장"""
|
||||
self.encrypted_upbit_access_key = self.encrypt_upbit_key(access_key)
|
||||
self.encrypted_upbit_secret_key = self.encrypt_upbit_key(secret_key)
|
||||
self.save(update_fields=['encrypted_upbit_access_key', 'encrypted_upbit_secret_key'])
|
||||
|
||||
def clear_upbit_credentials(self):
|
||||
"""Upbit API 자격증명 삭제"""
|
||||
self.encrypted_upbit_access_key = None
|
||||
self.encrypted_upbit_secret_key = None
|
||||
self.save(update_fields=['encrypted_upbit_access_key', 'encrypted_upbit_secret_key'])
|
||||
|
||||
|
||||
# ============================================
|
||||
# NHN Cloud 프로젝트 (멀티 프로젝트 지원)
|
||||
|
||||
Reference in New Issue
Block a user