sio-2425/delivery1/client/bin/rep_list_orgs

34 lines
791 B
Plaintext
Raw Normal View History

2024-11-12 10:26:56 +00:00
#!/bin/python3
2024-11-17 20:18:02 +00:00
import os
2024-11-12 10:26:56 +00:00
import sys
import logging
import json
import requests
2024-11-17 20:18:02 +00:00
from subject import main
2024-11-12 10:26:56 +00:00
# Identity attributes
# {'username' : '', 'full_name' : '', 'email' : '', public_key : '' }
logging.basicConfig(format='%(levelname)s\t- %(message)s')
logger = logging.getLogger()
logger.setLevel(logging.INFO)
2024-11-17 20:18:02 +00:00
state = main(sys.argv)
2024-11-12 10:26:56 +00:00
def listOrganizations():
try:
orgs = requests.get(f'https://{state['REP_ADDRESS']}/org/list')
2024-11-12 10:26:56 +00:00
orgs.raise_for_status()
except requests.exceptions.RequestException as errex:
logger.error("Failed to obtain response from server.")
2024-11-20 20:49:40 +00:00
sys.exit(-1)
2024-11-12 10:26:56 +00:00
for org in orgs.json():
sys.stdout.write(str(org['id']) + " - " + org['name'])
2024-11-12 10:26:56 +00:00
2024-11-20 20:49:40 +00:00
sys.exit(0)
2024-11-12 10:26:56 +00:00
if __name__ == '__main__':
listOrganizations()