CLI tool that generates a .env file using key-value pairs retrieved from Bitwarden Secrets
- This utilizes the bws CLI instead of BWS SDK Language Python as it reduces dependencies and simplifies installation and usage.
- Currently supports bws CLI v1.0.0
- Tested on Apple Silicon and Debian Bookworm
- This is a very basic tool, feel free to scrap it for parts and implement it directly into your project
- Python 3
- Bash Environemtn (or alternative)
- bws CLI v1.0.0 (in PATH)
- bws Machine Account token
- Download .zip of bws CLI v1.0.0
- Unzip the archive
unzip bws-macos-universal-1.0.0zip
- Add bws to your PATH
cp -R bws /usr/local/bin
- https://bitwarden.com/help/secrets/
- You will need to assign your machine account access to your created secrets
- Enter downloaded bws-dotenv-gen directory
cd bws-dotenv-gen/src
- Add keys to template.env (make sure the keys in this file match those in bws)
echo "PROXMOX_API_KEY=" >> template.envecho "DEBIAN1_ROOT_PASSWORD=" >> template.envecho "CHATGPT_API_KEY=" >> template.env
- Run bws-dotenv-gen
python3 main.py
- Enter your bws token at prompt
- Check .env for the generated dotenv file
cat .envPROXMOX_API_KEY=CCE2F4FD-AD40-4B6F-A5ED-C8549FF251CFDEBIAN1_ROOT_PASSWORD=3spre4di$dA835tCHATGPT_API_KEY=62A8117C-4A60-4E21-B51C-460BBF4C9107
- bws_client grabs all secrets your machine account has access to and checks them against the keys in template.env
- Currently this reads a template.env from ../src and puts the .env in ../.env
- You will very likely want to adjust the directories used to match your needs
- The script will error out if no template.env is found, but will not error out if not all keys in template.env are found in bws, the unfound keys will be left blank in the .env