Added Proxy parameter to allow usage of proxy configuration
This commit is contained in:
@@ -4,10 +4,11 @@ from cryptography.hazmat.primitives.serialization import pkcs12, pkcs7
|
||||
from cryptography.hazmat.primitives import hashes, serialization
|
||||
|
||||
class AirwatchAPI:
|
||||
def __init__(self, Server, APIKey, AuthMethod, APIUser=None, APIPassword=None, CertPath=None, CertPass=""):
|
||||
def __init__(self, Server, APIKey, AuthMethod, APIUser=None, APIPassword=None, CertPath=None, CertPass="", Proxy={}):
|
||||
self.Server = Server
|
||||
self.APIKey = APIKey
|
||||
self.AuthMethod = (AuthMethod).upper()
|
||||
self.Proxy = Proxy
|
||||
|
||||
if(self.AuthMethod == "PASSWORD"):
|
||||
self.APIUser = APIUser
|
||||
@@ -45,7 +46,7 @@ class AirwatchAPI:
|
||||
cmdURI = f'/API/system/users/search?username={username}'
|
||||
airwatchHeaders = self.GetHeaders(cmdURI)
|
||||
uri = f"{self.Server}{cmdURI}"
|
||||
user = requests.get(uri, headers=airwatchHeaders)
|
||||
user = requests.get(uri, headers=airwatchHeaders, proxies=self.Proxy)
|
||||
if(user.status_code == 200):
|
||||
return AirwatchUser(user.json()["Users"][0])
|
||||
|
||||
@@ -60,24 +61,36 @@ class AirwatchAPI:
|
||||
pageNum = 0
|
||||
devices = []
|
||||
uri = f"{self.Server}{cmdURI}{pageNum}"
|
||||
result = requests.get(uri, headers=airwatchHeaders)
|
||||
result = requests.get(uri, headers=airwatchHeaders, proxies=self.Proxy)
|
||||
if(result.status_code == 200):
|
||||
deviceTotalCount = result.json()["Total"]
|
||||
|
||||
while(len(devices) != deviceTotalCount):
|
||||
uri = f"{self.Server}{cmdURI}{pageNum}"
|
||||
result = requests.get(uri, headers=airwatchHeaders).json()["Devices"]
|
||||
result = requests.get(uri, headers=airwatchHeaders, proxies=self.Proxy).json()["Devices"]
|
||||
for device in result:
|
||||
devices += [AirwatchDevice(device)]
|
||||
pageNum += 1
|
||||
return devices
|
||||
return None
|
||||
|
||||
def GetBitlocker(self, deviceUuid):
|
||||
cmdURI = f"/api/mdm//devices/{deviceUuid}/bitlocker/drives"
|
||||
airwatchHeaders = self.GetHeaders(cmdURI)
|
||||
uri = f"{self.Server}{cmdURI}"
|
||||
result = requests.get(uri, headers=airwatchHeaders, proxies=self.Proxy)
|
||||
bitlocker_info = {}
|
||||
return result
|
||||
if(result.status_code == 200):
|
||||
bitlocker_info = result.json()["drive_information"][0]
|
||||
return bitlocker_info
|
||||
|
||||
|
||||
def GetTagDevices(self, tagID):
|
||||
cmdURI = f"/api/mdm/tags/{tagID}/devices"
|
||||
airwatchHeaders = self.GetHeaders(cmdURI)
|
||||
uri = f"{self.Server}{cmdURI}"
|
||||
result = requests.get(uri, headers=airwatchHeaders)
|
||||
result = requests.get(uri, headers=airwatchHeaders, proxies=self.Proxy)
|
||||
devices = []
|
||||
if(result.status_code == 200):
|
||||
for dev in result.json()["Device"]:
|
||||
@@ -90,7 +103,7 @@ class AirwatchAPI:
|
||||
airwatchHeaders = self.GetHeaders(cmdURI)
|
||||
uri = f"{self.Server}{cmdURI}"
|
||||
apps = []
|
||||
result = requests.get(uri, headers=airwatchHeaders)
|
||||
result = requests.get(uri, headers=airwatchHeaders, proxies=self.Proxy)
|
||||
if(result.status_code == 200):
|
||||
for app in result.json()["app_items"]:
|
||||
apps += [AirwatchApplication(app)]
|
||||
@@ -101,7 +114,7 @@ class AirwatchAPI:
|
||||
cmdURI = f"/API/mdm/dep/groups/{groupUuid}/devices"
|
||||
uri = f"{self.Server}{cmdURI}"
|
||||
airwatchHeaders = self.GetHeaders(cmdURI)
|
||||
result = requests.get(uri, headers=airwatchHeaders)
|
||||
result = requests.get(uri, headers=airwatchHeaders, proxies=self.Proxy)
|
||||
if(result.status_code == 200):
|
||||
for device in result.json():
|
||||
if (device["enrollmentStatus"] != "Unenrolled"):
|
||||
@@ -109,7 +122,7 @@ class AirwatchAPI:
|
||||
assignDEPProfileURI = f"/API/mdm/dep/profiles/{device['profileUuid']}/devices/{device['deviceSerialNumber']}?action=Assign"
|
||||
uri = f"{airwatchServer}{assignDEPProfileURI}"
|
||||
airwatchHeaders = self.GetHeaders(assignDEPProfileURI)
|
||||
requests.put(uri, headers=airwatchHeaders)
|
||||
requests.put(uri, headers=airwatchHeaders, proxies=self.Proxy)
|
||||
return True
|
||||
return False
|
||||
|
||||
@@ -117,7 +130,7 @@ class AirwatchAPI:
|
||||
cmdURI = f"/API/mdm/groups/{groupUuid}/enrollment-tokens?device_type={deviceType}&page_size=500"
|
||||
uri = f"{self.Server}{cmdURI}"
|
||||
airwatchHeaders = self.GetHeaders(cmdURI)
|
||||
result = requests.get(uri, headers=airwatchHeaders)
|
||||
result = requests.get(uri, headers=airwatchHeaders, proxies=self.Proxy)
|
||||
return result.json()["tokens"]
|
||||
|
||||
def UpdateUserOnEnrollmentTokens(self, groupUuid,user, serialnumber):
|
||||
@@ -137,13 +150,13 @@ class AirwatchAPI:
|
||||
airwatchHeaders["Accept"] = "application/json;version=2"
|
||||
uri = f"{self.Server}{cmdURI}"
|
||||
print(uri)
|
||||
return requests.post(uri, headers=airwatchHeaders, json=body)
|
||||
return requests.post(uri, headers=airwatchHeaders, json=body, proxies=self.Proxy)
|
||||
|
||||
def SyncDEPDevices(self, groupUuid):
|
||||
cmdURI = f"/API/mdm/dep/groups/{groupUuid}/devices?action=sync"
|
||||
uri = f"{self.Server}{cmdURI}"
|
||||
airwatchHeaders = self.GetHeaders(cmdURI)
|
||||
return requests.put(uri, headers=airwatchHeaders).status_code
|
||||
return requests.put(uri, headers=airwatchHeaders, proxies=self.Proxy).status_code
|
||||
|
||||
def AddDevicesToTag(self, tagID, devices):
|
||||
cmdURI = f"/API/mdm/tags/{tagID}/adddevices"
|
||||
@@ -154,7 +167,7 @@ class AirwatchAPI:
|
||||
"Value": devices
|
||||
}
|
||||
}
|
||||
return requests.post(uri, headers=airwatchHeaders, json=body).status_code
|
||||
return requests.post(uri, headers=airwatchHeaders, json=body, proxies=self.Proxy).status_code
|
||||
|
||||
def SetDeviceFriendlyName(self, device, friendlyName):
|
||||
cmdURI = f"/API/mdm/devices/{device.Id}"
|
||||
@@ -163,19 +176,19 @@ class AirwatchAPI:
|
||||
body = {
|
||||
"DeviceFriendlyName":friendlyName
|
||||
}
|
||||
return requests.put(uri, headers=airwatchHeaders, json=body).status_code
|
||||
return requests.put(uri, headers=airwatchHeaders, json=body, proxies=self.Proxy).status_code
|
||||
|
||||
def SetDeviceUser(self, device, airwatchUser):
|
||||
cmdURI = f'/API/mdm/devices/{device.Id}/enrollmentuser/{airwatchUser.Id}'
|
||||
uri = f"{self.Server}{cmdURI}"
|
||||
airwatchHeaders = self.GetHeaders(cmdURI)
|
||||
return requests.patch(uri, headers=airwatchHeaders).status_code
|
||||
return requests.patch(uri, headers=airwatchHeaders, proxies=self.Proxy).status_code
|
||||
|
||||
def DeleteDevice(self, device):
|
||||
cmdURI = f"/API/mdm/devices/{device.Id}"
|
||||
airwatchHeaders = self.GetHeaders(cmdURI)
|
||||
uri = f"{self.Server}{cmdURI}"
|
||||
return requests.delete(uri, headers=airwatchHeaders).status_code
|
||||
return requests.delete(uri, headers=airwatchHeaders, proxies=self.Proxy).status_code
|
||||
|
||||
class AirwatchUser:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user