Esempio n. 1
0
def HAWK_GET(api, id, key, versioned="v1/"):
    url = BASEURL + versioned + api
    print "HAWK_GET", url
    creds = {"id": id.encode("hex"), "key": key, "algorithm": "sha256"}
    header = hawk_client.header(url, "GET", {"credentials": creds, "ext": ""})
    r = requests.get(url, headers={"authorization": header["field"]})
    if r.status_code != 200:
        raise WebError(r)
    return r.json()
Esempio n. 2
0
def HAWK_GET(api, id, key):
    creds = {"id": id.encode("hex"),
             "key": key.encode("hex"), # TODO: this should not be encoded,
                                       # the server has a bug that needs it
             "algorithm": "sha256"
             }
    header = hawk_client.header(BASEURL+api, "GET", {"credentials": creds,
                                                     "ext": ""})
    r = requests.get(BASEURL+api, headers={"authorization": header["field"]})
    assert r.status_code == 200, (r, r.content)
    return r.json()
Esempio n. 3
0
def HAWK_GET(api, id, key, versioned="v1/"):
    url = BASEURL+versioned+api
    print "HAWK_GET", url
    creds = {"id": id.encode("hex"),
             "key": key,
             "algorithm": "sha256"
             }
    header = hawk_client.header(url, "GET", {"credentials": creds,
                                             "ext": ""})
    r = requests.get(url, headers={"authorization": header["field"]})
    assert r.status_code == 200, (r, r.content)
    return r.json()
Esempio n. 4
0
def HAWK_POST(api, id, key, body_object, versioned="v1/"):
    url = BASEURL+versioned+api
    print "HAWK_POST", url
    body = json.dumps(body_object)
    creds = {"id": id.encode("hex"),
             "key": key,
             "algorithm": "sha256"
             }
    header = hawk_client.header(url, "POST",
                                {"credentials": creds,
                                 "ext": "",
                                 "payload": body,
                                 "contentType": "application/json"})
    r = requests.post(url, headers={"authorization": header["field"],
                                    "content-type": "application/json"},
                      data=body)
    assert r.status_code == 200, (r, r.content)
    return r.json()
Esempio n. 5
0
def HAWK_POST(api, id, key, body_object, versioned="v1/"):
    url = BASEURL + versioned + api
    print "HAWK_POST", url
    body = json.dumps(body_object)
    creds = {"id": id.encode("hex"), "key": key, "algorithm": "sha256"}
    header = hawk_client.header(
        url, "POST", {
            "credentials": creds,
            "ext": "",
            "payload": body,
            "contentType": "application/json"
        })
    r = requests.post(url,
                      headers={
                          "authorization": header["field"],
                          "content-type": "application/json"
                      },
                      data=body)
    if r.status_code != 200:
        raise WebError(r)
    return r.json()