Skip to content

Commit a027057

Browse files
Trim spaces and newlines from secret files (#696)
Purely a UX change for admins, since most text editors append a newline to written files. * Trim spaces and newlines from secret files * Extract only the first line from secret files. --------- Signed-off-by: Rory& <[email protected]> Co-authored-by: gnuxie <[email protected]>
1 parent 420aaff commit a027057

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/config.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -352,12 +352,11 @@ export function configRead(): IConfig {
352352
"--pantalaimon-password-path"
353353
);
354354
if (explicitAccessTokenPath !== undefined) {
355-
config.accessToken = fs.readFileSync(explicitAccessTokenPath, "utf8");
355+
config.accessToken = readSecretFromPath(explicitAccessTokenPath);
356356
}
357357
if (explicitPantalaimonPasswordPath) {
358-
config.pantalaimon.password = fs.readFileSync(
359-
explicitPantalaimonPasswordPath,
360-
"utf8"
358+
config.pantalaimon.password = readSecretFromPath(
359+
explicitPantalaimonPasswordPath
361360
);
362361
}
363362
return config;
@@ -484,6 +483,15 @@ function getCommandLineOption(
484483
throw new Error(`No value provided for ${optionName}`);
485484
}
486485

486+
function readSecretFromPath(path: string): string {
487+
// extract only the first line.
488+
const secret = fs.readFileSync(path, "utf8").match(/^[^\r\n]*/)?.[0];
489+
if (!secret) {
490+
throw new TypeError(`There is no secret present in the file at ${path}`);
491+
}
492+
return secret;
493+
}
494+
487495
type UnknownPropertyPaths = string[];
488496

489497
export function getUnknownPropertiesHelper(

0 commit comments

Comments
 (0)