def do_register_init(args, config): priv_key = signing.generate_privkey() pub_key = signing.generate_pubkey(priv_key) user_public_key = args.user_public_key user_name = args.user_name email_address = args.email_address authorized = args.authorized role = args.role cmd = "user list-user" cmd = shlex.split(cmd) process = subprocess.Popen(cmd, stdout=subprocess.PIPE) process.wait() output = '' for line in process.stdout: output += line.decode("utf-8").strip() if output == "[]" and role == "admin" and len(user_public_key) == 66: url = config.get('DEFAULT', 'url') client = UserBatch(base_url=url) response = client.register_user(user_public_key, user_name, email_address, authorized, role, priv_key, pub_key) print_msg(response) else: print(ret_access_denied__msg('Invalid operation.'))
def do_list_user(args, config): url = config.get('DEFAULT', 'url') client = UserBatch(base_url=url) user_list = client.list_user() if user_list is not None: output = refine_output(str(user_list)) print(output) else: raise UserException("Could not retrieve user list.")
def do_retrieve_user(args, config): user_public_key = args.user_public_key url = config.get('DEFAULT', 'url') client = UserBatch(base_url=url) data = client.retreive_user(user_public_key) if data is not None: output = filter_output(str(data)) print(output) else: raise UserException("User not found: {}".format(user_public_key))
def do_register_user(args, config): user_public_key = args.user_public_key user_name = args.user_name email_address = args.email_address authorized = args.authorized role = args.role ad_private_key = args.ad_private_key ad_public_key = args.ad_public_key # # # context = create_context('secp256k1') # user_private_key = context.new_random_private_key() # user_public_key = context.get_public_key(user_private_key) # # if len(user_public_key) == 66: payload = "{}" key = json.loads(payload) key["publickey"] = ad_public_key key["privatekey"] = ad_private_key key["allowedrole"] = [{"role": "admin"}] payload = json.dumps(key) headers = {'content-type': 'application/json'} response = requests.post("http://127.0.0.1:818/api/sparts/ledger/auth", data=json.dumps(key), headers=headers) output = response.content.decode("utf-8").strip() statusinfo = json.loads(output) if statusinfo.get('status') and statusinfo.get('message'): status = statusinfo['status'] message = statusinfo['message'] if status == 'success' and message == 'authorized': b_url = config.get('DEFAULT', 'url') client = UserBatch(base_url=b_url) response = client.register_user(user_public_key, user_name, email_address, authorized, role, ad_private_key, ad_public_key) print_msg(response) else: print(output) else: print(output) else: print(ret_access_denied__msg('Invalid key'))