-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bd3e8b4
commit afbd9a2
Showing
5 changed files
with
95 additions
and
76 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import type PolykeyClient from 'polykey/dist/PolykeyClient'; | ||
import CommandPolykey from '../CommandPolykey'; | ||
import * as binUtils from '../utils'; | ||
import * as binOptions from '../utils/options'; | ||
import * as binParsers from '../utils/parsers'; | ||
import * as binProcessors from '../utils/processors'; | ||
|
||
class CommandDelete extends CommandPolykey { | ||
constructor(...args: ConstructorParameters<typeof CommandPolykey>) { | ||
super(...args); | ||
this.name('rm'); | ||
this.description('Delete a Secret from a specified Vault'); | ||
this.argument( | ||
'<secretPaths>', | ||
'Path to one or more secret to be deleted, each specified as <vaultName>:<directoryPath>', | ||
binParsers.parseSecretPathValue, | ||
); | ||
this.addOption(binOptions.nodeId); | ||
this.addOption(binOptions.clientHost); | ||
this.addOption(binOptions.clientPort); | ||
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' | ||
); | ||
const clientOptions = await binProcessors.processClientOptions( | ||
options.nodePath, | ||
options.nodeId, | ||
options.clientHost, | ||
options.clientPort, | ||
this.fs, | ||
this.logger.getChild(binProcessors.processClientOptions.name), | ||
); | ||
const meta = await binProcessors.processAuthentication( | ||
options.passwordFile, | ||
this.fs, | ||
); | ||
|
||
let pkClient: PolykeyClient; | ||
this.exitHandlers.handlers.push(async () => { | ||
if (pkClient != null) await pkClient.stop(); | ||
}); | ||
try { | ||
pkClient = await PolykeyClient.createPolykeyClient({ | ||
nodeId: clientOptions.nodeId, | ||
host: clientOptions.clientHost, | ||
port: clientOptions.clientPort, | ||
options: { nodePath: options.nodePath }, | ||
logger: this.logger.getChild(PolykeyClient.name), | ||
}); | ||
await binUtils.retryAuthentication(async (auth) => { | ||
try { | ||
await pkClient.rpcClient.methods.vaultsSecretsRemove({ | ||
metadata: auth, | ||
nameOrId: secretPaths[0], | ||
secretNames: [secretPaths[1]], | ||
options: { recursive: options.recursive }, | ||
}); | ||
} catch(e) { | ||
console.error(e); | ||
throw e; | ||
} | ||
// for (const secretPath of secretPaths) { | ||
// await pkClient.rpcClient.methods.vaultsSecretsRemove({ | ||
// metadata: auth, | ||
// nameOrId: secretPath[0], | ||
// secretNames: [secretPath[1]], | ||
// options: { recursive: options.recursive }, | ||
// }); | ||
// } | ||
}, meta); | ||
} finally { | ||
if (pkClient! != null) await pkClient.stop(); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
export default CommandDelete; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters