Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions icons/delete.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ async function querySecrets(searchString, manualSearch) {
);

for (const item of credentialsSets) {
// Attach the secret path to the credentials for later use (e.g., deletion)
item.secretPath = `${storeComponents.root}/metadata/${storeComponents.subPath}/${secret}${encodedElement}`;
// Display the decoded element name to the user
addCredentialsToList(item, decodedElement, resultList);

Expand Down Expand Up @@ -243,6 +245,19 @@ function addCredentialsToList(credentials, credentialName, list) {
});
actions.appendChild(copyPasswordButton);

const deleteButton = document.createElement('button');
deleteButton.classList.add('button');
deleteButton.title = 'delete credentials';
deleteButton.innerHTML = `
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon--inline">
<use href="icons/delete.svg#delete"/>
</svg>
`;
deleteButton.addEventListener('click', function () {
deleteCredentials(credentials.secretPath);
});
actions.appendChild(deleteButton);

list.appendChild(item);
}

Expand Down Expand Up @@ -292,4 +307,26 @@ async function copyStringToClipboard(string) {
}
}

async function deleteCredentials(secretPath) {
const result = await fetch(`${vaultServerAddress}/v1/${secretPath}`, {
method: 'DELETE',
headers: {
'X-Vault-Token': vaultToken,
'Content-Type': 'application/json',
},
});
if (result.ok) {
notify.clear().success('Credentials deleted successfully!', {
removeOption: false,
});
// Refresh the list after deletion
await querySecrets(currentUrl, searchInput.value.length !== 0);
} else {
notify.error('Unable to delete credentials...', {
removeOption: true,
});
return;
}
}

document.addEventListener('DOMContentLoaded', mainLoaded, false);
2 changes: 1 addition & 1 deletion style.css
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
--font-xl: 1.25rem;

/* Spacing */
--space-xs: 0.25rem;
--space-xs: 0.15rem;
--space-sm: 0.5rem;
--space-md: 0.7rem;
--space-lg: 1.5rem;
Expand Down