-
Notifications
You must be signed in to change notification settings - Fork 0
/
jamf_api.py
78 lines (58 loc) · 3.15 KB
/
jamf_api.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
import requests
from requests.auth import HTTPBasicAuth
import getpass
from datetime import datetime, timedelta
class UserSession:
def __init__(self, *args):
self.username = args
self.password = args
self.token = args
self.token_exp_epoc = args
def jamf_auth():
session = UserSession()
session.username = input("[?] Enter Jamf Pro username:")
pwd = getpass.getpass("[?] Enter Jamf Pro password:")
while True:
response = requests.post(f"{JPSURL}/api/auth/tokens",
auth=HTTPBasicAuth(session.username, pwd),
headers={'Accept': 'application/json',
'Content-Type': 'application/json'})
if response.status_code == 200:
session.password = pwd
session.token_exp_epoc = datetime.fromtimestamp(int(response.json()["expires"] / 1000)) + timedelta(hours=1)
session.token = response.json()["token"]
print(f"\n[*] Login successful. You session will expire at {session.token_exp_epoc} GMT +2")
del pwd
return session
elif response.status_code == 401:
print(f"\n[!] The password for {session.username} was incorrect. Please try again")
pwd = getpass.getpass(f"[?] Enter password for {session.username}:")
else:
print(f"\n[!] Hmm... Something is not right. We had an HTTP Error {response.status_code}. Please "
f"investigate.")
exit(1)
def jamf_provisioning_profiles(session):
response = requests.get(f"{JPSURL}/JSSResource/mobiledeviceprovisioningprofiles",
auth=HTTPBasicAuth(session.username, session.password),
headers={'Accept': 'application/json',
'Content-Type': 'application/json'}).json()
return response['mobile_device_provisioning_profiles']
def jamf_mobiledeviceapps(session):
response = requests.get(f"{JPSURL}/JSSResource/mobiledeviceapplications",
auth=HTTPBasicAuth(session.username, session.password),
headers={'Accept': 'application/json',
'Content-Type': 'application/json'}).json()
return response['mobile_device_applications']
def jamf_mobiledeviceapp(session, id):
response = requests.get(f"{JPSURL}/JSSResource/mobiledeviceapplications/id/{id}",
auth=HTTPBasicAuth(session.username, session.password),
headers={'Accept': 'application/json',
'Content-Type': 'application/json'})
return response.json()['mobile_device_application']["general"]
def jamf_update_mobiledeviceapp(session, id, data):
response = requests.put(f"{JPSURL}/JSSResource/mobiledeviceapplications/id/{id}",
data=data,
auth=HTTPBasicAuth(session.username, session.password),
headers={'Accept': 'application/xml',
'Content-Type': 'application/xml'})
#print(response)