MCPcopy Create free account
hub / github.com/Noumena-Network/code / readTokenFromWellKnownFile

Function readTokenFromWellKnownFile

src/utils/authFileDescriptor.ts:62–87  ·  view source on GitHub ↗
(
  path: string,
  tokenName: string,
)

Source from the content-addressed store, hash-verified

60 * else — treated as "no fallback", not an error.
61 */
62export function readTokenFromWellKnownFile(
63 path: string,
64 tokenName: string,
65): string | null {
66 try {
67 const fsOps = getFsImplementation()
68 // eslint-disable-next-line custom-rules/no-sync-fs -- fallback read for CCR subprocess path, one-shot at startup, caller is sync
69 const token = fsOps.readFileSync(path, { encoding: 'utf8' }).trim()
70 if (!token) {
71 return null
72 }
73 logForDebugging(`Read ${tokenName} from well-known file ${path}`)
74 return token
75 } catch (error) {
76 // ENOENT is the expected outcome outside CCR — stay silent. Anything
77 // else (EACCES from perm misconfig, etc.) is worth surfacing in the
78 // debug log so subprocess auth failures aren't mysterious.
79 if (!isENOENT(error)) {
80 logForDebugging(
81 `Failed to read ${tokenName} from ${path}: ${errorMessage(error)}`,
82 { level: 'debug' },
83 )
84 }
85 return null
86 }
87}
88
89/**
90 * Shared FD-or-well-known-file credential reader.

Callers 2

getCredentialFromFdFunction · 0.85

Calls 4

getFsImplementationFunction · 0.85
isENOENTFunction · 0.85
logForDebuggingFunction · 0.70
errorMessageFunction · 0.70

Tested by

no test coverage detected