#!/usr/bin/env bash # # Author: Hari Sekhon # Date: 2019-09-18 # # https://github.com/HariSekhon/DevOps-Bash-tools # # License: see accompanying LICENSE file # # https://www.linkedin.com/in/HariSekhon # # https://docs.github.com/en/free-pro-team@latest/rest/reference/users#list-public-ssh-keys-for-the-authenticated-user set -euo pipefail [ -n "${DEBUG:-}" ] && set -x srcdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" usage(){ cat <&2 user="$("$srcdir/github_api.sh" "/user" | jq -r '.login')" # XXX: not handling paging because if you have > 100 SSH keys I want to know what is going on first! echo "# Fetching SSH Public Key(s) from GitHub for the currently authenticated account" >&2 echo "#" >&2 "$srcdir/github_api.sh" "/user/keys" | # doesn't give any more info #jq -r '.[].id' | #while read -r id; do # "$srcdir/github_api.sh" "/user/keys/$id" | # jq . #done jq -r '.[] | [.key, .title] | @tsv' | tr '\t' ' ' | sed "s|$| (github.com/$user)|"