Created
April 23, 2017 10:07
-
-
Save samdbmg/37eec34b66574345b5bd55918a4e17f8 to your computer and use it in GitHub Desktop.
Codenvy GIT_SSH script to get private key
This file contains 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 | |
set -e | |
if [ $1 = "-p" ] | |
then | |
host=$(echo "$3" | sed -e 's/git@//') | |
else | |
host=$(echo "$1" | sed -e 's/git@//') | |
fi | |
ssh_key=$(echo "$(curl -s "$CHE_API/ssh/vcs/find?name=$host&token=$USER_TOKEN"| grep -Po '"privateKey":.*?[^\\]",')" | sed -e "s/\"privateKey\":\"//" | sed -e "s/\",//" | sed -e "s/\\\\u003d/=/g") | |
if [ -n "$ssh_key" ] | |
then | |
key_file=$(mktemp) | |
echo "$ssh_key" > "$key_file" | |
sed 's/\\n/\n/g' -i "$key_file" | |
ssh -i "$key_file" "$@" | |
rm "$key_file" | |
else | |
ssh "$@" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment