Expand description
XDG storage backend for API keys (four-layer hierarchy).
Implements the four-layer key loading hierarchy:
CONTEXT7_API_KEYSruntime environment variable (highest priority)- XDG config file
~/.config/context7/config.toml .envfile in the current working directoryCONTEXT7_API_KEYScompile-time environment variable (lowest priority)
Structs§
- ApiKey
- Secure wrapper for API keys with automatic memory cleanup.
- File
Config - Represents the structured TOML configuration file.
- Stored
Key - Represents a stored API key entry in the XDG configuration file.
Functions§
- apply_
600_ permissions - Sets 600 permissions (owner read/write only) on Unix systems.
- cmd_
keys_ add - Adds a new key to the XDG storage.
- cmd_
keys_ clear - Removes all stored keys. Asks for confirmation unless
--yesis passed. - cmd_
keys_ export - Exports all keys to stdout in
CONTEXT7_API=<value>format, one per line. - cmd_
keys_ import - Imports keys from a
.envfile, readingCONTEXT7_API=entries. - cmd_
keys_ list - Lists all stored keys with their 1-based indices and masked values.
- cmd_
keys_ path - Displays the path of the XDG configuration file.
- cmd_
keys_ remove - Removes a key by its 1-based index.
- discover_
config_ path - Discovers the XDG configuration path for the
config.tomlfile. - discover_
xdg_ log_ paths - Discovers the XDG path for storing log files.
- extract_
env_ keys - Extracts
CONTEXT7_API=keys from.envfile content in memory. - load_
api_ keys - Loads API keys using the four-layer precedence hierarchy:
- mask_
key - Masks an API key showing only the first 12 and last 4 characters.
- read_
compile_ time_ env - Layer 4: reads keys embedded at compile time via
option_env!("CONTEXT7_API_KEYS"). - read_
env_ cwd - Layer 3: reads keys from the
.envfile in the current working directory. - read_
env_ var_ key - Layer 1: reads keys from the
CONTEXT7_API_KEYSruntime environment variable. - read_
xdg_ config - Layer 2: reads keys from the XDG configuration file (
config.toml). - read_
xdg_ config_ raw - Reads the XDG configuration file and returns the full
FileConfig. - write_
file_ config - Writes a complete
FileConfigto the XDG configuration file. - write_
xdg_ config - Writes (or updates) the XDG configuration file with the provided key.