-
Notifications
You must be signed in to change notification settings - Fork 10
/
test_api_rights.py
79 lines (71 loc) · 3.06 KB
/
test_api_rights.py
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import requests
import json
import urllib3
urllib3.disable_warnings()
"""
### Django Shell Code to create the test users (run there first)
for i in range(0, 6):
...: username = "__api_user_{id}[email protected]".format(id=i)
...: email = username
...: u = User.objects.create(username=username, email=email)
...: u.confirm_email(u.confirmation_key)
...: u.set_password("password{id}".format(id=i))
...: u.save()
...: p, _ = UserProfile.create_user_profile(user=u, display_name=username)
...: p.assign_role(i)
"""
users = [
dict(role='Server Admin', username='[email protected]', password='password0'),
dict(role='Steward', username='[email protected]', password='password1'),
dict(role='Catalog Admin', username='[email protected]', password='password2'),
dict(role='Viewer', username='[email protected]', password='password3'),
dict(role='Composer', username='[email protected]', password='password4'),
dict(role='Source Admin', username='[email protected]', password='password5')
]
url = 'https://ec2-18-218-6-215.us-east-2.compute.amazonaws.com'
ds_id = 70
api_list = [
f'/integration/v1/datasource/{ds_id}',
f'/integration/v1/schema/?ds_id={ds_id}',
f'/integration/v1/table/?ds_id={ds_id}',
f'/integration/v1/column/?ds_id={ds_id}',
'/integration/v1/article/',
'/integration/v1/custom_template/',
'/integration/v2/bi/server/',
'/integration/v1/user/',
'/integration/v2/dataflow/'
]
for role in users:
print('---------------------')
print(role['role'])
r = requests.post(url=url+'/integration/v1/createRefreshToken/',
json=dict(username=role['username'],
password=role['password'],
name=f"API Token for {role['username']}"),
verify=False)
refresh_token = r.json().get('refresh_token')
user_id = r.json().get('user_id')
print(f"Created a refresh token for user ID {user_id}")
r = requests.post(url=url+'/integration/v1/createAPIAccessToken/',
json=dict(refresh_token=refresh_token,
user_id=user_id),
verify=False)
api_access_token = r.json().get('api_access_token')
print('---------------------')
for a in api_list:
url_ = url + a
r = requests.get(url=url_,
headers=dict(token=api_access_token),
params=dict(limit=25),
verify=False)
if r.status_code==500:
print(f"Request = {r.request.url} Status code {r.status_code} with {r.content}.")
continue
r_parsed = json.loads(r.content)
if isinstance(r_parsed, list):
print(f"Request = {r.request.url} Status code {r.status_code} with {len(r_parsed)} items.")
# if len(r_parsed)<=50:
# for i in r_parsed:
# print(i)
else:
print(f"Request = {r.request.url} Status code {r.status_code} with {r_parsed}.")