Skip to main content

Module storage

Module storage 

Source
Expand description

XDG storage backend for API keys (four-layer hierarchy).

Implements the four-layer key loading hierarchy:

  1. CONTEXT7_API_KEYS runtime environment variable (highest priority)
  2. XDG config file ~/.config/context7/config.toml
  3. .env file in the current working directory
  4. CONTEXT7_API_KEYS compile-time environment variable (lowest priority)

Structs§

ApiKey
Secure wrapper for API keys with automatic memory cleanup.
FileConfig
Represents the structured TOML configuration file.
StoredKey
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 --yes is passed.
cmd_keys_export
Exports all keys to stdout in CONTEXT7_API=<value> format, one per line.
cmd_keys_import
Imports keys from a .env file, reading CONTEXT7_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.toml file.
discover_xdg_log_paths
Discovers the XDG path for storing log files.
extract_env_keys
Extracts CONTEXT7_API= keys from .env file 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 .env file in the current working directory.
read_env_var_key
Layer 1: reads keys from the CONTEXT7_API_KEYS runtime 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 FileConfig to the XDG configuration file.
write_xdg_config
Writes (or updates) the XDG configuration file with the provided key.