rotate-api-keys

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Rotate API Keys

API密钥轮换

Input Parameters

输入参数

ParameterRequiredDescriptionExample
old_api_key
YesThe API key to be replaced (the old or compromised key)sk-old-abc123
new_api_key
YesThe new API key to replace the old one withsk-new-xyz789
target_directories
NoDirectories to search for .env files and keystores (defaults to home directory and common project paths)~/Herd ~/Code
参数名称是否必填描述示例
old_api_key
待替换的旧API密钥(已泄露或过期的密钥)sk-old-abc123
new_api_key
用于替换旧密钥的新API密钥sk-new-xyz789
target_directories
搜索.env文件和密钥库的目标目录(默认为主目录和常见项目路径)~/Herd ~/Code

Procedure

操作步骤

  1. Ask for the old and new API keys if not provided
  2. Identify all target files — .env files, keystore files (
    keys.json
    ), and logs containing credentials:
    bash
    find {{SEARCH_PATH}} -name "*.env" -o -name "keys.json" -o -name "*.log"
  3. Create backups and replace the key in each file:
    bash
    sed -i.bak "s|{{OLD_KEY}}|{{NEW_KEY}}|g" {{FILE_PATH}}
  4. Verify the replacement in a sample of updated files:
    bash
    grep -o "sk-[a-zA-Z0-9-]*" {{FILE_PATH}} | head -1
  5. Report a summary of all updated files, backup locations, and verification results
  1. 若未提供旧密钥和新密钥,先向用户索要
  2. 识别所有目标文件 —— .env文件、密钥库文件(
    keys.json
    )以及包含凭证的日志文件:
    bash
    find {{SEARCH_PATH}} -name "*.env" -o -name "keys.json" -o -name "*.log"
  3. 创建备份并在每个文件中替换密钥:
    bash
    sed -i.bak "s|{{OLD_KEY}}|{{NEW_KEY}}|g" {{FILE_PATH}}
  4. 在部分已更新的文件中验证替换结果:
    bash
    grep -o "sk-[a-zA-Z0-9-]*" {{FILE_PATH}} | head -1
  5. 报告所有已更新文件的摘要、备份位置以及验证结果

Notes

注意事项

  • Backups are created automatically using the
    -i.bak
    flag before any changes
  • Verify replacements before confirming completion
  • Revoke the old key in the API provider's dashboard after rotation
  • Large log files may take time to process
  • 所有更改前会自动使用
    -i.bak
    标志创建备份文件
  • 在确认完成前请验证替换结果
  • 轮换完成后,请在API提供商的控制台中撤销旧密钥
  • 大型日志文件的处理可能需要较长时间

Example

使用示例

rotate my API key across all my projects and config files
replace my old OpenAI key with a new one in all .env files
update this API key everywhere it appears on my system
rotate my compromised API key across all config files and keystores
refresh my API credentials across my development environment
轮换我所有项目和配置文件中的API密钥
在所有.env文件中用新密钥替换我的旧OpenAI密钥
更新我的系统中所有出现该API密钥的位置
在所有配置文件和密钥库中轮换我已泄露的API密钥
刷新我开发环境中的API凭证