fix: 아키텍처 리뷰 이슈 3건 수정
- 명령줄 토큰 노출 제거 — exec.Command에서 -token 인자 제거, 환경변수(A301_TOKEN)만 사용 - redeemTicket 재시도 추가 — 3회 exponential backoff, 4xx는 즉시 실패 - 임시 추출 디렉토리 defer os.RemoveAll 추가 — 중복 정리 코드 제거 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
21
protocol.go
21
protocol.go
@@ -156,8 +156,24 @@ func fetchServerInfo() (*downloadInfo, error) {
|
||||
}
|
||||
|
||||
// redeemTicket exchanges a one-time launch ticket for a fresh JWT access token.
|
||||
// Retries up to 3 times with exponential backoff on transient errors.
|
||||
func redeemTicket(ticket string) (string, error) {
|
||||
return redeemTicketFrom(redeemTicketURL, ticket)
|
||||
const maxRetries = 3
|
||||
var lastErr error
|
||||
for i := range maxRetries {
|
||||
token, err := redeemTicketFrom(redeemTicketURL, ticket)
|
||||
if err == nil {
|
||||
return token, nil
|
||||
}
|
||||
lastErr = err
|
||||
// HTTP 4xx errors should not be retried
|
||||
var noRetry *errNoRetry
|
||||
if errors.As(err, &noRetry) {
|
||||
return "", err
|
||||
}
|
||||
time.Sleep(time.Duration(1<<i) * time.Second)
|
||||
}
|
||||
return "", fmt.Errorf("인증 실패 (%d회 재시도): %w", maxRetries, lastErr)
|
||||
}
|
||||
|
||||
func redeemTicketFrom(url, ticket string) (string, error) {
|
||||
@@ -173,6 +189,9 @@ func redeemTicketFrom(url, ticket string) (string, error) {
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode >= 400 && resp.StatusCode < 500 {
|
||||
return "", &errNoRetry{fmt.Errorf("런처 인증에 실패했습니다 (HTTP %d)", resp.StatusCode)}
|
||||
}
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return "", fmt.Errorf("런처 인증에 실패했습니다 (HTTP %d)", resp.StatusCode)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user