keyring
stableSecure key-value secret storage organized by service name, persisted as a JSON file in the system temp directory.
use plugin keyring::{set_secret, get_secret, delete_secret, …} Functions (9)
- set_secret Store a secret value for a service and key
- get_secret Retrieve a secret value by service and key
- delete_secret Remove a specific secret entry
- list_services List all registered service names
- list_keys List all key names for a service
- has_secret Check if a secret exists
- clear_service Remove all secrets for a service
- secret_count Count secrets stored for a service
- storage_path Get the path to the secrets storage file
Store a secret value for a service and key
Stores a secret string under service + key. Creates the service namespace automatically if it does not exist. Use this to persist API tokens, passwords, or other sensitive strings across program runs.
use plugin keyring::{set_secret}
set_secret("myapp", "api_token", "sk-abc123")
set_secret("myapp", "db_password", "hunter2")
Retrieve a secret value by service and key
Retrieves the secret stored at service + key. Returns nil if the entry does not exist.
use plugin keyring::{set_secret, get_secret}
set_secret("myapp", "api_token", "sk-abc123")
let token = get_secret("myapp", "api_token")
print("Token: {token}")
Remove a specific secret entry
Removes a single secret entry. If the service becomes empty after deletion it is also removed. Does nothing if the key does not exist.
use plugin keyring::{delete_secret}
delete_secret("myapp", "old_token")
List all registered service names
Returns an array of all service names currently in the store. Useful for auditing which services have stored secrets.
use plugin keyring::{list_services}
let services = list_services()
print("Registered services: {services}")
List all key names for a service
Returns an array of all key names stored under service. Returns an empty table if the service does not exist.
use plugin keyring::{set_secret, list_keys}
set_secret("myapp", "api_token", "abc")
set_secret("myapp", "db_password", "xyz")
let keys = list_keys("myapp")
print("Keys: {keys}")
Check if a secret exists
Returns true if a secret exists for the given service and key, false otherwise. Use this before calling get_secret to avoid nil checks.
use plugin keyring::{has_secret, get_secret}
if has_secret("myapp", "api_token") {
let token = get_secret("myapp", "api_token")
print("Using token: {token}")
} else {
print("No token configured")
}
Remove all secrets for a service
Removes all secrets stored under service. The service namespace is deleted entirely.
use plugin keyring::{clear_service}
clear_service("myapp")
Count secrets stored for a service
Returns the number of secrets stored for a service. Returns 0 if the service does not exist.
use plugin keyring::{secret_count}
let n = secret_count("myapp")
print("myapp has {n} secrets")
Get the path to the secrets storage file
Returns the absolute path to the JSON file used for persistent storage. Useful for debugging or backing up secrets.
use plugin keyring::{storage_path}
let path = storage_path()
print("Secrets stored at: {path}")