From 6332a357d90e508da3a19e81d9df27e911f3a693 Mon Sep 17 00:00:00 2001 From: vgrem Date: Sat, 27 Jan 2024 20:39:51 +0200 Subject: [PATCH] Intune API support & typings updates --- examples/security/create_simulation.py | 0 office365/intune/devices/collection.py | 57 ++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) delete mode 100644 examples/security/create_simulation.py create mode 100644 office365/intune/devices/collection.py diff --git a/examples/security/create_simulation.py b/examples/security/create_simulation.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/office365/intune/devices/collection.py b/office365/intune/devices/collection.py new file mode 100644 index 000000000..e3622b854 --- /dev/null +++ b/office365/intune/devices/collection.py @@ -0,0 +1,57 @@ +import random +import string +import uuid + +from office365.delta_collection import DeltaCollection +from office365.intune.devices.alternative_security_id import AlternativeSecurityId +from office365.intune.devices.device import Device +from office365.runtime.client_value_collection import ClientValueCollection +from office365.runtime.queries.create_entity import CreateEntityQuery + + +class DeviceCollection(DeltaCollection[Device]): + """Device's collection""" + + def __init__(self, context, resource_path=None): + super(DeviceCollection, self).__init__(context, Device, resource_path) + + def add( + self, + display_name, + operating_system, + operating_system_version, + account_enabled=False, + alternative_security_id=None, + device_id=None, + ): + """Create and register a new device in the organization. + :param str display_name: The display name for the device + :param str operating_system: + :param str operating_system_version: + :param bool account_enabled: + :param AlternativeSecurityId alternative_security_id: + :param str device_id: + """ + + if alternative_security_id is None: + key_id = "base64" + "".join( + random.choice(string.ascii_lowercase + string.digits) for _ in range(10) + ) + alternative_security_id = AlternativeSecurityId(2, key_id) + if device_id is None: + device_id = str(uuid.uuid4()) + + return_type = Device(self.context) + return_type.set_property("displayName", display_name) + return_type.set_property("operatingSystem", operating_system) + return_type.set_property("operatingSystemVersion", operating_system_version) + return_type.set_property("accountEnabled", account_enabled) + return_type.set_property("deviceId", device_id) + return_type.set_property( + "alternativeSecurityIds", + ClientValueCollection(AlternativeSecurityId, [alternative_security_id]), + ) + self.add_child(return_type) + qry = CreateEntityQuery(self, return_type, return_type) + self.context.add_query(qry) + return return_type