rotate-api-keys
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseRotate API Keys
API密钥轮换
Input Parameters
输入参数
| Parameter | Required | Description | Example |
|---|---|---|---|
| Yes | The API key to be replaced (the old or compromised key) | sk-old-abc123 |
| Yes | The new API key to replace the old one with | sk-new-xyz789 |
| No | Directories to search for .env files and keystores (defaults to home directory and common project paths) | ~/Herd ~/Code |
| 参数名称 | 是否必填 | 描述 | 示例 |
|---|---|---|---|
| 是 | 待替换的旧API密钥(已泄露或过期的密钥) | sk-old-abc123 |
| 是 | 用于替换旧密钥的新API密钥 | sk-new-xyz789 |
| 否 | 搜索.env文件和密钥库的目标目录(默认为主目录和常见项目路径) | ~/Herd ~/Code |
Procedure
操作步骤
-
Ask for the old and new API keys if not provided
-
Identify all target files — .env files, keystore files (), and logs containing credentials:
keys.jsonbashfind {{SEARCH_PATH}} -name "*.env" -o -name "keys.json" -o -name "*.log" -
Create backups and replace the key in each file:bash
sed -i.bak "s|{{OLD_KEY}}|{{NEW_KEY}}|g" {{FILE_PATH}} -
Verify the replacement in a sample of updated files:bash
grep -o "sk-[a-zA-Z0-9-]*" {{FILE_PATH}} | head -1 -
Report a summary of all updated files, backup locations, and verification results
-
若未提供旧密钥和新密钥,先向用户索要
-
识别所有目标文件 —— .env文件、密钥库文件()以及包含凭证的日志文件:
keys.jsonbashfind {{SEARCH_PATH}} -name "*.env" -o -name "keys.json" -o -name "*.log" -
创建备份并在每个文件中替换密钥:bash
sed -i.bak "s|{{OLD_KEY}}|{{NEW_KEY}}|g" {{FILE_PATH}} -
在部分已更新的文件中验证替换结果:bash
grep -o "sk-[a-zA-Z0-9-]*" {{FILE_PATH}} | head -1 -
报告所有已更新文件的摘要、备份位置以及验证结果
Notes
注意事项
- Backups are created automatically using the flag before any changes
-i.bak - 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凭证