Skip to content

Commit

Permalink
Intune API support & typings updates
Browse files Browse the repository at this point in the history
  • Loading branch information
vgrem committed Feb 5, 2024
1 parent c777594 commit a914924
Show file tree
Hide file tree
Showing 35 changed files with 936 additions and 87 deletions.
701 changes: 701 additions & 0 deletions examples/data/Financial Sample.csv

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions examples/directory/applications/add_cert.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
"""

from office365.graph_client import GraphClient
from tests import test_client_id, test_tenant
from tests.graph_case import acquire_token_by_username_password
from tests import test_client_id, test_password, test_tenant, test_username

cert_path = "../../selfsigncert.pem"

client = GraphClient(acquire_token_by_username_password)
client = GraphClient.with_username_and_password(
test_tenant, test_client_id, test_username, test_password
)
target_app = client.applications.get_by_app_id(test_client_id)
with open(cert_path, "rb") as f:
cert_data = f.read()
Expand Down
17 changes: 8 additions & 9 deletions examples/directory/applications/get_by_app_id.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
"""
Manage an Azure AD application using Microsoft Graph
https://learn.microsoft.com/en-us/graph/tutorial-applications-basics?tabs=http
https://learn.microsoft.com/en-us/graph/tutorial-applications-basics
You can address an application or a service principal by its ID or by its appId, where ID is referred to
as Object ID and appId is referred to as Application (client) ID on the Azure portal.
"""
from office365.graph_client import GraphClient
from tests import test_client_credentials
from tests.graph_case import acquire_token_by_client_credentials

client = GraphClient(acquire_token_by_client_credentials)
app = (
client.applications.get_by_app_id(test_client_credentials.clientId)
.get()
.execute_query()
from tests import (
test_client_id,
test_client_secret,
test_tenant,
)

client = GraphClient.with_client_secret(test_tenant, test_client_id, test_client_secret)
app = client.applications.get_by_app_id(test_client_id).get().execute_query()
print(app)
19 changes: 13 additions & 6 deletions examples/directory/users/assign_manager.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
"""
Assign manager
https://learn.microsoft.com/en-us/graph/api/user-post-manager?view=graph-rest-1.0&tabs=http
https://learn.microsoft.com/en-us/graph/api/user-post-manager?view=graph-rest-1.0
"""
from office365.graph_client import GraphClient
from tests import test_user_principal_name
from tests.graph_case import acquire_token_by_username_password
from tests import (
test_client_id,
test_password,
test_tenant,
test_user_principal_name,
test_username,
)

client = GraphClient(acquire_token_by_username_password)
user = client.users.get_by_principal_name(test_user_principal_name)
manager = client.me.assign_manager(user).get().execute_query()
client = GraphClient.with_username_and_password(
test_tenant, test_client_id, test_username, test_password
)
manager = client.users.get_by_principal_name(test_user_principal_name)
client.me.assign_manager(manager).get().execute_query()
print("User manager has been assigned")
6 changes: 4 additions & 2 deletions examples/directory/users/export_personal_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
https://learn.microsoft.com/en-us/graph/api/user-exportpersonaldata?view=graph-rest-1.0
"""
from office365.graph_client import GraphClient
from tests.graph_case import acquire_token_by_username_password
from tests import test_client_id, test_password, test_tenant, test_username

client = GraphClient(acquire_token_by_username_password)
client = GraphClient.with_username_and_password(
test_tenant, test_client_id, test_username, test_password
)
result = client.me.export_personal_data("storageLocation-value").execute_query()
19 changes: 19 additions & 0 deletions examples/directory/users/get_licenses.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""
Retrieve a list of licenseDetails objects for enterprise users.
https://learn.microsoft.com/en-us/graph/api/user-list-licensedetails?view=graph-rest-1.0
"""
from office365.graph_client import GraphClient
from tests import (
test_client_id,
test_password,
test_tenant,
test_username,
)

client = GraphClient.with_username_and_password(
test_tenant, test_client_id, test_username, test_password
)
result = client.me.license_details.get().execute_query()
for details in result:
print(details)
2 changes: 1 addition & 1 deletion examples/onedrive/files/upload.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Demonstrates how to upload a small file
https://learn.microsoft.com/en-us/graph/api/driveitem-put-content?view=graph-rest-1.0&tabs=http
https://learn.microsoft.com/en-us/graph/api/driveitem-put-content?view=graph-rest-1.0
"""

from office365.graph_client import GraphClient
Expand Down
10 changes: 7 additions & 3 deletions examples/onedrive/folders/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@

