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 Jan 30, 2024
1 parent 9f8e04f commit 035b324
Show file tree
Hide file tree
Showing 35 changed files with 287 additions and 322 deletions.
36 changes: 36 additions & 0 deletions examples/auth/gcc_high.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""
Connect via national clouds (Microsoft 365 GCC High environment)
Microsoft Graph for US Government L4: https://graph.microsoft.us
"""
import msal

from office365.graph_client import GraphClient
from tests import (
test_client_id,
test_client_secret,
test_tenant,
test_user_principal_name,
)


def acquire_token():
authority_url = "https://login.microsoftonline.us/{0}".format(test_tenant)

app = msal.ConfidentialClientApplication(
authority=authority_url,
client_id=test_client_id,
client_credential=test_client_secret,
)
return app.acquire_token_for_client(scopes=["https://graph.microsoft.us/.default"])


def construct_request(request):
request.url = request.url.replace(
"https://graph.microsoft.com", "https://graph.microsoft.us"
)


client = GraphClient(acquire_token)
client.before_execute(construct_request)
messages = client.users[test_user_principal_name].messages.get().execute_query()
4 changes: 2 additions & 2 deletions examples/onedrive/drives/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
https://learn.microsoft.com/en-us/graph/api/drive-list?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)
drives = client.drives.get().top(100).execute_query()
for drive in drives:
print("Drive url: {0}".format(drive.web_url))
2 changes: 2 additions & 0 deletions examples/sharepoint/folders/download_as_zip.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
import tempfile

from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.files.file import File
from tests import test_client_credentials, test_team_site_url


def print_progress(file):
# type: (File) -> None
print("File {0} has been downloaded".format(file.serverRelativeUrl))


Expand Down
9 changes: 4 additions & 5 deletions office365/communications/calls/participant.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Optional

from office365.communications.calls.invitation_participant_info import (
InvitationParticipantInfo,
)
Expand Down Expand Up @@ -68,9 +70,6 @@ def info(self):

@property
def metadata(self):
"""
A blob of data provided by the participant in the roster.
:rtype: str
"""
# type: () -> Optional[str]
"""A blob of data provided by the participant in the roster."""
return self.properties.get("metadata", None)
9 changes: 9 additions & 0 deletions office365/directory/authentication/method_configuration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from office365.entity import Entity


class AuthenticationMethodConfiguration(Entity):
"""
This is an abstract type that represents the settings for each authentication method. It has the configuration
of whether a specific authentication method is enabled or disabled for the tenant and which users and groups
can register and use that method.
"""
12 changes: 3 additions & 9 deletions office365/directory/identities/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ class IdentityContainer(Entity):

@property
def api_connectors(self):
"""
Represents entry point for API connectors.
"""
"""Represents entry point for API connectors."""
return self.properties.get(
"apiConnectors",
EntityCollection(
Expand Down Expand Up @@ -52,9 +50,7 @@ def identity_providers(self):

@property
def b2x_user_flows(self):
"""
Represents entry point for B2X/self-service sign-up identity userflows.
"""
"""Represents entry point for B2X/self-service sign-up identity userflows."""
return self.properties.get(
"b2xUserFlows",
EntityCollection(
Expand All @@ -66,9 +62,7 @@ def b2x_user_flows(self):

@property
def user_flow_attributes(self):
"""
Represents entry point for identity userflow attributes.
"""
"""Represents entry point for identity userflow attributes."""
return self.properties.get(
"userFlowAttributes",
EntityCollection(
Expand Down
40 changes: 19 additions & 21 deletions office365/graph_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
from office365.directory.applications.collection import ApplicationCollection
from office365.directory.applications.template import ApplicationTemplate
from office365.directory.audit.log_root import AuditLogRoot
from office365.directory.authentication.method_configuration import (
AuthenticationMethodConfiguration,
)
from office365.directory.directory import Directory
from office365.directory.domains.domain import Domain
from office365.directory.extensions.schema import SchemaExtension
Expand Down Expand Up @@ -399,6 +402,15 @@ def application_templates(self):
self, ApplicationTemplate, ResourcePath("applicationTemplates")
)

@property
def authentication_method_configurations(self):
"""Get the list of application templates in this organization."""
return EntityCollection(
self,
AuthenticationMethodConfiguration,
ResourcePath("authenticationMethodConfigurations"),
)

@property
def applications(self):
"""Get the list of applications in this organization."""
Expand Down Expand Up @@ -435,16 +447,12 @@ def group_settings(self):

@property
def communications(self):
"""
Cloud communications API endpoint
"""
"""Cloud communications API endpoint"""
return CloudCommunications(self, ResourcePath("communications"))

@property
def identity_governance(self):
"""
The identity governance singleton
"""
"""The identity governance singleton"""
return IdentityGovernance(self, ResourcePath("identityGovernance"))

@property
Expand Down Expand Up @@ -509,9 +517,7 @@ def solutions(self):

@property
def teams_templates(self):
"""
Get the list of teams templates.
"""
"""Get the list of teams templates."""
return EntityCollection(self, TeamsTemplate, ResourcePath("teamsTemplates"))

@property
Expand All @@ -524,34 +530,26 @@ def planner(self):

@property
def permission_grants(self):
"""
List all resource-specific permission grants
"""
"""List all resource-specific permission grants"""
return EntityCollection(
self, ResourceSpecificPermissionGrant, ResourcePath("permissionGrants")
)

@property
def print(self):
"""
Used to manage printers and print jobs within Universal Print.
"""
"""Used to manage printers and print jobs within Universal Print."""
from office365.intune.printing.print import Print

return Print(self, ResourcePath("print"))

@property
def search(self):
"""
The search endpoint is the entry point for Microsoft Search API to query data.
"""
"""The search endpoint is the entry point for Microsoft Search API to query data."""
return SearchEntity(self, ResourcePath("search"))

@property
def employee_experience(self):
"""
An alias to EmployeeExperience
"""
"""An alias to EmployeeExperience"""
return EmployeeExperience(self, ResourcePath("employeeExperience"))

@property
Expand Down
16 changes: 4 additions & 12 deletions office365/onedrive/contenttypes/content_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ class ContentType(BaseItem):
columns that must be present on every listItem in a list."""

