Skip to content

Instantly share code, notes, and snippets.

@sirosen
Created August 13, 2020 15:11
Show Gist options
  • Save sirosen/0088ad2761e742e4082d9ca2c9b5a8fd to your computer and use it in GitHub Desktop.
Save sirosen/0088ad2761e742e4082d9ca2c9b5a8fd to your computer and use it in GitHub Desktop.
get-subscription-ids from Globus Transfer
#!/usr/bin/env python3
import sys
import globus_sdk
CLIENT_ID = "5f50cf96-04f9-4223-97f7-7d288d132b34"
UUIDLEN = len(CLIENT_ID)
def login_and_get_client():
client = globus_sdk.NativeAppAuthClient(CLIENT_ID)
client.oauth2_start_flow()
authorize_url = client.oauth2_get_authorize_url()
print(f"Please go to this URL and login:\n{authorize_url}", file=sys.stderr)
auth_code = input("Please enter the code you get after login here: ").strip()
token_response = client.oauth2_exchange_code_for_tokens(auth_code)
globus_transfer_data = token_response.by_resource_server["transfer.api.globus.org"]
token = globus_transfer_data["access_token"]
return globus_sdk.TransferClient(authorizer=globus_sdk.AccessTokenAuthorizer(token))
def main():
tc = login_and_get_client()
data = tc.get("/private/my_subscriptions")["DATA"]
print("subscription_id".ljust(UUIDLEN) + " | ha")
print("-" * UUIDLEN + "-|------")
for item in data:
print(f"{item['id']} | {item['high_assurance']}")
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment