Skip to content

Instantly share code, notes, and snippets.

@nSimonFR
Last active December 2, 2023 16:18
Show Gist options
  • Save nSimonFR/8467644bb56020274d7593ba6f549965 to your computer and use it in GitHub Desktop.
Save nSimonFR/8467644bb56020274d7593ba6f549965 to your computer and use it in GitHub Desktop.
Generate secrets.json from a .env and uploads them to wrangler via bulk
#!/bin/sh
##
# Exports .env to .env.json and sends them to wrangler secret
# Generated by ChatGPT (But heavily human-corrected, it's almost as bad at regex as humans)
#
# Assumes you use gnused, warning for macOS users !
#
# MIT License - nSimon.fr
##
echo '{' > .env.json
cat .env | grep '^[A-z -_]*=.*$' | sed "s/ //g" | sed "s/'//g" | sed "s/\"//g" | while IFS='=' read -r key value; do
echo "\"$key\": \"$value\"," >> .env.json
done
sed -i '$ s/,$//' .env.json
echo '}' >> .env.json
wrangler secret:bulk .env.json
rm .env.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment