renovate/lib/util/sanitize.ts

37 lines
695 B
TypeScript
Raw Normal View History

2019-09-12 10:48:31 +00:00
const secrets = new Set<string>();
export const redactedFields = [
'authorization',
'token',
'githubAppKey',
'npmToken',
'npmrc',
'yarnrc',
'privateKey',
'gitPrivateKey',
'forkToken',
'password',
];
export function sanitize(input: string): string {
if (!input) {
return input;
}
2019-09-12 10:48:31 +00:00
let output: string = input;
secrets.forEach((secret) => {
2019-09-12 10:48:31 +00:00
while (output.includes(secret)) {
output = output.replace(secret, '**redacted**');
}
});
return output;
}
export function add(secret: string): void {
2019-09-12 10:48:31 +00:00
secrets.add(secret);
secrets.add(secret?.replace('x-access-token:', '')); // GitHub App tokens
2019-09-12 10:48:31 +00:00
}
export function clear(): void {
2019-09-12 10:48:31 +00:00
secrets.clear();
}