Skip to content

Commit

Permalink
Update findVaultContent function to prevent issues when dcli inject h…
Browse files Browse the repository at this point in the history
…andles multiple references (#260)

See #259 for details

Co-authored-by: Alan Transon <[email protected]>
  • Loading branch information
atranson and Alan Transon authored Jun 10, 2024
1 parent 3858cf8 commit 6f6188f
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/modules/database/vaultContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,26 +60,32 @@ export const getVaultContent = (path: string): string => {
};

export const findVaultContent = (vaultContent: VaultContent, parsedPath: ParsedPath): string => {
let filteredVaultContent: VaultContent = {

Check failure on line 63 in src/modules/database/vaultContent.ts

View workflow job for this annotation

GitHub Actions / build

'filteredVaultContent' is never reassigned. Use 'const' instead
credentials: [],
notes: [],
secrets: []

Check failure on line 66 in src/modules/database/vaultContent.ts

View workflow job for this annotation

GitHub Actions / build

Insert `,`
};

if (parsedPath.title) {
vaultContent.credentials = vaultContent.credentials.filter(
filteredVaultContent.credentials = vaultContent.credentials.filter(
(credential) => credential.title === parsedPath.title
);
vaultContent.notes = vaultContent.notes.filter((note) => note.title === parsedPath.title);
vaultContent.secrets = vaultContent.secrets.filter((secret) => secret.title === parsedPath.title);
filteredVaultContent.notes = vaultContent.notes.filter((note) => note.title === parsedPath.title);
filteredVaultContent.secrets = vaultContent.secrets.filter((secret) => secret.title === parsedPath.title);
}

if (parsedPath.itemId) {
vaultContent.credentials = vaultContent.credentials.filter((credential) => credential.id === parsedPath.itemId);
vaultContent.notes = vaultContent.notes.filter((note) => note.id === parsedPath.itemId);
vaultContent.secrets = vaultContent.secrets.filter((secret) => secret.id === parsedPath.itemId);
filteredVaultContent.credentials = vaultContent.credentials.filter((credential) => credential.id === parsedPath.itemId);

Check failure on line 78 in src/modules/database/vaultContent.ts

View workflow job for this annotation

GitHub Actions / build

Replace `(credential)·=>·credential.id·===·parsedPath.itemId` with `⏎············(credential)·=>·credential.id·===·parsedPath.itemId⏎········`
filteredVaultContent.notes = vaultContent.notes.filter((note) => note.id === parsedPath.itemId);
filteredVaultContent.secrets = vaultContent.secrets.filter((secret) => secret.id === parsedPath.itemId);
}

if (vaultContent.credentials.length === 0 && vaultContent.notes.length === 0 && vaultContent.secrets.length === 0) {
if (filteredVaultContent.credentials.length === 0 && filteredVaultContent.notes.length === 0 && filteredVaultContent.secrets.length === 0) {

Check failure on line 83 in src/modules/database/vaultContent.ts

View workflow job for this annotation

GitHub Actions / build

Replace `filteredVaultContent.credentials.length·===·0·&&·filteredVaultContent.notes.length·===·0·&&·filteredVaultContent.secrets.length·===·0` with `⏎········filteredVaultContent.credentials.length·===·0·&&⏎········filteredVaultContent.notes.length·===·0·&&⏎········filteredVaultContent.secrets.length·===·0⏎····`
throw new Error(`No matching item found for "${parsedPath.itemId ?? parsedPath.title ?? ''}"`);
}

const secretToRender: Record<string, any> =
vaultContent.secrets[0] ?? vaultContent.credentials[0] ?? vaultContent.notes[0];
filteredVaultContent.secrets[0] ?? filteredVaultContent.credentials[0] ?? filteredVaultContent.notes[0];

if (parsedPath.field) {
if (!secretToRender[parsedPath.field]) {
Expand Down

0 comments on commit 6f6188f

Please sign in to comment.