MCPcopy
hub / github.com/coder/mux / createApiSession

Method createApiSession

src/node/services/coderService.ts:499–522  ·  view source on GitHub ↗

* Create a short-lived Coder API token for deployment endpoints.

(tokenName: string)

Source from the content-addressed store, hash-verified

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,

Callers 2

withApiSessionMethod · 0.95

Calls 2

execFileAsyncFunction · 0.90
debugMethod · 0.80

Tested by

no test coverage detected