def is_published(self):
"""
Check the publishing status of a contentType in a content type hub site.
"""
"""Check the publishing status of a contentType in a content type hub site."""
return_type = ClientResult(self.context, bool())
qry = FunctionQuery(self, "isPublished", None, return_type)
self.context.add_query(qry)
Expand Down Expand Up @@ -57,9 +55,7 @@ def publish(self):
return self

def unpublish(self):
"""
Unpublish a contentType from a content type hub site.
"""
"""Unpublish a contentType from a content type hub site."""
qry = ServiceOperationQuery(self, "unpublish")
self.context.add_query(qry)
return self
Expand All @@ -75,9 +71,7 @@ def associated_hubs_urls(self):

@property
def document_set(self):
"""
Document Set metadata.
"""
"""Document Set metadata."""
return self.properties.get("documentSet", DocumentSet())

@property
Expand Down Expand Up @@ -115,9 +109,7 @@ def propagate_changes(self):
@property
def read_only(self):
# type: () -> Optional[bool]
"""
If true, the content type cannot be modified unless this value is first set to false.
"""
"""If true, the content type cannot be modified unless this value is first set to false."""
return self.properties.get("readOnly", None)

@property
Expand Down
17 changes: 10 additions & 7 deletions office365/runtime/auth/providers/acs_token_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


