Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import itertools
import logging
import os
import requests
logging.basicConfig(level=logging.DEBUG)
session = requests.Session()
def github_api_token():
return os.environ['GITHUB_API_TOKEN']
def github_org():
return os.environ['GITHUB_ORG']
def request(method, endpoint, **kwargs):
return session.request(method, f'https://api.github.com{endpoint}',
headers={'authorization': f'Bearer {github_api_token()}'}, **kwargs)
def users():
return request('GET', f'/orgs/{github_org()}/members').json()
def ssh_keys(login):
return request('GET', f'/users/{login}/keys').json()
users_ssh_keys = {user['login']: ssh_keys(user['login']) for user in users()}
for user, ssh_keys in users_ssh_keys.items():
if ssh_keys != []:
print(f'# {user}')
for ssh_key in ssh_keys:
print(ssh_key['key'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment