Compare commits
9 Commits
1.01
...
a6727b9538
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a6727b9538 | ||
| 8bf9f9c620 | |||
| 1cdfbc6dc5 | |||
|
|
90378bb2e5 | ||
|
|
f34f1ae793 | ||
| e53af9bb26 | |||
|
|
f5abc6f0f4 | ||
|
|
14b48e7f41 | ||
|
|
930927b489 |
@@ -10,7 +10,7 @@ jobs:
|
|||||||
uses: actions/checkout@main
|
uses: actions/checkout@main
|
||||||
- name: Building the package
|
- name: Building the package
|
||||||
run: |
|
run: |
|
||||||
mv ${{ gitea.workspace }}\AirwatchAPI.py ${{ gitea.workspace }}\build\src\AirwatchAPI\
|
powershell mv ${{ gitea.workspace }}\AirwatchAPI.py build\src\AirwatchAPI\
|
||||||
cd ${{ gitea.workspace }}\build
|
cd ${{ gitea.workspace }}\build
|
||||||
python -m build
|
python -m build
|
||||||
- name: Publish package
|
- name: Publish package
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ variables:
|
|||||||
build: # This job runs in the build stage, which runs first.
|
build: # This job runs in the build stage, which runs first.
|
||||||
script:
|
script:
|
||||||
- pip install build twine
|
- pip install build twine
|
||||||
- mkdir build/src/AirwatchAPI/
|
|
||||||
- mv AirwatchAPI.py build/src/AirwatchAPI/
|
- mv AirwatchAPI.py build/src/AirwatchAPI/
|
||||||
- cd build/
|
- cd build/
|
||||||
- python -m build
|
- python -m build
|
||||||
|
|||||||
@@ -4,10 +4,11 @@ from cryptography.hazmat.primitives.serialization import pkcs12, pkcs7
|
|||||||
from cryptography.hazmat.primitives import hashes, serialization
|
from cryptography.hazmat.primitives import hashes, serialization
|
||||||
|
|
||||||
class AirwatchAPI:
|
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.Server = Server
|
||||||
self.APIKey = APIKey
|
self.APIKey = APIKey
|
||||||
self.AuthMethod = (AuthMethod).upper()
|
self.AuthMethod = (AuthMethod).upper()
|
||||||
|
self.Proxy = Proxy
|
||||||
|
|
||||||
if(self.AuthMethod == "PASSWORD"):
|
if(self.AuthMethod == "PASSWORD"):
|
||||||
self.APIUser = APIUser
|
self.APIUser = APIUser
|
||||||
@@ -45,7 +46,7 @@ class AirwatchAPI:
|
|||||||
cmdURI = f'/API/system/users/search?username={username}'
|
cmdURI = f'/API/system/users/search?username={username}'
|
||||||
airwatchHeaders = self.GetHeaders(cmdURI)
|
airwatchHeaders = self.GetHeaders(cmdURI)
|
||||||
uri = f"{self.Server}{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):
|
if(user.status_code == 200):
|
||||||
return AirwatchUser(user.json()["Users"][0])
|
return AirwatchUser(user.json()["Users"][0])
|
||||||
|
|
||||||
@@ -60,25 +61,49 @@ class AirwatchAPI:
|
|||||||
pageNum = 0
|
pageNum = 0
|
||||||
devices = []
|
devices = []
|
||||||
uri = f"{self.Server}{cmdURI}{pageNum}"
|
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):
|
if(result.status_code == 200):
|
||||||
deviceTotalCount = result.json()["Total"]
|
deviceTotalCount = result.json()["Total"]
|
||||||
|
|
||||||
while(len(devices) != deviceTotalCount):
|
while(len(devices) != deviceTotalCount):
|
||||||
uri = f"{self.Server}{cmdURI}{pageNum}"
|
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:
|
for device in result:
|
||||||
devices += [AirwatchDevice(device)]
|
devices += [AirwatchDevice(device)]
|
||||||
pageNum += 1
|
pageNum += 1
|
||||||
return devices
|
return devices
|
||||||
return None
|
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, proxies=self.Proxy)
|
||||||
|
devices = []
|
||||||
|
if(result.status_code == 200):
|
||||||
|
for dev in result.json()["Device"]:
|
||||||
|
devices += [dev["DeviceId"]]
|
||||||
|
return devices
|
||||||
|
return []
|
||||||
|
|
||||||
def GetDeviceApps(self, device):
|
def GetDeviceApps(self, device):
|
||||||
cmdURI = f"/api/mdm/devices/{device.Uuid}/apps/search"
|
cmdURI = f"/api/mdm/devices/{device.Uuid}/apps/search"
|
||||||
airwatchHeaders = self.GetHeaders(cmdURI)
|
airwatchHeaders = self.GetHeaders(cmdURI)
|
||||||
uri = f"{self.Server}{cmdURI}"
|
uri = f"{self.Server}{cmdURI}"
|
||||||
apps = []
|
apps = []
|
||||||
result = requests.get(uri, headers=airwatchHeaders)
|
result = requests.get(uri, headers=airwatchHeaders, proxies=self.Proxy)
|
||||||
if(result.status_code == 200):
|
if(result.status_code == 200):
|
||||||
for app in result.json()["app_items"]:
|
for app in result.json()["app_items"]:
|
||||||
apps += [AirwatchApplication(app)]
|
apps += [AirwatchApplication(app)]
|
||||||
@@ -89,7 +114,7 @@ class AirwatchAPI:
|
|||||||
cmdURI = f"/API/mdm/dep/groups/{groupUuid}/devices"
|
cmdURI = f"/API/mdm/dep/groups/{groupUuid}/devices"
|
||||||
uri = f"{self.Server}{cmdURI}"
|
uri = f"{self.Server}{cmdURI}"
|
||||||
airwatchHeaders = self.GetHeaders(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):
|
if(result.status_code == 200):
|
||||||
for device in result.json():
|
for device in result.json():
|
||||||
if (device["enrollmentStatus"] != "Unenrolled"):
|
if (device["enrollmentStatus"] != "Unenrolled"):
|
||||||
@@ -97,7 +122,7 @@ class AirwatchAPI:
|
|||||||
assignDEPProfileURI = f"/API/mdm/dep/profiles/{device['profileUuid']}/devices/{device['deviceSerialNumber']}?action=Assign"
|
assignDEPProfileURI = f"/API/mdm/dep/profiles/{device['profileUuid']}/devices/{device['deviceSerialNumber']}?action=Assign"
|
||||||
uri = f"{airwatchServer}{assignDEPProfileURI}"
|
uri = f"{airwatchServer}{assignDEPProfileURI}"
|
||||||
airwatchHeaders = self.GetHeaders(assignDEPProfileURI)
|
airwatchHeaders = self.GetHeaders(assignDEPProfileURI)
|
||||||
requests.put(uri, headers=airwatchHeaders)
|
requests.put(uri, headers=airwatchHeaders, proxies=self.Proxy)
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@@ -105,7 +130,7 @@ class AirwatchAPI:
|
|||||||
cmdURI = f"/API/mdm/groups/{groupUuid}/enrollment-tokens?device_type={deviceType}&page_size=500"
|
cmdURI = f"/API/mdm/groups/{groupUuid}/enrollment-tokens?device_type={deviceType}&page_size=500"
|
||||||
uri = f"{self.Server}{cmdURI}"
|
uri = f"{self.Server}{cmdURI}"
|
||||||
airwatchHeaders = self.GetHeaders(cmdURI)
|
airwatchHeaders = self.GetHeaders(cmdURI)
|
||||||
result = requests.get(uri, headers=airwatchHeaders)
|
result = requests.get(uri, headers=airwatchHeaders, proxies=self.Proxy)
|
||||||
return result.json()["tokens"]
|
return result.json()["tokens"]
|
||||||
|
|
||||||
def UpdateUserOnEnrollmentTokens(self, groupUuid,user, serialnumber):
|
def UpdateUserOnEnrollmentTokens(self, groupUuid,user, serialnumber):
|
||||||
@@ -125,13 +150,13 @@ class AirwatchAPI:
|
|||||||
airwatchHeaders["Accept"] = "application/json;version=2"
|
airwatchHeaders["Accept"] = "application/json;version=2"
|
||||||
uri = f"{self.Server}{cmdURI}"
|
uri = f"{self.Server}{cmdURI}"
|
||||||
print(uri)
|
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):
|
def SyncDEPDevices(self, groupUuid):
|
||||||
cmdURI = f"/API/mdm/dep/groups/{groupUuid}/devices?action=sync"
|
cmdURI = f"/API/mdm/dep/groups/{groupUuid}/devices?action=sync"
|
||||||
uri = f"{self.Server}{cmdURI}"
|
uri = f"{self.Server}{cmdURI}"
|
||||||
airwatchHeaders = self.GetHeaders(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):
|
def AddDevicesToTag(self, tagID, devices):
|
||||||
cmdURI = f"/API/mdm/tags/{tagID}/adddevices"
|
cmdURI = f"/API/mdm/tags/{tagID}/adddevices"
|
||||||
@@ -142,7 +167,7 @@ class AirwatchAPI:
|
|||||||
"Value": devices
|
"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):
|
def SetDeviceFriendlyName(self, device, friendlyName):
|
||||||
cmdURI = f"/API/mdm/devices/{device.Id}"
|
cmdURI = f"/API/mdm/devices/{device.Id}"
|
||||||
@@ -151,19 +176,19 @@ class AirwatchAPI:
|
|||||||
body = {
|
body = {
|
||||||
"DeviceFriendlyName":friendlyName
|
"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):
|
def SetDeviceUser(self, device, airwatchUser):
|
||||||
cmdURI = f'/API/mdm/devices/{device.Id}/enrollmentuser/{airwatchUser.Id}'
|
cmdURI = f'/API/mdm/devices/{device.Id}/enrollmentuser/{airwatchUser.Id}'
|
||||||
uri = f"{self.Server}{cmdURI}"
|
uri = f"{self.Server}{cmdURI}"
|
||||||
airwatchHeaders = self.GetHeaders(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):
|
def DeleteDevice(self, device):
|
||||||
cmdURI = f"/API/mdm/devices/{device.Id}"
|
cmdURI = f"/API/mdm/devices/{device.Id}"
|
||||||
airwatchHeaders = self.GetHeaders(cmdURI)
|
airwatchHeaders = self.GetHeaders(cmdURI)
|
||||||
uri = f"{self.Server}{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:
|
class AirwatchUser:
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,20 @@
|
|||||||
[build-system]
|
[build-system]
|
||||||
requires = [
|
requires = [
|
||||||
"setuptools >= 77.0.3",
|
"setuptools >= 77.0.3",
|
||||||
"requests >= 2.32.5"
|
"requests >= 2.32.5",
|
||||||
|
"cryptography"
|
||||||
]
|
]
|
||||||
build-backend = "setuptools.build_meta"
|
build-backend = "setuptools.build_meta"
|
||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "AirwatchAPI"
|
name = "AirwatchAPI"
|
||||||
version = "1.0.0"
|
version = "1.0.4"
|
||||||
description = "A module python to make it easier to use Workspace One API"
|
description = "A module python to make it easier to use Workspace One API"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
|
dependencies = [
|
||||||
|
"requests >= 2.32.5",
|
||||||
|
"cryptography"
|
||||||
|
]
|
||||||
requires-python = ">=3.7"
|
requires-python = ">=3.7"
|
||||||
classifiers = [
|
classifiers = [
|
||||||
"Programming Language :: Python :: 3"
|
"Programming Language :: Python :: 3"
|
||||||
|
|||||||
1
build/src/AirwatchAPI/__init__.py
Normal file
1
build/src/AirwatchAPI/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
__all__ = ["AirwatchAPI"]
|
||||||
@@ -1 +0,0 @@
|
|||||||
__all__ = ["AirwatchAPI"]
|
|
||||||
Reference in New Issue
Block a user