Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 39 additions & 5 deletions ssh-key-experiment.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
. ./.gh-api-examples.conf

echo you probably should not need this script
exit

# https://docs.github.com/en/enterprise-cloud@latest/rest/deploy-keys/deploy-keys?apiVersion=2022-11-28#create-a-deploy-key
# POST /repos/{owner}/{repo}/keys
# As per the documentation the app will need at least "Administration" permission on the repository.

public_key_file=${1:-${my_ssh_pub_key}}
public_key=$(cat ${public_key_file})
ts=$(date +%s)

ssh_key_file=tmp/ed25519_${default_app_id}
ssh_public_key_file=tmp/ed25519_${default_app_id}.pub
ssh_key_file=~/.ssh/ed25519
ssh_public_key_file=~/.ssh/ed25519.pub
rm -f ${ssh_key_file} ${ssh_public_key_file}
echo $?

ssh-keygen -t ed25519 -f ${ssh_key_file} -q -N '' -C "crispy-key-${ts}"
echo $?

ssh-keygen -l -v -f ${ssh_public_key_file}
echo $?

public_key=$(cat ${ssh_public_key_file})

Expand All @@ -24,8 +29,37 @@ jq -n \
--arg key "${public_key}" \
'{title: $title, key: $key}' > ${json_file}

cat $json_file | jq -r


# Set this if you are using an oauth token
#GITHUB_TOKEN=
echo "Sending with token ${GITHUB_TOKEN:0:4}...${GITHUB_TOKEN: -8}"


curl ${curl_custom_flags} \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
-H "Accept: application/vnd.github.v3+json" \
${GITHUB_API_BASE_URL}/user/keys --data @${json_file}
"${GITHUB_API_BASE_URL}/user/keys" --data @${json_file}

echo $?

ssh_cf=~/.ssh/config
rm -f ${ssh_cf}

echo ==============
echo $ssh_key_file
echo $ssh_public_key_file
echo ==============
echo " Creating ssh config file"
echo host github.com > ${ssh_cf}
echo HostName github.com >> ${ssh_cf}
echo IdentityFile ${ssh_key_file} >> ${ssh_cf}
echo
echo
ssh -T [email protected]
echo
echo
rm -rf $repo
echo "cloning"
git clone [email protected]:${org}/${repo}.git