Skip to content

Commit de7e285

Browse files
committed
deps: update polykey to 1.18.0
1 parent e8673be commit de7e285

File tree

7 files changed

+54
-19
lines changed

7 files changed

+54
-19
lines changed

npmDepsHash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sha256-NYzadQBEN6ZbZfdSnW9aoW77InHvL8oL0joXcrs1ktI=
1+
sha256-Ud5IBToO1LXjvPkAyw+oc2m9EFbwtHvvyVO2Y2BdZwg=

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
@@ -153,7 +153,7 @@
153153
"nexpect": "^0.6.0",
154154
"node-gyp-build": "^4.4.0",
155155
"nodemon": "^3.0.1",
156-
"polykey": "^1.17.4",
156+
"polykey": "^1.18.0",
157157
"prettier": "^3.0.0",
158158
"shelljs": "^0.8.5",
159159
"shx": "^0.3.4",

src/secrets/CommandCat.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class CommandGet extends CommandPolykey {
123123
break;
124124
default:
125125
never(
126-
`Expected "SuccessMessage" or "ContentMessage", got ${type}`,
126+
`Expected "SuccessMessage" or "ErrorMessage", got ${type}`,
127127
);
128128
}
129129
}

src/secrets/CommandCreate.ts

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type PolykeyClient from 'polykey/dist/PolykeyClient';
2+
import path from 'path';
23
import * as errors from '../errors';
34
import CommandPolykey from '../CommandPolykey';
45
import * as binUtils from '../utils';
@@ -27,6 +28,7 @@ class CommandCreate extends CommandPolykey {
2728
const { default: PolykeyClient } = await import(
2829
'polykey/dist/PolykeyClient'
2930
);
31+
const { never } = await import('polykey/dist/utils');
3032
const clientOptions = await binProcessors.processClientOptions(
3133
options.nodePath,
3234
options.nodeId,
@@ -68,16 +70,49 @@ class CommandCreate extends CommandPolykey {
6870
cause: e,
6971
});
7072
}
71-
await binUtils.retryAuthentication(
72-
(auth) =>
73-
pkClient.rpcClient.methods.vaultsSecretsNew({
74-
metadata: auth,
75-
nameOrId: secretPath[0],
76-
secretName: secretPath[1] ?? '/',
77-
secretContent: content.toString('binary'),
78-
}),
79-
meta,
80-
);
73+
await binUtils.retryAuthentication(async (auth) => {
74+
// Make sure the path exists
75+
const response =
76+
await pkClient.rpcClient.methods.vaultsSecretsMkdir();
77+
const writer = response.writable.getWriter();
78+
await writer.write({
79+
nameOrId: secretPath[0],
80+
dirName: path.dirname(secretPath[1] ?? '/'),
81+
metadata: { ...auth, options: { recursive: true } },
82+
});
83+
await writer.close();
84+
for await (const chunk of response.readable) {
85+
const type = chunk.type;
86+
switch (type) {
87+
case 'SuccessMessage':
88+
// No special action required if mkdir succeeds
89+
break;
90+
case 'ErrorMessage':
91+
// This operation can only fail if a file already exists at the
92+
// target location. No other error should happen.
93+
if (chunk.code === 'EEXIST') {
94+
throw new errors.ErrorPolykeyCLIMakeDirectory(
95+
`A file already exists at path ${chunk.reason}`,
96+
);
97+
} else {
98+
throw new errors.ErrorPolykeyCLIMakeDirectory(
99+
`Failed to create directory ${chunk.reason} (${chunk.code})`,
100+
);
101+
}
102+
default:
103+
never(
104+
`Expected "SuccessMessage" or "ErrorMessage", got ${type}`,
105+
);
106+
}
107+
}
108+
// Write the contents
109+
await pkClient.rpcClient.methods.vaultsSecretsWriteFile({
110+
metadata: auth,
111+
nameOrId: secretPath[0],
112+
secretName: secretPath[1] ?? '/',
113+
secretContent: content.toString('binary'),
114+
});
115+
}, meta);
81116
} finally {
82117
if (pkClient! != null) await pkClient.stop();
83118
}

src/secrets/CommandEdit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class CommandEdit extends CommandPolykey {
110110
break;
111111
default:
112112
never(
113-
`Expected "SuccessMessage" or "ContentMessage", got ${type}`,
113+
`Expected "SuccessMessage" or "ErrorMessage", got ${type}`,
114114
);
115115
}
116116
}

tests/secrets/create.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ describe('commandCreateSecret', () => {
9393
expect(result.exitCode).not.toBe(0);
9494
// The root directory is already defined so we can't create a new secret
9595
// at path `vault:/`.
96-
expect(result.stderr).toInclude('ErrorSecretsSecretDefined');
96+
expect(result.stderr).toInclude('ErrorSecretsIsDirectory');
9797
});
9898
test.prop([fileNameArb, fileNameArb, envVariableArb], { numRuns: 10 })(
9999
'secrets handle unix style paths for secrets',

0 commit comments

Comments
 (0)