Ejemplo n.º 1
0
def add_Category(args, config):
    pt_id = args.pt_id
    category_id = args.category_id
    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':
            url = config.get('DEFAULT', 'url')
            client = PartBatch(base_url=url)
            response = client.add_category(pt_id, category_id, private_key,
                                           public_key)
            print_msg(response)
        else:
            print(output)
    else:
        print(output)
Ejemplo n.º 2
0
def do_add_category(args, config):
    """
    Establishes relationship between Part and Category in the state associating
    with the UUID of the Transaction Family : Part
    
    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.
    
    """
    deleteCat   = args.delete
    
    pt_id       = args.pt_id
    category_id = args.category_id
    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 = PartBatch(base_url=b_url)
            response = client.add_category(
                                pt_id, category_id, private_key, public_key,
                                deleteCat
                            )
                            
            print_msg(response, "AddCategory")
        else:
            print(output)
    else:
        print(output)      
Ejemplo n.º 3
0
def add_Category(args, config):
    pt_id = args.pt_id
    category_id = args.category_id

    url = config.get('DEFAULT', 'url')
    key_file = config.get('DEFAULT', 'key_file')

    client = PartBatch(base_url=url, keyfile=key_file)
    response = client.add_category(pt_id, category_id)

    print_msg(response)
Ejemplo n.º 4
0
def api_do_add_category(args, config, del_flag=False):
    """
    API version of "do_add_category" function.
    """
    param_check = _payload_check_(args, cmd="AddCategory")
    
    if param_check[0]:
        return ret_msg("failed", param_check[1], "EmptyRecord", "{}")
    
    pt_id       = args["relation"]["part_uuid"]
    category_id = args["relation"]["category_uuid"]
    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 = PartBatch(base_url=b_url)
            response = client.add_category(
                                pt_id, category_id, private_key, public_key,
                                del_flag
                            )
                            
            return print_msg(response, "AddCategory")
        else:
            return output
    else:
        return output