blob: 77c9ab8d1a3e009bc8d419c5c0216bc6670f0837 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
#!/usr/bin/env python3
import logging
import sys
import urllib3
import requests
# We do not currently care about verify certificates. Maybe later.
# FIXME: Remove these once we have proper certificates for everything,
# including test instances of Qvarn.
urllib3.disable_warnings()
logging.captureWarnings(True)
baseurl, user, secret = sys.argv[1:4]
scopes = sys.argv[4:]
url = '{}/token'.format(baseurl)
auth = (user, secret)
data = {
'grant_type': 'client_credentials',
'scope': ' '.join(scopes),
}
r = requests.post(url, auth=auth, data=data, verify=False)
if r.ok:
obj = r.json()
print(obj['access_token'])
else:
sys.stderr.write(r.text)
sys.stderr.write('\n')
sys.exit(1)
|