class ACSTokenProvider(AuthenticationProvider, office365.logger.LoggerContext):
def __init__(self, url, client_id, client_secret, environment='commercial'):
def __init__(self, url, client_id, client_secret, environment="commercial"):
"""
Provider to acquire the access token from a Microsoft Azure Access Control Service (ACS)
Expand Down Expand Up @@ -65,7 +65,9 @@ def _get_app_only_access_token(self, target_host, target_realm):
self.SharePointPrincipal, target_host, target_realm
)
principal_id = self.get_formatted_principal(self._client_id, None, target_realm)
sts_url = self.get_security_token_service_url(target_realm, environment=self._environment)
sts_url = self.get_security_token_service_url(
target_realm, environment=self._environment
)
oauth2_request = {
"grant_type": "client_credentials",
"client_id": principal_id,
Expand Down Expand Up @@ -105,13 +107,14 @@ def get_formatted_principal(principal_name, host_name, realm):

@staticmethod
def get_security_token_service_url(realm, environment):
# type: (str, str) -> str
if environment == "GCCH":
return "https://login.microsoftonline.us/{0}/tokens/OAuth/2".format(
realm
)
return "https://login.microsoftonline.us/{0}/tokens/OAuth/2".format(realm)
else:
return "https://accounts.accesscontrol.windows.net/{0}/tokens/OAuth/2".format(
realm
return (
"https://accounts.accesscontrol.windows.net/{0}/tokens/OAuth/2".format(
realm
)
)

def _get_authorization_header(self):
Expand Down
19 changes: 6 additions & 13 deletions office365/runtime/client_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,10 @@ def execute_query_retry(
)
return self

def after_execute(self, action, *args, **kwargs):
# type: (Callable[[Self, Any, Any], None], Any, Any) -> Self
"""
Attach an event handler to client object which gets triggered after query is submitted to server
"""
self._context.after_query_execute(action, self, *args, **kwargs)
def after_execute(self, action):
# type: (Callable[[Self], None]) -> Self
"""Attach an event handler to client object which gets triggered after query is submitted to server"""
self._context.after_query_execute(action, self)
return self

def get(self):
Expand Down Expand Up @@ -138,13 +136,8 @@ def get_property(self, name, default_value=None):
return self._properties.get(name, default_value)

def set_property(self, name, value, persist_changes=True):
# type: (str, P_T, bool) -> Self
"""Sets property value
:param str name: Property name
:param P_T value: Property value
:param bool persist_changes: Persist changes
"""
# type: (str|int, P_T, bool) -> Self
"""Sets property value"""
if persist_changes:
self._ser_property_names.append(name)

Expand Down
23 changes: 10 additions & 13 deletions office365/runtime/client_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

from typing_extensions import Self

from office365.runtime.http.request_options import RequestOptions

if TYPE_CHECKING:
from office365.runtime.client_runtime_context import ClientRuntimeContext # noqa
from office365.runtime.client_value import ClientValue # noqa
Expand All @@ -19,21 +21,16 @@ def __init__(self, context, default_value=None):
self._context = context
self._value = copy.deepcopy(default_value) # type: T

def before_execute(self, action, *args, **kwargs):
"""
Attach an event handler which is triggered before query is submitted to server
:param (office365.runtime.http.request_options.RequestOptions) -> None action: Event handler
"""
self._context.before_query_execute(action, *args, **kwargs)
def before_execute(self, action):
# type: (Callable[[RequestOptions], None]) -> Self
"""Attach an event handler which is triggered before query is submitted to server"""
self._context.before_query_execute(action)
return self

def after_execute(self, action, *args, **kwargs):
# type: (Callable[[Self], None], Any, Any) -> Self
"""
Attach an event handler which is triggered after query is submitted to server
:param (ClientResult) -> None action: Event handler
"""
self._context.after_query_execute(action, self, *args, **kwargs)
def after_execute(self, action):
# type: (Callable[[Self], None]) -> Self
"""Attach an event handler which is triggered after query is submitted to server"""
self._context.after_query_execute(action, self)
return self

def set_property(self, key, value, persist_changes=False):
Expand Down

0 comments on commit 035b324

Please sign in to comment.