Skip to content

Commit

Permalink
deps: update polykey to 1.18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
aryanjassal committed Jan 31, 2025
1 parent e8673be commit de7e285
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 19 deletions.
2 changes: 1 addition & 1 deletion npmDepsHash
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sha256-NYzadQBEN6ZbZfdSnW9aoW77InHvL8oL0joXcrs1ktI=
sha256-Ud5IBToO1LXjvPkAyw+oc2m9EFbwtHvvyVO2Y2BdZwg=
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 @@ -153,7 +153,7 @@
"nexpect": "^0.6.0",
"node-gyp-build": "^4.4.0",
"nodemon": "^3.0.1",
"polykey": "^1.17.4",
"polykey": "^1.18.0",
"prettier": "^3.0.0",
"shelljs": "^0.8.5",
"shx": "^0.3.4",
Expand Down
2 changes: 1 addition & 1 deletion src/secrets/CommandCat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class CommandGet extends CommandPolykey {
break;
default:
never(
`Expected "SuccessMessage" or "ContentMessage", got ${type}`,
`Expected "SuccessMessage" or "ErrorMessage", got ${type}`,
);
}
}
Expand Down
55 changes: 45 additions & 10 deletions src/secrets/CommandCreate.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type PolykeyClient from 'polykey/dist/PolykeyClient';
import path from 'path';
import * as errors from '../errors';
import CommandPolykey from '../CommandPolykey';
import * as binUtils from '../utils';
Expand Down Expand Up @@ -27,6 +28,7 @@ class CommandCreate extends CommandPolykey {
const { default: PolykeyClient } = await import(
'polykey/dist/PolykeyClient'
);
const { never } = await import('polykey/dist/utils');
const clientOptions = await binProcessors.processClientOptions(
options.nodePath,
options.nodeId,
Expand Down Expand Up @@ -68,16 +70,49 @@ class CommandCreate extends CommandPolykey {
cause: e,
});
}
await binUtils.retryAuthentication(
(auth) =>
pkClient.rpcClient.methods.vaultsSecretsNew({
metadata: auth,
nameOrId: secretPath[0],
secretName: secretPath[1] ?? '/',
secretContent: content.toString('binary'),
}),
meta,
);
await binUtils.retryAuthentication(async (auth) => {
// Make sure the path exists
const response =
await pkClient.rpcClient.methods.vaultsSecretsMkdir();
const writer = response.writable.getWriter();
await writer.write({
nameOrId: secretPath[0],
dirName: path.dirname(secretPath[1] ?? '/'),
metadata: { ...auth, options: { recursive: true } },
});
await writer.close();
for await (const chunk of response.readable) {
const type = chunk.type;
switch (type) {
case 'SuccessMessage':
// No special action required if mkdir succeeds
break;
case 'ErrorMessage':
// This operation can only fail if a file already exists at the
// target location. No other error should happen.
if (chunk.code === 'EEXIST') {
throw new errors.ErrorPolykeyCLIMakeDirectory(
`A file already exists at path ${chunk.reason}`,
);
} else {
throw new errors.ErrorPolykeyCLIMakeDirectory(
`Failed to create directory ${chunk.reason} (${chunk.code})`,
);
}
default:
never(
`Expected "SuccessMessage" or "ErrorMessage", got ${type}`,
);
}
}
// Write the contents
await pkClient.rpcClient.methods.vaultsSecretsWriteFile({
metadata: auth,
nameOrId: secretPath[0],
secretName: secretPath[1] ?? '/',
secretContent: content.toString('binary'),
});
}, meta);
} finally {
if (pkClient! != null) await pkClient.stop();
}
Expand Down
2 changes: 1 addition & 1 deletion src/secrets/CommandEdit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class CommandEdit extends CommandPolykey {
break;
default:
never(
`Expected "SuccessMessage" or "ContentMessage", got ${type}`,
`Expected "SuccessMessage" or "ErrorMessage", got ${type}`,
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/secrets/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ describe('commandCreateSecret', () => {
expect(result.exitCode).not.toBe(0);
// The root directory is already defined so we can't create a new secret
// at path `vault:/`.
expect(result.stderr).toInclude('ErrorSecretsSecretDefined');
expect(result.stderr).toInclude('ErrorSecretsIsDirectory');
});
test.prop([fileNameArb, fileNameArb, envVariableArb], { numRuns: 10 })(
'secrets handle unix style paths for secrets',
Expand Down

0 comments on commit de7e285

Please sign in to comment.