Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
import itertools
import logging
import os
import requests
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'{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:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment