diff --git a/core/license.py b/core/license.py index 0188699..0251a75 100644 --- a/core/license.py +++ b/core/license.py @@ -41,7 +41,7 @@ _SIG_LEN = 8 # HMAC-SHA256 중 앞 8바이트 # TRIAL 에디션 키만 발급 가능 — 설치당 1회 제한으로 남용 방지 _TRIAL_MASTER_KEY = "477561524469415f545249414c5f4b65795f4e6f745f466f725f50726f647563" -TRIAL_DURATION_DAYS = 7 +TRIAL_DURATION_DAYS = int(os.getenv("TRIAL_DURATION_DAYS", "7")) # 환경변수로 조정 가능 # ── 에디션 정의 ──────────────────────────────────────────────────────────────── @@ -160,18 +160,25 @@ def generate_license_key( # ── 체험판 라이선스 생성 ──────────────────────────────────────────────────────── -def generate_trial_key(customer: str, license_id: Optional[str] = None) -> str: +def generate_trial_key(customer: str, license_id: Optional[str] = None, + days: Optional[int] = None) -> str: """ - 7일 무료 체험 라이선스 키 생성. + 체험 라이선스 키 생성. - 내장 Trial 마스터 키 사용 (GUARDIA_LICENSE_KEY 불필요) - - TRIAL 에디션 고정 (COMMUNITY 동일 제한) - - 만료: 생성 시점 + 7일 + - TRIAL 에디션 고정 + - 만료: 생성 시점 + days일 (기본: TRIAL_DURATION_DAYS) + + Args: + customer: 고객사/사용자명 + license_id: 라이선스 ID (None이면 자동 생성) + days: 체험 기간 (일). None이면 TRIAL_DURATION_DAYS 사용 Returns: "GRD-{base64url}" 형태의 체험 라이선스 키 """ - expires_at = datetime.now(timezone.utc) + timedelta(days=TRIAL_DURATION_DAYS) + trial_days = days if days is not None else TRIAL_DURATION_DAYS + expires_at = datetime.now(timezone.utc) + timedelta(days=trial_days) lid = license_id or f"TRL-{secrets.token_hex(6).upper()}" limits = EDITION_LIMITS[LicenseEdition.TRIAL] diff --git a/routers/license.py b/routers/license.py index 086b600..c8d4ecd 100644 --- a/routers/license.py +++ b/routers/license.py @@ -41,6 +41,7 @@ class ActivateRequest(BaseModel): class TrialRequest(BaseModel): customer: str = "GUARDiA 체험판" + days: int = 7 # 체험 기간 (일): 7 또는 30 class LicenseStatusOut(BaseModel): @@ -184,9 +185,10 @@ async def activate_trial_license( if existing: existing.is_active = False - # 체험 라이선스 생성 - trial_key = generate_trial_key(body.customer) - status = validate_license(trial_key) + # 체험 라이선스 생성 (days 파라미터 지원) + trial_days = max(1, min(body.days, 90)) # 최대 90일 제한 + trial_key = generate_trial_key(body.customer, days=trial_days) + status = validate_license(trial_key) record = LicenseRecord( license_key = trial_key,