MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / readAuthFile

Function readAuthFile

packages/plugins/file-secrets/src/index.ts:108–128  ·  view source on GitHub ↗
(
  filePath: string,
)

Source from the content-addressed store, hash-verified

106 new StorageError({ message, cause });
107
108const readAuthFile = (
109 filePath: string,
110): Effect.Effect<Record<string, string>, StorageError | AuthFileDecodeError> => {
111 if (!fs.existsSync(filePath)) return Effect.succeed({});
112 return Effect.try({
113 try: () => fs.readFileSync(filePath, "utf-8"),
114 catch: toStorageError("Failed to read auth file"),
115 }).pipe(
116 Effect.catchIf(
117 (error: StorageError) => isFileNotFoundCause(error.cause),
118 () => Effect.succeed(""),
119 ),
120 Effect.flatMap((raw: string) =>
121 raw === ""
122 ? Effect.succeed<Record<string, string>>({})
123 : decodeFlatAuthFile(raw).pipe(
124 Effect.mapError((cause) => new AuthFileDecodeError({ filePath, cause })),
125 ),
126 ),
127 );
128};
129
130const readAll = (filePath: string): Effect.Effect<Record<string, string>, StorageError> =>
131 readAuthFile(filePath).pipe(

Callers 2

readAllFunction · 0.70
migrateLegacyAuthFileFunction · 0.70

Calls 2

isFileNotFoundCauseFunction · 0.85
toStorageErrorFunction · 0.70

Tested by

no test coverage detected