from office365.graph_client import GraphClient
from office365.onedrive.driveitems.driveItem import DriveItem
from tests import test_user_principal_name
from tests.graph_case import acquire_token_by_client_credentials
from tests import (
test_client_id,
test_client_secret,
test_tenant,
test_user_principal_name,
)

client = GraphClient(acquire_token_by_client_credentials)
client = GraphClient.with_client_secret(test_tenant, test_client_id, test_client_secret)
drive = client.users[test_user_principal_name].drive
with tempfile.TemporaryDirectory() as local_path:
drive_items = drive.root.children.get().execute_query()
Expand Down
4 changes: 2 additions & 2 deletions examples/onedrive/sites/get_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
https://learn.microsoft.com/en-us/graph/api/site-getallsites?view=graph-rest-1.0
"""
from office365.graph_client import GraphClient
from tests.graph_case import acquire_token_by_client_credentials
from tests import test_client_id, test_client_secret, test_tenant

client = GraphClient(acquire_token_by_client_credentials)
client = GraphClient.with_client_secret(test_tenant, test_client_id, test_client_secret)
sites = client.sites.get_all_sites().execute_query()
print("{0} sites was found".format(len(sites)))
13 changes: 10 additions & 3 deletions examples/outlook/messages/send.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,17 @@
"""

from office365.graph_client import GraphClient
from tests import test_user_principal_name_alt
from tests.graph_case import acquire_token_by_username_password
from tests import (
test_client_id,
test_password,
test_tenant,
test_user_principal_name_alt,
test_username,
)

