-
Notifications
You must be signed in to change notification settings - Fork 0
/
sp_decommission.py
56 lines (45 loc) · 1.24 KB
/
sp_decommission.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
import requests
import json
import uuid, sys, time
def get_jwt(tenant, key):
url = "https://ztadmin.ericomcloud.net/api/v1/auth"
payload = json.dumps({
"tenantID": tenant,
"key": key
})
headers = {
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
jwt = response.json()['JWT']
cookie = response.cookies['route']
return jwt, cookie
def logout(jwt):
url = "https://ztadmin.ericomcloud.net/api/v1/auth"
headers = {
'Content-Type': 'application/json',
'Authorization': (f'Bearer {jwt}')
}
response = requests.request("DELETE", url, headers=headers)
return response
def usage():
print("Usage: python3 sp_decommission.py <Tenant ID> <API Key>")
if __name__ == "__main__":
try:
auth_tenant = sys.argv[1]
except:
print("Tenant ID missing")
usage()
exit(1)
try:
key = sys.argv[2]
except:
print("API Key missing")
usage()
exit(1)
print("Authenticating and retrieving token...")
jwt, cookie = get_jwt(auth_tenant, key)
print("Decommissioning...")
#TBD enter code here for decomm
print("Done!")
logout(jwt)