Created
December 7, 2020 21:20
-
-
Save drichardson/68dc5cd78cab5e736df6b0f5aa6b2d2d to your computer and use it in GitHub Desktop.
List github gpg public keys for a user
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
#!/usr/bin/python3 | |
import json | |
import sys | |
import urllib.request | |
import os | |
scriptname=os.path.basename(__file__) | |
usage=f'''Missing username. | |
USAGE | |
{scriptname} username | |
EXAMPLES | |
List drichardson's gpg public keys: | |
{scriptname} drichardson | |
View drichardson's gpg public keys with GnuPG: | |
{scriptname} drichardson | gpg | |
Import drichardson's gpg public keys to GnuPG: | |
{scriptname} drichardson | gpg --import | |
''' | |
if len(sys.argv) < 2: | |
sys.stderr.write(usage) | |
sys.exit(1) | |
username=sys.argv[1] | |
req = urllib.request.Request(f'https://api.github.com/users/{username}/gpg_keys') | |
req.add_header('Accept', 'application/vnd.github.v3+json') | |
with urllib.request.urlopen(req) as f: | |
for entry in json.load(f): | |
print(entry['raw_key']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment