Skip to content

Commit

Permalink
Merge pull request #279 from MatrixAI/feature-unix-rm
Browse files Browse the repository at this point in the history
Adding `secrets rm` command
  • Loading branch information
aryanjassal authored Sep 16, 2024
2 parents 131d38a + 51cc64f commit 6f77c68
Show file tree
Hide file tree
Showing 8 changed files with 275 additions and 98 deletions.
2 changes: 1 addition & 1 deletion npmDepsHash
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sha256-iXj2QmiuiYudb/V9FRTAPU52ns1i2g4H82Rb2NrWLNo=
sha256-FDJmb93Xgols7SXWv/ETyDm0uggBmVuVWiD+vJOcKcc=
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
"nexpect": "^0.6.0",
"node-gyp-build": "^4.4.0",
"nodemon": "^3.0.1",
"polykey": "^1.10.0",
"polykey": "^1.11.1",
"prettier": "^3.0.0",
"shelljs": "^0.8.5",
"shx": "^0.3.4",
Expand Down
39 changes: 18 additions & 21 deletions src/secrets/CommandDelete.ts → src/secrets/CommandRemove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@ import * as binProcessors from '../utils/processors';
class CommandDelete extends CommandPolykey {
constructor(...args: ConstructorParameters<typeof CommandPolykey>) {
super(...args);
this.name('delete');
this.aliases(['del', 'rm']);
this.description('Delete a Secret from a Specified Vault');
this.name('rm');
this.description('Delete a Secret from a specified Vault');
this.argument(
'<secretPath>',
'Path to the secret that to be deleted, specified as <vaultName>:<directoryPath>',
binParsers.parseSecretPathValue,
'<secretPaths...>',
'Path to one or more secret to be deleted, each specified as <vaultName>:<directoryPath>',
);
this.addOption(binOptions.nodeId);
this.addOption(binOptions.clientHost);
this.addOption(binOptions.clientPort);
this.action(async (secretPath, options) => {
this.addOption(binOptions.recursive);
this.action(async (secretPaths, options) => {
secretPaths = secretPaths.map((path: string) =>
binParsers.parseSecretPathValue(path),
);
const { default: PolykeyClient } = await import(
'polykey/dist/PolykeyClient'
);
Expand All @@ -31,11 +33,10 @@ class CommandDelete extends CommandPolykey {
this.fs,
this.logger.getChild(binProcessors.processClientOptions.name),
);
const auth = await binProcessors.processAuthentication(
const meta = await binProcessors.processAuthentication(
options.passwordFile,
this.fs,
);

let pkClient: PolykeyClient;
this.exitHandlers.handlers.push(async () => {
if (pkClient != null) await pkClient.stop();
Expand All @@ -45,20 +46,16 @@ class CommandDelete extends CommandPolykey {
nodeId: clientOptions.nodeId,
host: clientOptions.clientHost,
port: clientOptions.clientPort,
options: {
nodePath: options.nodePath,
},
options: { nodePath: options.nodePath },
logger: this.logger.getChild(PolykeyClient.name),
});
await binUtils.retryAuthentication(
(auth) =>
pkClient.rpcClient.methods.vaultsSecretsDelete({
metadata: auth,
nameOrId: secretPath[0],
secretName: secretPath[1],
}),
auth,
);
await binUtils.retryAuthentication(async (auth) => {
await pkClient.rpcClient.methods.vaultsSecretsRemove({
metadata: auth,
secretNames: secretPaths,
options: { recursive: options.recursive },
});
}, meta);
} finally {
if (pkClient! != null) await pkClient.stop();
}
Expand Down
4 changes: 2 additions & 2 deletions src/secrets/CommandSecrets.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import CommandCreate from './CommandCreate';
import CommandDelete from './CommandDelete';
import CommandDir from './CommandDir';
import CommandEdit from './CommandEdit';
import CommandEnv from './CommandEnv';
import CommandGet from './CommandGet';
import CommandList from './CommandList';
import CommandMkdir from './CommandMkdir';
import CommandRename from './CommandRename';
import CommandRemove from './CommandRemove';
import CommandUpdate from './CommandUpdate';
import CommandStat from './CommandStat';
import CommandPolykey from '../CommandPolykey';
Expand All @@ -17,14 +17,14 @@ class CommandSecrets extends CommandPolykey {
this.name('secrets');
this.description('Secrets Operations');
this.addCommand(new CommandCreate(...args));
this.addCommand(new CommandDelete(...args));
this.addCommand(new CommandDir(...args));
this.addCommand(new CommandEdit(...args));
this.addCommand(new CommandEnv(...args));
this.addCommand(new CommandGet(...args));
this.addCommand(new CommandList(...args));
this.addCommand(new CommandMkdir(...args));
this.addCommand(new CommandRename(...args));
this.addCommand(new CommandRemove(...args));
this.addCommand(new CommandUpdate(...args));
this.addCommand(new CommandStat(...args));
}
Expand Down
6 changes: 6 additions & 0 deletions src/utils/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,11 @@ const order = new commander.Option(
.choices(['asc', 'desc'])
.default('asc');

const recursive = new commander.Option(
'--recursive',
'If enabled, specified directories will be removed along with their contents',
).default(false);

export {
nodePath,
format,
Expand Down Expand Up @@ -343,4 +348,5 @@ export {
events,
limit,
order,
recursive,
};
69 changes: 0 additions & 69 deletions tests/secrets/delete.test.ts

This file was deleted.

Loading

0 comments on commit 6f77c68

Please sign in to comment.