返回 Skill 列表
extension
分类: 开发与工程无需 API Key

rotate-api-keys

替换多个配置文件、密钥库和日志中的旧API密钥为新密钥。当用户要求在整个系统中轮换、替换、更新或刷新API密钥时,使用此技能。支持.env文件、JSON密钥库和日志文件。在进行更改前自动创建备份。

person作者: jakexiaohubgithub

Rotate API Keys

Input Parameters

| Parameter | Required | Description | Example | | -------------------- | -------- | ---------------------------------------------------------------------------------------------------------- | ------------- | | old_api_key | Yes | The API key to be replaced (the old or compromised key) | sk-old-abc123 | | new_api_key | Yes | The new API key to replace the old one with | sk-new-xyz789 | | target_directories | No | Directories to search for .env files and keystores (defaults to home directory and common project paths) | ~/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:

    find {{SEARCH_PATH}} -name "*.env" -o -name "keys.json" -o -name "*.log"
    
  3. Create backups and replace the key in each file:

    sed -i.bak "s|{{OLD_KEY}}|{{NEW_KEY}}|g" {{FILE_PATH}}
    
  4. Verify the replacement in a sample of updated files:

    grep -o "sk-[a-zA-Z0-9-]*" {{FILE_PATH}} | head -1
    
  5. Report a summary of all updated files, backup locations, and verification results

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

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