Skip to content

Instantly share code, notes, and snippets.

@samdbmg
Created April 23, 2017 10:07
Show Gist options
  • Save samdbmg/37eec34b66574345b5bd55918a4e17f8 to your computer and use it in GitHub Desktop.
Save samdbmg/37eec34b66574345b5bd55918a4e17f8 to your computer and use it in GitHub Desktop.
Codenvy GIT_SSH script to get private key
#!/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