Created
December 11, 2018 03:51
-
-
Save srkiNZ84/bd5f27191344c66b142f15e6d3a6c927 to your computer and use it in GitHub Desktop.
Script to generate and upload access keys to BitBucket repositories
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
BB_ACCOUNT_NAME="john" | |
BB_USERNAME="doe" | |
BB_PASSWORD="password" | |
declare -a repositoryList=( "limerick-generator" ) | |
for repository in "${repositoryList[@]}" | |
do | |
echo "TODO: Checking for existing access key in $repository..." | |
# TODO: If key exists do nothing | |
keyname="$repository-`date +%s`" | |
echo "Generating key $keyname for $repository" | |
ssh-keygen -C $keyname -N "" -f $keyname.key | |
echo "TODO: Saving key to Secret storage (e.g. Vault)" | |
echo "Uploading key to repository Access Keys" | |
publicKey=`cat $keyname.key.pub` | |
curl -X POST -u $BB_USERNAME:"$BB_PASSWORD" https://api.bitbucket.org/1.0/repositories/$BB_ACCOUNT_NAME/$repository/deploy-keys --data-urlencode "key=$publicKey" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment