* Create a short-lived Coder API token for deployment endpoints.
(tokenName: string)
| 497 | * Create a short-lived Coder API token for deployment endpoints. |
| 498 | */ |
| 499 | private async createApiSession(tokenName: string): Promise<CoderApiSession> { |
| 500 | using tokenProc = execFileAsync( |
| 501 | "coder", |
| 502 | ["tokens", "create", "--lifetime", "5m", "--name", tokenName], |
| 503 | { timeoutMs: 30_000 } |
| 504 | ); |
| 505 | const { stdout: token } = await tokenProc.result; |
| 506 | const trimmed = token.trim(); |
| 507 | |
| 508 | return { |
| 509 | token: trimmed, |
| 510 | dispose: async () => { |
| 511 | try { |
| 512 | using deleteProc = execFileAsync("coder", ["tokens", "delete", tokenName], { |
| 513 | timeoutMs: 30_000, |
| 514 | }); |
| 515 | await deleteProc.result; |
| 516 | } catch { |
| 517 | // Best-effort cleanup; token will expire in 5 minutes anyway. |
| 518 | log.debug("Failed to delete temporary Coder API token", { tokenName }); |
| 519 | } |
| 520 | }, |
| 521 | }; |
| 522 | } |
| 523 | |
| 524 | private async withApiSession<T>( |
| 525 | tokenName: string, |
no test coverage detected