def do_create_category(args, config): """ Creates the state associating with the UUID in the Transaction Family : Category Args: args (ArgumentParser): ArgumentParser object containing required parameters config (ConfigParser): ConfigParser which contains the default url Returns: type: str String representing JSON object which allows the client to know that the call was either a success or a failure. """ category_id = args.category_id category_name = args.category_name description = args.description private_key = args.private_key public_key = args.public_key payload = "{}" key = json.loads(payload) key["publickey"] = public_key key["privatekey"] = private_key key["allowedrole"] = [{"role": "admin"}, {"role": "member"}] 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 = CategoryBatch(base_url=b_url) response = client.create_category(category_id, category_name, description, private_key, public_key) print_msg(response, "create") else: print(output) else: print(output)
def api_do_create_category(args, config): """ API version of "do_create_category" function. """ param_check = _payload_check_(args, creation=True) if param_check[0]: return ret_msg("failed", param_check[1], "EmptyRecord", "{}") category_id = args["category"]["uuid"] category_name = args["category"]["name"] description = args["category"]["description"] private_key = args["private_key"] public_key = args["public_key"] payload = "{}" key = json.loads(payload) key["publickey"] = public_key key["privatekey"] = private_key key["allowedrole"] = [{"role": "admin"}, {"role": "member"}] 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 = CategoryBatch(base_url=b_url) response = client.create_category(category_id, category_name, description, private_key, public_key) return print_msg(response, "create") else: return output else: return output
def do_create_category(args, config): category_id = args.category_id category_name = args.category_name description = args.description url = config.get('DEFAULT', 'url') key_file = config.get('DEFAULT', 'key_file') auth_user, auth_password = _get_auth_info(args) client = CategoryBatch(base_url=url, keyfile=key_file) response = client.create_category(category_id, category_name, description, auth_user=auth_user, auth_password=auth_password) print_msg(response)
def do_create_category(args, config): category_id = args.category_id category_name = args.category_name description = args.description private_key = args.private_key public_key = args.public_key # context = create_context('secp256k1') # # # private_key = context.new_random_private_key() # public_key = context.get_public_key(private_key) # # payload = "{}" key = json.loads(payload) key["publickey"] = public_key key["privatekey"] = private_key key["allowedrole"]=[{"role":"admin"},{"role":"member"}] 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 = CategoryBatch(base_url=b_url) response = client.create_category(category_id,category_name,description,private_key,public_key) print_msg(response) else: print(output) else: print(output)
def do_create_category(args, config): category_id = args.category_id category_name = args.category_name description = args.description private_key = args.private_key public_key = args.public_key payload = "{}" key = json.loads(payload) key["publickey"] = public_key key["privatekey"] = private_key key["allowedrole"] = [{"role":"admin"}, {"role":"member"}] 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 = CategoryBatch(base_url=b_url) response = client.create_category(category_id, category_name, description, private_key, public_key) print_msg(response) else: print(output) else: print(output)