Manage secret storage using the Splunk SDK for Python
You can call the storage/passwords REST API endpoint using the Splunk SDK for Python.
Use these classes from the SDK to manage secret storage:
- splunklib.client.StoragePassword(Opens new window) for an individual secret.
- splunklib.client.StoragePasswords(Opens new window) for a collection of secrets.
Access these classes through an instance of the splunklib.client.Service(Opens new window) 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 Python. To use these examples, you must be connected to a Splunk Enterprise instance.
Store a new secret for the user1 user:
service = client.connect(...)storage_passwords = service.storage_passwords# Create a secretstorage_password = storage_passwords.create("password1", "user1", "realm1")print("Created storage password with name: {}".format(storage_password.name))
List all secrets that are visible to the current user:
service = client.connect(...)storage_passwords = service.storage_passwords# List secretsfor storage_password in storage_passwords.list():print(storage_password.name)
See also
How to work with users, roles, and secret storage using the Splunk Enterprise SDK for Python