-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy patht-04-token-03-delete.py
More file actions
executable file
·39 lines (35 loc) · 954 Bytes
/
t-04-token-03-delete.py
File metadata and controls
executable file
·39 lines (35 loc) · 954 Bytes
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
#!/usr/bin/env vpython3
import json
import rlogger
import requests
import sys
from ksefconfig import Config
def main():
cfg = Config(int(sys.argv[1]), False)
with open(f'{cfg.prefix}-auth.json', 'rt') as fp:
auth = json.loads(fp.read())
token = sys.argv[2]
resp = requests.delete(
cfg.url+f'/tokens/{token}',
headers={
"Authorization": "Bearer "+auth['accessToken']['token'],
},
timeout=5
)
print('tokens:', resp)
if resp.status_code != 200:
print(resp.text)
print(resp.headers)
return
else:
data = resp.json()
print(data)
with open(f'{cfg.prefix}-tokens.json', 'rt') as fp:
tokens = json.loads(fp.read())
try:
del tokens[token]
except KeyError as exc:
pass
with open(f'{cfg.prefix}-tokens.json', 'wt') as fp:
fp.write(json.dumps(tokens))
main()