diff --git a/src/secrets/CommandList.ts b/src/secrets/CommandList.ts index f0e7e16a..2b519fb8 100644 --- a/src/secrets/CommandList.ts +++ b/src/secrets/CommandList.ts @@ -1,33 +1,11 @@ import type PolykeyClient from 'polykey/dist/PolykeyClient'; import CommandPolykey from '../CommandPolykey'; -import { VaultFileNode } from 'polykey/dist/client/types'; +import { SecretFiles } from 'polykey/dist/client/types'; import * as binUtils from '../utils'; import * as binOptions from '../utils/options'; import * as binProcessors from '../utils/processors'; import * as binParsers from '../utils/parsers'; -function formatDate(date: Date): string { - const now = new Date(); - const sixMonthsAgo = new Date( - now.getFullYear(), - now.getMonth() - 6, - now.getDate(), - ); - const isRecent = date > sixMonthsAgo && date <= now; - - const month = date.toLocaleString('en-US', { month: 'short' }); - const day = date.getDate().toString().padStart(2, ' '); - - if (isRecent) { - const hours = date.getHours().toString().padStart(2, '0'); - const minutes = date.getMinutes().toString().padStart(2, '0'); - return `${month} ${day} ${hours}:${minutes}`; - } else { - const year = date.getFullYear().toString().padStart(5, ' '); - return `${month} ${day} ${year}`; - } -} - class CommandList extends CommandPolykey { constructor(...args: ConstructorParameters) { super(...args); @@ -72,13 +50,12 @@ class CommandList extends CommandPolykey { logger: this.logger.getChild(PolykeyClient.name), }); const data = await binUtils.retryAuthentication(async (auth) => { - let data: Array = []; + let data: Array = []; const stream = - await pkClient.rpcClient.methods.vaultsSecretsGetFileTree({ + await pkClient.rpcClient.methods.vaultsSecretsList({ metadata: auth, nameOrId: vaultPattern[0], - pattern: vaultPattern[1] ?? '/', - yieldStats: false, + path: vaultPattern[1] ?? '/', }); for await (const secret of stream) data.push(secret); diff --git a/src/utils/parsers.ts b/src/utils/parsers.ts index 85f7d814..41e115ee 100644 --- a/src/utils/parsers.ts +++ b/src/utils/parsers.ts @@ -66,7 +66,7 @@ function parseCoreCount(v: string): number | undefined { } } -function parseSecretName(secretPath: string): [string?, string?] { +function parseSecretName(secretPath: string): [string, string?] { // E.g. If 'vault1:a/b/c', ['vault1', 'a/b/c'] is returned // If 'vault1', ['vault1, undefined] is returned if (!secretPathNameRegex.test(secretPath)) { @@ -76,7 +76,7 @@ function parseSecretName(secretPath: string): [string?, string?] { } // Returns [vaultName, secretName?] const match = secretPath.match(secretPathNameRegex)!; - return [match[1] || undefined, match[2] || undefined]; + return [match[1], match[2] || undefined]; } function parseSecretPath(secretPath: string): [string, string, string?] { diff --git a/tests/secrets/list.test.ts b/tests/secrets/list.test.ts index 406fd008..caeed2ab 100644 --- a/tests/secrets/list.test.ts +++ b/tests/secrets/list.test.ts @@ -53,7 +53,7 @@ describe('commandListSecrets', () => { await vaultOps.addSecret(vault, 'MySecret3', 'this is the secret 3'); }); - command = ['secrets', 'list', '-np', dataDir, vaultName]; + command = ['secrets', 'ls', '-np', dataDir, vaultName]; const result = await testUtils.pkStdio([...command], { env: { @@ -62,6 +62,7 @@ describe('commandListSecrets', () => { cwd: dataDir, }); expect(result.exitCode).toBe(0); + expect(result.stdout).toBe('MySecret1\nMySecret2\nMySecret3\n'); }, globalThis.defaultTimeout * 2, );