Last active
May 12, 2022 16:08
-
-
Save jnahelou/94edfc8d79757af8e5f162ca9cb8f808 to your computer and use it in GitHub Desktop.
List users with ssh keys
This file contains 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 googleapiclient.discovery | |
compute_v1 = googleapiclient.discovery.build( | |
"compute", "v1", cache_discovery=False | |
) | |
project_id = "<project_id>" | |
project_info = compute_v1.projects().get(project=project_id).execute() | |
for metadata in project_info["commonInstanceMetadata"].get("items", []): | |
if metadata["key"] == "ssh-keys": | |
users = [] | |
for google_key in metadata["value"].split('\n'): | |
# Add expireOn exclusion ? | |
users.append( google_key.split(':')[0]) | |
print('{},{}'.format(project_id, ';'.join(users))) |
This file contains 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
google-api-python-client |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment