Skip to content

Commit 724ae84

Browse files
committed
fixup! feat(ncu-config): add support for partially encrypted config files
1 parent ea20ccf commit 724ae84

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

lib/auth.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ async function auth(
105105
const { username, jenkins_token } = getMergedConfig();
106106
if (!username || !jenkins_token) {
107107
errorExit(
108-
'Get your Jenkins API token in https://ci.nodejs.org/me/configure ' +
108+
'Get your Jenkins API token in https://ci.nodejs.org/me/security ' +
109109
'and run the following command to add it to your ncu config: ' +
110-
'ncu-config --global set jenkins_token TOKEN'
110+
'ncu-config --global set -x jenkins_token'
111111
);
112112
};
113113
check(username, jenkins_token);
@@ -121,7 +121,7 @@ async function auth(
121121
'Get your HackerOne API token in ' +
122122
'https://docs.hackerone.com/organizations/api-tokens.html ' +
123123
'and run the following command to add it to your ncu config: ' +
124-
'ncu-config --global set h1_token TOKEN or ' +
124+
'ncu-config --global set -x h1_token or ' +
125125
'ncu-config --global set h1_username USERNAME'
126126
);
127127
};

lib/config.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ export function getNcurcPath() {
2020
}
2121

2222
let mergedConfig;
23-
export function getMergedConfig(dir, home) {
23+
export function getMergedConfig(dir, home, additional) {
2424
if (mergedConfig == null) {
2525
const globalConfig = getConfig(GLOBAL_CONFIG, home);
2626
const projectConfig = getConfig(PROJECT_CONFIG, dir);
2727
const localConfig = getConfig(LOCAL_CONFIG, dir);
28-
mergedConfig = Object.assign(globalConfig, projectConfig, localConfig);
28+
mergedConfig = Object.assign(globalConfig, projectConfig, localConfig, additional);
2929
}
3030
return mergedConfig;
3131
};
@@ -41,7 +41,7 @@ export async function encryptValue(input) {
4141
{
4242
captureStdout: true,
4343
ignoreFailure: false,
44-
spawnArgs: { input }
44+
input
4545
}
4646
);
4747
}
@@ -60,7 +60,11 @@ function addEncryptedPropertyGetter(target, key, input) {
6060
__proto__: null,
6161
configurable: true,
6262
get() {
63-
console.warn(`The config value for ${key} is encrypted, spawning gpg to decrypt it...`);
63+
// Using an error object to get a stack trace in debug mode.
64+
const warn = new Error(
65+
`The config value for ${key} is encrypted, spawning gpg to decrypt it...`
66+
);
67+
console.warn(setOwnProperty(warn, 'name', 'Warning'));
6468
const value = runSync(process.env.GPG_BIN || 'gpg', ['--decrypt'], { input });
6569
setOwnProperty(target, key, value);
6670
return value;

lib/session.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export default class Session {
1919
this.cli = cli;
2020
this.dir = dir;
2121
this.prid = prid;
22-
this.config = { ...getMergedConfig(this.dir), ...argv };
22+
this.config = getMergedConfig(this.dir, undefined, argv);
2323
this.gpgSign = argv?.['gpg-sign']
2424
? (argv['gpg-sign'] === true ? ['-S'] : ['-S', argv['gpg-sign']])
2525
: [];
@@ -126,7 +126,12 @@ export default class Session {
126126
writeJson(this.sessionPath, {
127127
state: STARTED,
128128
prid: this.prid,
129-
config: this.config
129+
// Filter out getters, those are likely encrypted data we don't need on the session.
130+
config: Object.entries(Object.getOwnPropertyDescriptors(this.config))
131+
.reduce((pv, [key, desc]) => {
132+
if (Object.hasOwn(desc, 'value')) pv[key] = desc.value;
133+
return pv;
134+
}, { __proto__: null }),
130135
});
131136
}
132137

0 commit comments

Comments
 (0)