Manage secret storage using the Splunk SDK for JavaScript
Was this page helpful?
Was this page helpful?
On this page
You can call the storage/passwords REST API endpoint using the Splunk SDK for JavaScript.
Use these classes from the SDK to manage secret storage:
- splunkjs.Service.StoragePassword for an individual secret.
- splunkjs.Service.StoragePasswords for a collection of secrets.
Access these classes through an instance of the splunkjs.Service class. First, retrieve a collection, and then you can access and create individual items in the collection.
Examples
The following examples show how to manage secret storage in an app using the Splunk SDK for JavaScript. To use these examples, you must be connected to a Splunk Enterprise instance.
Store a new secret for the user1
user:
JavaScript// Get the current user // Get the collection of secrets var storagePasswords = service.storagePasswords(); // Create a new secret storagePasswords.create({ name: "user1", realm: "realm1",
Copy to clipboard...
List all secrets that are visible to the current user:
JavaScript// List secrets storagePasswords.fetch( function(err, storagePasswords) { if (err) {console.warn(err);} else { // Secret was created successfully console.log("Found " + storagePasswords.list().length + " storage passwords"); } });
Copy to clipboard
See also
How to work with users, roles, and secret storage using the Splunk Enterprise SDK for JavaScript