client = GraphClient(acquire_token_by_username_password)
client = GraphClient.with_username_and_password(
test_tenant, test_client_id, test_username, test_password
)
client.me.send_mail(
subject="Meet for lunch?",
body="The new cafeteria is open.",
Expand Down
8 changes: 3 additions & 5 deletions examples/sharepoint/files/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@

list_title = "Documents"
folder = ctx.web.lists.get_by_title(list_title).root_folder
# path = "../../data/SharePoint User Guide.docx"
# path = "../../data/Sample.pdf"
path = "../../data/countries.json"
path = "../../data/Financial Sample.csv"
# with open(path, "rb") as f:
# file = folder.files.upload(f).execute_query()
with open(path, "rb") as content_file:
file_content = content_file.read()
with open(path, "r") as content_file:
file_content = content_file.read().encode("utf-8-sig")
file = folder.upload_file(os.path.basename(path), file_content).execute_query()
print("File has been uploaded into: {0}".format(file.serverRelativeUrl))
Empty file.
5 changes: 5 additions & 0 deletions office365/booking/virtualevents/root.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from office365.entity import Entity


class VirtualEventsRoot(Entity):
""" """
4 changes: 1 addition & 3 deletions office365/directory/certificates/auth_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ class CertificateBasedAuthConfiguration(Entity):

@property
def certificate_authorities(self):
"""
Collection of certificate authorities which creates a trusted certificate chain.
"""
"""Collection of certificate authorities which creates a trusted certificate chain."""
return self.properties.get(
"certificateAuthorities", ClientValueCollection(CertificateAuthority)
)
8 changes: 2 additions & 6 deletions office365/directory/groups/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,9 +380,7 @@ def planner(self):
@property
def permission_grants(self):
# type: () -> EntityCollection[ResourceSpecificPermissionGrant]
"""
List permissions that have been granted to apps to access the group.
"""
"""List permissions that have been granted to apps to access the group."""
return self.properties.setdefault(
"permissionGrants",
EntityCollection(
Expand All @@ -394,9 +392,7 @@ def permission_grants(self):

@property
def photo(self):
"""
The group's profile photo
"""
"""The group's profile photo"""
return self.properties.get(
"photo",
ProfilePhoto(self.context, ResourcePath("photo", self.resource_path)),
Expand Down
17 changes: 14 additions & 3 deletions office365/directory/identitygovernance/governance.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
from office365.directory.identitygovernance.appconsent.approval_route import (
AppConsentApprovalRoute,
)
from office365.directory.identitygovernance.privilegedaccess.root import (
PrivilegedAccessRoot,
)
from office365.directory.identitygovernance.termsofuse.container import (
TermsOfUseContainer,
)
Expand Down Expand Up @@ -35,16 +38,24 @@ def app_consent(self):

@property
def access_reviews(self):
"""
Container for the base resources that expose the access reviews API and features.
"""
"""Container for the base resources that expose the access reviews API and features."""
return self.properties.get(
"accessReviews",
AccessReviewSet(
self.context, ResourcePath("accessReviews", self.resource_path)
),
)

@property
def privileged_access(self):
"""Container for the base resources that expose the access reviews API and features."""
return self.properties.get(
"privilegedAccess",
PrivilegedAccessRoot(
self.context, ResourcePath("privilegedAccess", self.resource_path)
),
)

@property
def terms_of_use(self):
"""
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from office365.entity import Entity


class PrivilegedAccessRoot(Entity):
"""Represents the entry point for resources related to Privileged Identity Management (PIM)."""
3 changes: 3 additions & 0 deletions office365/directory/key_credential.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,6 @@ def __init__(
self.startDateTime = start_datetime
self.type = key_type
self.usage = usage

def __str__(self):
return self.displayName or self.entity_type_name
28 changes: 26 additions & 2 deletions office365/directory/licenses/assignment_state.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from office365.runtime.client_value import ClientValue
from office365.runtime.types.collections import StringCollection


class LicenseAssignmentState(ClientValue):
Expand All @@ -12,8 +13,31 @@ class LicenseAssignmentState(ClientValue):
- Error details if the assignment state is Error
"""

def __init__(self, assigned_by_group=None):
def __init__(
self,
assigned_by_group=None,
disabled_plans=None,
error=None,
lastUpdatedDateTime=None,
skuId=None,
state=None,
):
"""
:param str assigned_by_group:
:param str assigned_by_group: ndicates whether the license is directly assigned or inherited from a group.
If directly assigned, this field is null; if inherited through a group membership, this field contains
the ID of the group.
:param list[str] disabled_plans: The service plans that are disabled in this assignment
:param str error: License assignment failure error. If the license is assigned successfully, this field is Null.
The possible values are CountViolation, MutuallyExclusiveViolation, DependencyViolation,
ProhibitedInUsageLocationViolation, UniquenessViolation, and Other.
For more information on how to identify and resolve license assignment errors, see here.
:param str skuId: The unique identifier for the SKU. Read-Only.
:param str state: Indicate the current state of this assignment. Read-Only.
The possible values are Active, ActiveWithError, Disabled, and Error.
"""
self.assignedByGroup = assigned_by_group
self.disabledPlans = StringCollection(disabled_plans)
self.error = error
self.lastUpdatedDateTime = lastUpdatedDateTime
self.skuId = skuId
self.state = state
7 changes: 4 additions & 3 deletions office365/directory/licenses/details.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
class LicenseDetails(Entity):
"""Contains information about a license assigned to a user."""

def __repr__(self):
return self.sku_part_number or self.entity_type_name

@property
def service_plans(self):
"""
Information about the service plans assigned with the license. Read-only, Not nullable
"""
"""Information about the service plans assigned with the license. Read-only, Not nullable"""
return self.properties.get(
"servicePlans", ClientValueCollection(ServicePlanInfo)
)
Expand Down
12 changes: 6 additions & 6 deletions office365/directory/profile_photo.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Optional

from office365.entity import Entity


Expand All @@ -12,14 +14,12 @@ class ProfilePhoto(Entity):

@property
def height(self):
"""
The height of the photo. Read-only.
"""
# type: () -> Optional[int]
"""The height of the photo."""
return self.properties.get("height", None)

@property
def width(self):
"""
The width of the photo. Read-only.
"""
# type: () -> Optional[int]
"""The width of the photo."""
return self.properties.get("width", None)
9 changes: 8 additions & 1 deletion office365/directory/security/attacksimulations/report.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
from office365.directory.security.attacksimulations.report_overview import (
SimulationReportOverview,
)
from office365.directory.security.attacksimulations.users.details import (
UserSimulationDetails,
)
from office365.runtime.client_value import ClientValue
from office365.runtime.client_value_collection import ClientValueCollection


class SimulationReport(ClientValue):
Expand All @@ -10,8 +14,11 @@ class SimulationReport(ClientValue):
participated in the campaign.
"""

def __init__(self, overview=SimulationReportOverview()):
def __init__(self, overview=SimulationReportOverview(), simulationUsers=None):
"""
:param SimulationReportOverview overview: Overview of an attack simulation and training campaign.
"""
self.overview = overview
self.simulationUsers = ClientValueCollection(
UserSimulationDetails, simulationUsers
)
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from office365.runtime.client_value import ClientValue


class UserSimulationDetails(ClientValue):
"""Represents a user of a tenant and their online actions in an attack simulation and training campaign."""
4 changes: 1 addition & 3 deletions office365/directory/serviceprincipals/service_principal.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,7 @@ def app_role_assigned_to(self):

@property
def app_roles(self):
"""
The roles exposed by the application which this service principal represents.
"""
"""The roles exposed by the application which this service principal represents."""
return self.properties.get("appRoles", AppRoleCollection())

@property
Expand Down
Loading

0 comments on commit a914924

Please sign in to comment.