Skip to content

Commit

Permalink
wip: working on passing filetree via rpc
Browse files Browse the repository at this point in the history
  • Loading branch information
aryanjassal committed Aug 7, 2024
1 parent 34102e2 commit 536820f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
},
{
"name": "Aditya Varma"
},
{
"name": "Aryan Jassal"
}
],
"description": "Polykey Core Library",
Expand Down
17 changes: 6 additions & 11 deletions src/client/handlers/VaultsSecretsList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ class VaultsSecretsList extends UnaryHandler<
async (vault) => {
const data = await vault.readF(async (fs) => {
const fileTreeGen = fileTree.globWalk({
fs,
basePath: vault.vaultDataDir, // NOTE: check if this is correct
fs: fs,
basePath: '.',
pattern: input.pattern,
yieldStats: true,
yieldRoot: false,
Expand All @@ -49,25 +49,20 @@ class VaultsSecretsList extends UnaryHandler<
yieldDirectories: true,
});
const data: Array<TreeNode | ContentNode | Uint8Array> = [];
const parserTransform = fileTree.parserTransformStreamFactory();
const serializedStream = fileTree.serializerStreamFactory(
fs,
fileTreeGen,
false,
true,
);
const outputStream = serializedStream.pipeThrough(parserTransform);
for await (const output of outputStream) {
for await (const output of serializedStream) {
data.push(output);
}
return data;
});

const files = data
const contents = data
.filter((v) => v instanceof Uint8Array)
.map((v) => Buffer.from(v as Uint8Array).toString());
return {
secretFilesList: files,
};
return { secretFilesList: contents };
},
tran,
);
Expand Down
22 changes: 14 additions & 8 deletions tests/client/handlers/vaults.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ import * as vaultsUtils from '@/vaults/utils';
import * as vaultsErrors from '@/vaults/errors';
import * as networkUtils from '@/network/utils';
import * as testsUtils from '../../utils';
import { fileTree } from '@/vaults';

describe('vaultsClone', () => {
const logger = new Logger('vaultsClone test', LogLevel.WARN, [
Expand Down Expand Up @@ -1588,16 +1589,21 @@ describe('vaultsSecretsNewDir and vaultsSecretsList', () => {
});
expect(addResponse.success).toBeTruthy();
// List secrets
const listResponse = await rpcClient.methods.vaultsSecretsList({
const secrets = await rpcClient.methods.vaultsSecretsList({
nameOrId: vaultsIdEncoded,
pattern: '**/*',
});
const secrets: Array<string> = [];
for await (const secret of listResponse) {
secrets.push(secret.secretName);
}
expect(secrets.sort()).toStrictEqual(
secretList.map((secret) => path.join('secretDir', secret)).sort(),
);

console.log(secrets);

const secretFiles = secrets.secretFilesList;
const parserTransform = fileTree.parserTransformStreamFactory();
// const parsedFiles = dataStream.pipeThrough(parserTransform);

expect(secretFiles).toIncludeAllMembers([
...secretList.map((secret) => path.join('secretDir', secret)),
'secretDir'
]);
});
});
describe('vaultsSecretsRename', () => {
Expand Down

0 comments on commit 536820f

Please sign in to comment.