Skip to content

Commit 6f77c68

Browse files
authored
Merge pull request #279 from MatrixAI/feature-unix-rm
Adding `secrets rm` command
2 parents 131d38a + 51cc64f commit 6f77c68

8 files changed

Lines changed: 275 additions & 98 deletions

File tree

npmDepsHash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sha256-iXj2QmiuiYudb/V9FRTAPU52ns1i2g4H82Rb2NrWLNo=
1+
sha256-FDJmb93Xgols7SXWv/ETyDm0uggBmVuVWiD+vJOcKcc=

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@
150150
"nexpect": "^0.6.0",
151151
"node-gyp-build": "^4.4.0",
152152
"nodemon": "^3.0.1",
153-
"polykey": "^1.10.0",
153+
"polykey": "^1.11.1",
154154
"prettier": "^3.0.0",
155155
"shelljs": "^0.8.5",
156156
"shx": "^0.3.4",
Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,20 @@ import * as binProcessors from '../utils/processors';
88
class CommandDelete extends CommandPolykey {
99
constructor(...args: ConstructorParameters<typeof CommandPolykey>) {
1010
super(...args);
11-
this.name('delete');
12-
this.aliases(['del', 'rm']);
13-
this.description('Delete a Secret from a Specified Vault');
11+
this.name('rm');
12+
this.description('Delete a Secret from a specified Vault');
1413
this.argument(
15-
'<secretPath>',
16-
'Path to the secret that to be deleted, specified as <vaultName>:<directoryPath>',
17-
binParsers.parseSecretPathValue,
14+
'<secretPaths...>',
15+
'Path to one or more secret to be deleted, each specified as <vaultName>:<directoryPath>',
1816
);
1917
this.addOption(binOptions.nodeId);
2018
this.addOption(binOptions.clientHost);
2119
this.addOption(binOptions.clientPort);
22-
this.action(async (secretPath, options) => {
20+
this.addOption(binOptions.recursive);
21+
this.action(async (secretPaths, options) => {
22+
secretPaths = secretPaths.map((path: string) =>
23+
binParsers.parseSecretPathValue(path),
24+
);
2325
const { default: PolykeyClient } = await import(
2426
'polykey/dist/PolykeyClient'
2527
);
@@ -31,11 +33,10 @@ class CommandDelete extends CommandPolykey {
3133
this.fs,
3234
this.logger.getChild(binProcessors.processClientOptions.name),
3335
);
34-
const auth = await binProcessors.processAuthentication(
36+
const meta = await binProcessors.processAuthentication(
3537
options.passwordFile,
3638
this.fs,
3739
);
38-
3940
let pkClient: PolykeyClient;
4041
this.exitHandlers.handlers.push(async () => {
4142
if (pkClient != null) await pkClient.stop();
@@ -45,20 +46,16 @@ class CommandDelete extends CommandPolykey {
4546
nodeId: clientOptions.nodeId,
4647
host: clientOptions.clientHost,
4748
port: clientOptions.clientPort,
48-
options: {
49-
nodePath: options.nodePath,
50-
},
49+
options: { nodePath: options.nodePath },
5150
logger: this.logger.getChild(PolykeyClient.name),
5251
});
53-
await binUtils.retryAuthentication(
54-
(auth) =>
55-
pkClient.rpcClient.methods.vaultsSecretsDelete({
56-
metadata: auth,
57-
nameOrId: secretPath[0],
58-
secretName: secretPath[1],
59-
}),
60-
auth,
61-
);
52+
await binUtils.retryAuthentication(async (auth) => {
53+
await pkClient.rpcClient.methods.vaultsSecretsRemove({
54+
metadata: auth,
55+
secretNames: secretPaths,
56+
options: { recursive: options.recursive },
57+
});
58+
}, meta);
6259
} finally {
6360
if (pkClient! != null) await pkClient.stop();
6461
}

src/secrets/CommandSecrets.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import CommandCreate from './CommandCreate';
2-
import CommandDelete from './CommandDelete';
32
import CommandDir from './CommandDir';
43
import CommandEdit from './CommandEdit';
54
import CommandEnv from './CommandEnv';
65
import CommandGet from './CommandGet';
76
import CommandList from './CommandList';
87
import CommandMkdir from './CommandMkdir';
98
import CommandRename from './CommandRename';
9+
import CommandRemove from './CommandRemove';
1010
import CommandUpdate from './CommandUpdate';
1111
import CommandStat from './CommandStat';
1212
import CommandPolykey from '../CommandPolykey';
@@ -17,14 +17,14 @@ class CommandSecrets extends CommandPolykey {
1717
this.name('secrets');
1818
this.description('Secrets Operations');
1919
this.addCommand(new CommandCreate(...args));
20-
this.addCommand(new CommandDelete(...args));
2120
this.addCommand(new CommandDir(...args));
2221
this.addCommand(new CommandEdit(...args));
2322
this.addCommand(new CommandEnv(...args));
2423
this.addCommand(new CommandGet(...args));
2524
this.addCommand(new CommandList(...args));
2625
this.addCommand(new CommandMkdir(...args));
2726
this.addCommand(new CommandRename(...args));
27+
this.addCommand(new CommandRemove(...args));
2828
this.addCommand(new CommandUpdate(...args));
2929
this.addCommand(new CommandStat(...args));
3030
}

src/utils/options.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,11 @@ const order = new commander.Option(
302302
.choices(['asc', 'desc'])
303303
.default('asc');
304304

305+
const recursive = new commander.Option(
306+
'--recursive',
307+
'If enabled, specified directories will be removed along with their contents',
308+
).default(false);
309+
305310
export {
306311
nodePath,
307312
format,
@@ -343,4 +348,5 @@ export {
343348
events,
344349
limit,
345350
order,
351+
recursive,
346352
};

tests/secrets/delete.test.ts

Lines changed: 0 additions & 69 deletions
This file was deleted.

0 commit comments

Comments
 (0)