MCPcopy Index your code
hub / github.com/coder/mux / getWhoamiData

Method getWhoamiData

src/node/services/coderService.ts:597–622  ·  view source on GitHub ↗
(options?: {
    useCache?: boolean;
    signal?: AbortSignal;
  })

Source from the content-addressed store, hash-verified

595 // Preserve the old behavior: explicit whoami checks should hit the CLI even if cached.
596 // The cache only exists so later URL lookups can reuse the last whoami response.
597 private async getWhoamiData(options?: {
598 useCache?: boolean;
599 signal?: AbortSignal;
600 }): Promise<CoderWhoamiData> {
601 if (options?.useCache && this.cachedWhoami) {
602 return this.cachedWhoami;
603 }
604
605 const stdout = await this.runCoderJsonCommand(["whoami", "--output=json"], {
606 timeoutMs: 10_000,
607 signal: options?.signal,
608 });
609
610 const data = JSON.parse(stdout) as Array<Partial<CoderWhoamiData>>;
611 if (!data[0]?.url) {
612 throw new Error("Could not determine Coder deployment URL from `coder whoami`");
613 }
614
615 this.cachedWhoami = {
616 url: data[0].url,
617 username: data[0].username,
618 id: data[0].id,
619 };
620
621 return this.cachedWhoami;
622 }
623
624 /**
625 * Get the Coder deployment URL via `coder whoami`.

Callers 3

getCoderInfoMethod · 0.95
getDeploymentUrlMethod · 0.95

Calls 2

runCoderJsonCommandMethod · 0.95
parseMethod · 0.45

Tested by

no test coverage detected