Last active
March 24, 2020 12:56
-
-
Save lukateras/b888913b01214c44ec79eaa68e6f2a51 to your computer and use it in GitHub Desktop.
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
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