Skip to content

Commit ba44c74

Browse files
authored
feat: add support for PGP encrypted config files (#683)
1 parent ad26df5 commit ba44c74

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,14 @@ After the token is generated, create an rc file with the following content:
8989
Note: you could use `ncu-config` to configure these variables, but it's not
9090
recommended to leave your tokens in your command line history.
9191

92+
If you have `gpg` installed and setup on your local machine, it is recommended
93+
to store an encrypted version of this file:
94+
95+
```console
96+
$ gpg --default-recipient-self --encrypt ~/.ncurc
97+
$ rm ~/.ncurc
98+
```
99+
92100
### Setting up Jenkins credentials
93101

94102
The `git-node` and `ncu-ci` commands need to query the Node.js Jenkins API for
@@ -104,8 +112,9 @@ To obtain the Jenkins API token
104112
3. Enter an identifiable name (for example, `node-core-utils`) for this
105113
token in the inbox that appears, and click `GENERATE`.
106114
4. Copy the generated token.
107-
5. Add it into your `ncurc` file (`~/.ncurc` or `$XDG_CONFIG_HOME/ncurc`)
108-
with `jenkins_token` as key, like this:
115+
5. Add it into your `ncurc` file (`~/.ncurc` or `$XDG_CONFIG_HOME/ncurc`, or
116+
`~/.ncurc.gpg` or `$XDG_CONFIG_HOME/ncurc.gpg`) with `jenkins_token` as key,
117+
like this:
109118

110119
```json
111120
{
@@ -125,6 +134,7 @@ Put the following entries into your
125134
```
126135
# node-core-utils configuration file
127136
.ncurc
137+
.ncurc.gpg
128138
# node-core-utils working directory
129139
.ncu
130140
```

lib/config.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import path from 'node:path';
22
import os from 'node:os';
33

44
import { readJson, writeJson } from './file.js';
5+
import { existsSync } from 'node:fs';
6+
import { spawnSync } from 'node:child_process';
57

68
export const GLOBAL_CONFIG = Symbol('globalConfig');
79
export const PROJECT_CONFIG = Symbol('projectConfig');
@@ -25,6 +27,14 @@ export function getMergedConfig(dir, home) {
2527

2628
export function getConfig(configType, dir) {
2729
const configPath = getConfigPath(configType, dir);
30+
const encryptedConfigPath = configPath + '.gpg';
31+
if (existsSync(encryptedConfigPath)) {
32+
const { status, stdout } =
33+
spawnSync('gpg', ['--decrypt', encryptedConfigPath]);
34+
if (status === 0) {
35+
return JSON.parse(stdout.toString('utf-8'));
36+
}
37+
}
2838
try {
2939
return readJson(configPath);
3040
} catch (cause) {

0 commit comments

Comments
 (0)