sio-2425/delivery1/client/bin/rep_create_org

44 lines
1.2 KiB
Plaintext
Raw Normal View History

2024-11-12 10:26:56 +00:00
#!/bin/python3
import os
import sys
import logging
import requests
import json
import re
logging.basicConfig(format='%(levelname)s\t- %(message)s')
logger = logging.getLogger()
logger.setLevel(logging.INFO)
state = {}
# Create organization
def createOrganization(args):
# {'name', 'username' , 'full_name', 'email' , 'public_key' }
if len(args) != 5:
logger.error("Missing parameters. Expected: 'name' 'username' 'full name' 'email' 'public key' ")
sys.exit(-1)
for item in args:
if item == '':
logger.error("Need a valid " + item)
sys.exit(-1)
input = {'name' : args[0], 'username' : args[1], 'full_name' : args[2], 'email' : args[3], 'public_key' : args[4]}
if not re.match(r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$', input['email']):
logger.error("Need a valid email.")
sys.exit(-1)
if (not os.path.isfile(input['public_key'])):
logger.error("File '" + input['public_key'] + "' not found.")
sys.exit(-1)
req = requests.post(f'http://{state['REP_ADDRESS']}/organization/create', json=json.dumps(input))
if __name__ == '__main__':
createOrganization(sys.argv[1:])