Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a6727b9538 | ||
| 8bf9f9c620 | |||
| 1cdfbc6dc5 | |||
|
|
90378bb2e5 | ||
|
|
f34f1ae793 | ||
| e53af9bb26 | |||
|
|
f5abc6f0f4 | ||
|
|
14b48e7f41 | ||
|
|
930927b489 | ||
|
|
9c468adf7d | ||
|
|
465064f412 | ||
|
|
069caaf2d1 | ||
|
|
73f21ac6cd | ||
|
|
23a617ef62 | ||
|
|
cfd6c2acb9 | ||
|
|
3645ecc257 | ||
|
|
d7dbbda2f9 | ||
|
|
5f0556c5c9 |
@@ -10,7 +10,7 @@ jobs:
|
||||
uses: actions/checkout@main
|
||||
- name: Building the package
|
||||
run: |
|
||||
mv ${{ gitea.workspace }}\AirwatchAPI.py ${{ gitea.workspace }}\build\src\AirwatchAPI\
|
||||
powershell mv ${{ gitea.workspace }}\AirwatchAPI.py build\src\AirwatchAPI\
|
||||
cd ${{ gitea.workspace }}\build
|
||||
python -m build
|
||||
- name: Publish package
|
||||
|
||||
16
.gitlab-ci.yml
Normal file
16
.gitlab-ci.yml
Normal file
@@ -0,0 +1,16 @@
|
||||
image: python:latest
|
||||
|
||||
variables:
|
||||
TWINE_USERNAME: gitlab-ci-token
|
||||
TWINE_PASSWORD: $CI_JOB_TOKEN
|
||||
|
||||
build: # This job runs in the build stage, which runs first.
|
||||
script:
|
||||
- pip install build twine
|
||||
- mv AirwatchAPI.py build/src/AirwatchAPI/
|
||||
- cd build/
|
||||
- python -m build
|
||||
- python -m twine upload --repository-url ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/pypi dist/*
|
||||
rules:
|
||||
- if: $CI_COMMIT_TAG
|
||||
|
||||
@@ -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,25 +61,49 @@ 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, 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):
|
||||
cmdURI = f"/api/mdm/devices/{device.Uuid}/apps/search"
|
||||
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)]
|
||||
@@ -89,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"):
|
||||
@@ -97,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
|
||||
|
||||
@@ -105,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):
|
||||
@@ -125,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"
|
||||
@@ -142,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}"
|
||||
@@ -151,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:
|
||||
|
||||
|
||||
@@ -1,15 +1,20 @@
|
||||
[build-system]
|
||||
requires = [
|
||||
"setuptools >= 77.0.3",
|
||||
"requests >= 2.32.5"
|
||||
"requests >= 2.32.5",
|
||||
"cryptography"
|
||||
]
|
||||
build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "AirwatchAPI"
|
||||
version = "1.0.0"
|
||||
version = "1.0.4"
|
||||
description = "A module python to make it easier to use Workspace One API"
|
||||
readme = "README.md"
|
||||
dependencies = [
|
||||
"requests >= 2.32.5",
|
||||
"cryptography"
|
||||
]
|
||||
requires-python = ">=3.7"
|
||||
classifiers = [
|
||||
"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"]
|
||||
Reference in New Issue
Block a user