示例#1
0
def add_Supplier(args, config):
    pt_id = args.pt_id
    supplier_id = args.supplier_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_supplier(pt_id, supplier_id, private_key,
                                           public_key)
            print_msg(response)
        else:
            print(output)
    else:
        print(output)
示例#2
0
def add_Supplier(args, config):
    pt_id = args.pt_id
    supplier_id = args.supplier_id

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

    client = PartBatch(base_url=url, keyfile=key_file)
    response = client.add_supplier(pt_id, supplier_id)

    print_msg(response)