2019-09-12 10:48:31 +00:00
|
|
|
const secrets = new Set<string>();
|
|
|
|
|
2020-05-16 10:35:41 +00:00
|
|
|
export const redactedFields = [
|
|
|
|
'authorization',
|
|
|
|
'token',
|
|
|
|
'githubAppKey',
|
|
|
|
'npmToken',
|
|
|
|
'npmrc',
|
|
|
|
'yarnrc',
|
|
|
|
'privateKey',
|
|
|
|
'gitPrivateKey',
|
|
|
|
'forkToken',
|
|
|
|
'password',
|
|
|
|
];
|
|
|
|
|
2019-11-24 07:43:24 +00:00
|
|
|
export function sanitize(input: string): string {
|
2020-03-17 11:15:22 +00:00
|
|
|
if (!input) {
|
|
|
|
return input;
|
|
|
|
}
|
2019-09-12 10:48:31 +00:00
|
|
|
let output: string = input;
|
2020-04-12 16:09:36 +00:00
|
|
|
secrets.forEach((secret) => {
|
2019-09-12 10:48:31 +00:00
|
|
|
while (output.includes(secret)) {
|
|
|
|
output = output.replace(secret, '**redacted**');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
2019-11-24 07:43:24 +00:00
|
|
|
export function add(secret: string): void {
|
2019-09-12 10:48:31 +00:00
|
|
|
secrets.add(secret);
|
2020-08-24 13:43:58 +00:00
|
|
|
secrets.add(secret?.replace('x-access-token:', '')); // GitHub App tokens
|
2019-09-12 10:48:31 +00:00
|
|
|
}
|
|
|
|
|
2019-11-24 07:43:24 +00:00
|
|
|
export function clear(): void {
|
2019-09-12 10:48:31 +00:00
|
|
|
secrets.clear();
|
|
|
|
}
|