Skip to content

Commit

Permalink
feat: 'secrets edit' now makes a new secret if it doesnt exist already
Browse files Browse the repository at this point in the history
  • Loading branch information
aryanjassal committed Aug 26, 2024
1 parent 755e97f commit 064b69a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 49 deletions.
52 changes: 10 additions & 42 deletions flake.lock

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

32 changes: 25 additions & 7 deletions src/secrets/CommandEdit.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import type PolykeyClient from 'polykey/dist/PolykeyClient';
import fs from 'fs';
import path from 'path';
import * as errors from '../errors';
import CommandPolykey from '../CommandPolykey';
import * as vaultsErrors from 'polykey/dist/vaults/errors';
import * as errors from '../errors';
import * as binUtils from '../utils';
import * as binOptions from '../utils/options';
import * as binParsers from '../utils/parsers';
Expand Down Expand Up @@ -54,15 +55,32 @@ class CommandEdit extends CommandPolykey {
},
logger: this.logger.getChild(PolykeyClient.name),
});
const response = await binUtils.retryAuthentication(
(auth) =>
pkClient.rpcClient.methods.vaultsSecretsGet({
const response = await binUtils.retryAuthentication((auth) => {
try {
pkClient.rpcClient.methods.vaultsSecretsStat({
metadata: auth,
nameOrId: secretPath[0],
secretName: secretPath[1],
}),
meta,
);
});
} catch (e) {
console.log(e.cause);
if (e.cause === vaultsErrors.ErrorSecretsSecretUndefined) {
pkClient.rpcClient.methods.vaultsSecretsNew({
metadata: auth,
nameOrId: secretPath[0],
secretName: secretPath[1],
secretContent: '',
});
}
else throw e;
}

return pkClient.rpcClient.methods.vaultsSecretsGet({
metadata: auth,
nameOrId: secretPath[0],
secretName: secretPath[1],
});
}, meta);
const secretContent = response.secretContent;
const tmpDir = await fs.promises.mkdtemp(
path.join(os.tmpdir(), 'polykey-'),
Expand Down

0 comments on commit 064b69a

Please sign in to comment.