diff options
author | Lars Wirzenius <liw@liw.fi> | 2018-11-05 10:36:02 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2018-11-05 10:36:02 +0200 |
commit | 82aa16698668375881e9edcab46965e4be3f5b83 (patch) | |
tree | 855cb8434e8cee343c1d7435337fe3af440a217f /yarns/lib.py | |
parent | 782d42ef1ee0c7edb2a9cf68a24ea5ba60eca8cc (diff) | |
download | muck-poc-82aa16698668375881e9edcab46965e4be3f5b83.tar.gz |
Add: owner metadata
Diffstat (limited to 'yarns/lib.py')
-rw-r--r-- | yarns/lib.py | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/yarns/lib.py b/yarns/lib.py index ee36f9f..583dff5 100644 --- a/yarns/lib.py +++ b/yarns/lib.py @@ -59,21 +59,18 @@ def start_muck(): subprocess.check_call(argv) V['base_url'] = 'http://127.0.0.1:{}'.format(12765) - V['token'] = create_test_token() - def stop_muck(): pid = int(read('muck.pid')) os.kill(pid, signal.SIGTERM) -def create_test_token(): +def create_test_token(sub): key_filename = os.path.join(srcdir, 'test-key') key_text = open(key_filename).read() iss = 'test-issuer' aud = 'test-audience' - sub = 'test-user' scopes = ['create', 'update', 'show', 'delete'] lifetime = 3600 @@ -95,28 +92,29 @@ def create_token(key_text, iss, aud, sub, scopes, lifetime): return token.decode('ascii') -def POST(path, headers, body): - return request(requests.post, path, headers, body) +def POST(sub, path, headers, body): + return request(sub, requests.post, path, headers, body) -def PUT(path, headers, body): - return request(requests.put, path, headers, body) +def PUT(sub, path, headers, body): + return request(sub, requests.put, path, headers, body) -def GET(path, headers, body=None): - return request(requests.get, path, headers, body=body) +def GET(sub, path, headers, body=None): + return request(sub, requests.get, path, headers, body=body) -def DELETE(path, headers): - return request(requests.delete, path, headers) +def DELETE(sub, path, headers): + return request(sub, requests.delete, path, headers) -def request(func, path, headers, body=None): +def request(sub, func, path, headers, body=None): url = '{}{}'.format(V['base_url'], path) if 'Content-Type' not in headers: headers['Content-Type'] = json_mime_type if 'Authorization' not in headers: - headers['Authorization'] = 'Bearer {}'.format(V['token']) + token = create_test_token(sub) + headers['Authorization'] = 'Bearer {}'.format(token) if body is not None: body = json.dumps(body) V['request_url'] = url |