o
    ,ifl]                     @   sb  d dl mZmZmZmZ d dlmZ d dlmZ d dl	m
Z
 d dlmZ d dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlm Z  d dl!m"Z" d dl#m$Z$ d dl%m&Z& d dl'm(Z( d dl)m*Z* d dl+m,Z, d dl-m.Z. d dl/m0Z0 d dl1m2Z2 d dl3m4Z4 d dl5m6Z6 d dl7m8Z8 d dl9m:Z: d dl;m<Z< d dl=m>Z> d dl?m@Z@ d d lAmBZB d d!lCmDZD d d"lEmFZF d d#lGmHZH d d$lImJZJ d d%lKmLZL d d&lMmNZN d d'lOmPZP d d(lQmRZR d d)lSmTZT d d*lUmVZV d d+lWmXZX d d,lYmZZZ d d-l[m\Z\ d d.l]m^Z^ d d/l_m`Z` d d0lambZb d d1lcmdZd d d2lemfZf d d3lgmhZh d d4limjZj d d5lkmlZl d d6lmmnZn d d7lompZp d d8lqmrZr d d9lsmtZt d d:lumvZv d d;lwmxZx d d<lymzZz d d=l{m|Z| d d>l}m~Z~ d d?lmZ d d@lmZ d dAlmZ d dBlmZ d dClmZ dDdEdFdGdHdFdIdJdFdKZG dLdM dMehZdNS )O    )AnyCallableListOptional)SolutionsRoot)CloudCommunications)DeltaCollection)ApplicationCollection)ApplicationTemplate)AuditLogRoot)!AuthenticationMethodConfiguration)!CertificateBasedAuthConfiguration)	Directory)Domain)SchemaExtension)GroupCollection)GroupLifecyclePolicy)GroupSettingTemplate)IdentityContainer)IdentityProvider)IdentityGovernance)MePath)InvitationCollection)SubscribedSku)DirectoryObjectCollection)OAuth2PermissionGrant)ResourceSpecificPermissionGrant)
PolicyRoot)InformationProtection)IdentityProtectionRoot)RoleManagement)DirectoryRole)Security)ServicePrincipalCollection)TenantRelationship)UserCollection)User)EducationRoot)EntityCollection)DeviceAppManagement)DeviceCollection)DeviceManagement)
OrgContact)Organization)Admin)Drive)SharesCollection)SitesWithRoot)Place)RoomList)Planner)
ReportRoot)TokenResponse)ClientRuntimeContext)
HttpMethod)RequestOptions)ODataRequest)ODataV4BatchRequest)V4JsonFormat)ResourcePath)DeleteEntityQuery)UpdateEntityQuery)SearchEntity)External)SubscriptionCollection)AppCatalogs)ChatCollection)TeamCollection)TeamsTemplate)EmployeeExperiencezhttps://graph.microsoft.comz!https://login.microsoftonline.com)	graph_url	entra_urlzhttps://graph.microsoft.usz https://login.microsoftonline.uszhttps://dod-graph.microsoft.uszhttps://login.chinacloudapi.cn)GCCHzGCC HighDoDc                       s4  e Zd ZdZd fdd	Ze	dddZe	dd	d
ZedddZedddZ	dddZ
dd Zdd Zdd Zdd Zedd Zedd Zedd Zed d! Zed"d# Zed$d% Zed&d' Zed(d) Zed*d+ Zed,d- Zed.d/ Zed0d1 Zed2d3 Zed4d5 Zed6d7 Zed8d9 Zed:d; Z ed<d= Z!ed>d? Z"ed@dA Z#edBdC Z$edDdE Z%edFdG Z&edHdI Z'edJdK Z(edLdM Z)edNdO Z*edPdQ Z+edRdS Z,edTdU Z-edVdW Z.edXdY Z/edZd[ Z0ed\d] Z1ed^d_ Z2ed`da Z3edbdc Z4eddde Z5edfdg Z6edhdi Z7edjdk Z8edldm Z9edndo Z:edpdq Z;edrds Z<edtdu Z=edvdw Z>edxdy Z?edzd{ Z@ed|d} ZAed~d ZBedd ZCedd ZDedd ZEedd ZFedd ZGedd ZH  ZIS )GraphClientzGraph Service clientv1.0rJ   c                    s2   t t|   d | _|| _t|d | _|| _d S N)	superrL   __init___pending_request_versionenvironments_endpointsget_environment_endpoints_acquire_token_callback)selfacquire_token_callbackversionenvironment	__class__ O/var/www/html/corbot_env/lib/python3.10/site-packages/office365/graph_client.pyrP   _   s
   
zGraphClient.__init__Nc           	         sN   du rdgd | }ddl}|j||||d|d  fdd}t|S )	a#  
        Initializes the confidential client with client certificate

        :param str tenant: Tenant name, for example: contoso.onmicrosoft.com
        :param str client_id: The OAuth client id of the calling application.
        :param str thumbprint: Thumbprint
        :param str private_key: Private key
        :param list[str] or None scopes: Scopes requested to access an API
        :param Any token_cache: Default cache is in memory only,
        Refer https://msal-python.readthedocs.io/en/latest/#msal.SerializableTokenCache
        N$https://graph.microsoft.com/.default%https://login.microsoftonline.com/{0}r   )
thumbprintprivate_key	authorityclient_credentialtoken_cachec                          j dS N)scopesacquire_token_for_clientr]   appri   r]   r^   _acquire_token      z4GraphClient.with_certificate.<locals>._acquire_tokenformatmsalConfidentialClientApplicationrL   )	tenant	client_idra   rb   ri   rf   authority_urlrr   rn   r]   rl   r^   with_certificateg   s   
zGraphClient.with_certificatec                    sH   du rdgd | }ddl}|j||||d  fdd}t|S )a  
        Initializes the confidential client with client secret

        :param str tenant: Tenant name, for example: contoso.onmicrosoft.com
        :param str client_id: The OAuth client id of the calling application.
        :param str client_secret: Client secret
        :param list[str] or None scopes: Scopes requested to access an API
        :param Any token_cache: Default cache is in memory only,
             Refer https://msal-python.readthedocs.io/en/latest/#msal.SerializableTokenCache
        Nr_   r`   r   rc   c                      rg   rh   rj   r]   rl   r]   r^   rn      ro   z6GraphClient.with_client_secret.<locals>._acquire_tokenrp   )rt   ru   client_secretri   rf   rv   rr   rn   r]   rl   r^   with_client_secret   s   
zGraphClient.with_client_secretc                    sF   du rdgd | }ddl}|j||d  fdd}t|S )a  
        Initializes the client via user credentials
        Note: only works if your app is registered with redirect_uri as http://localhost

        :param str tenant: Tenant name, for example: contoso.onmicrosoft.com
        :param str client_id: The OAuth client id of the calling application.
        :param str username: Typically a UPN in the form of an email address.
        :param list[str] or None scopes: Scopes requested to access an API
        Nr_   r`   r   )rd   c                     s@   d }  j d}|r|d } j|d} | s jd} | S )Nusernamer   account)
login_hint)get_accountsacquire_token_silentacquire_token_interactive)resultaccountschosenrm   ri   r{   r]   r^   rn      s   z:GraphClient.with_token_interactive.<locals>._acquire_tokenrq   rr   PublicClientApplicationrL   )rt   ru   r{   ri   rv   rr   rn   r]   r   r^   with_token_interactive   s   
z"GraphClient.with_token_interactivec                    sH   du rdgd | }ddl}|j||d  fdd}t|S )a  
        Initializes the client via user credentials

        :param str tenant: Tenant name, for example: contoso.onmicrosoft.com
        :param str client_id: The OAuth client id of the calling application.
        :param str username: Typically a UPN in the form of an email address.
        :param str password: The password.
        :param list[str] or None scopes: Scopes requested to access an API
        Nr_   r`   r   )rd   ru   c                     s>   d }  j d}|r j|d d} | s jd} | S )Nrz   r   r|   )r{   passwordri   )r   r   "acquire_token_by_username_password)r   r   rm   r   ri   r{   r]   r^   rn      s   z>GraphClient.with_username_and_password.<locals>._acquire_tokenr   )rt   ru   r{   r   ri   rv   rr   rn   r]   r   r^   with_username_and_password   s   
z&GraphClient.with_username_and_passwordd   c                 C   s>   t t }| j| j7  _| jr| |}|| | js| S )z}Constructs and submit a batch request

        :param int items_per_batch: Maximum to be selected for bulk operation
        )r;   r<   beforeExecute_authenticate_requesthas_pending_request_get_next_queryexecute_query)rW   items_per_batchbatch_requestqryr]   r]   r^   execute_batch   s   


zGraphClient.execute_batchc                 C   s@   | j d u rtt | _ | j  j| j7  _| j  j| j7  _| j S rN   )rQ   r:   r<   r   r   _build_specific_queryrW   r]   r]   r^   pending_request  s
   
zGraphClient.pending_requestc                 C   s   d | jS )Nzhttps://graph.microsoft.com/{0})rq   rR   r   r]   r]   r^   service_root_url  s   zGraphClient.service_root_urlc                 C   s4   t | jtrtj|_dS t | jtrtj|_dS dS )z#Builds Graph specific HTTP request.N)
isinstancecurrent_queryr?   r8   Patchmethodr>   Delete)rW   requestr]   r]   r^   r     s
   z!GraphClient._build_specific_queryc                 C   s*   |   }t|}|dd|j dS )zAuthenticate request.Authorizationz
Bearer {0}N)rV   r6   	from_jsonensure_headerrq   accessToken)rW   r   
token_jsontokenr]   r]   r^   r     s   
z!GraphClient._authenticate_requestc                 C      t | tdS )zHA container for administrator functionality for SharePoint and OneDrive.admin)r.   r=   r   r]   r]   r^   r         zGraphClient.adminc                 C   r   )z:A container for apps from the Microsoft Teams app catalog.appCatalogs)rC   r=   r   r]   r]   r^   app_catalogs%  r   zGraphClient.app_catalogsc                 C   s   t | t S )zIThe Me endpoint is provided as a shortcut for specifying the current user)r&   r   r   r]   r]   r^   me*  s   zGraphClient.mec                 C   r   )zRSingleton entity that acts as a container for all device management functionality.deviceManagement)r+   r=   r   r]   r]   r^   device_management/  r   zGraphClient.device_managementc                 C   r   )zZSingleton entity that acts as a container for all device and app management functionality.deviceAppManagement)r)   r=   r   r]   r]   r^   device_app_management4  r   z!GraphClient.device_app_managementc                 C      t | ttdS )zGet one drivesdrives)r(   r/   r=   r   r]   r]   r^   r   9     zGraphClient.drivesc                 C   r   )zUsers containerusers)r%   r=   r   r]   r]   r^   r   >  r   zGraphClient.usersc                 C   r   )zAlias to domainsdomains)r(   r   r=   r   r]   r]   r^   r   C  r   zGraphClient.domainsc                 C   r   )z
Get groupsgroups)r   r=   r   r]   r]   r^   r   H  r   zGraphClient.groupsc                 C   r   )zGet invitationsinvitations)r   r=   r   r]   r]   r^   r   M  r   zGraphClient.invitationsc                 C   r   )NidentityProtection)r   r=   r   r]   r]   r^   identity_protectionR     zGraphClient.identity_protectionc                 C   r   )zSites containersites)r1   r=   r   r]   r]   r^   r   V  r   zGraphClient.sitesc                 C   r   )zShares containershares)r0   r=   r   r]   r]   r^   r   [  r   zGraphClient.sharesc                 C   r   )zDirectory Objects containerdirectoryObjects)r   r=   r   r]   r]   r^   directory_objects`  r   zGraphClient.directory_objectsc                 C   r   )zDevices containerdevices)r*   r=   r   r]   r]   r^   r   e  r   zGraphClient.devicesc                 C   r   )zTeams containerteams)rE   r=   r   r]   r]   r^   r   j  r   zGraphClient.teamsc                 C   r   )zChats containerchats)rD   r=   r   r]   r]   r^   r   o  r   zGraphClient.chatsc                 C   r   )zRGroup setting templates represent system-defined settings available to the tenant.groupSettingTemplates)r(   r   r=   r   r]   r]   r^   group_setting_templatest     
z#GraphClient.group_setting_templatesc                 C   r   )z>Get the list of organizational contacts for this organization.contacts)r   r,   r=   r   r]   r]   r^   r   {  r   zGraphClient.contactsc                 C   r   )z*Represents a deleted item in the directory	directory)r   r=   r   r]   r]   r^   r     r   zGraphClient.directoryc                 C   r   )-Represents a directory roles in the directorydirectoryRoles)r   r!   r=   r   r]   r]   r^   directory_roles  r   zGraphClient.directory_rolesc                 C      ddl m} t| |tdS )z6Represents a directory role templates in the directoryr   )DirectoryRoleTemplatedirectoryRoleTemplates)+office365.directory.rolemanagement.templater   r(   r=   )rW   r   r]   r]   r^   directory_role_templates  s   
z$GraphClient.directory_role_templatesc                 C   r   ) identityProviders)r(   r   r=   r   r]   r]   r^   identity_providers  r   zGraphClient.identity_providersc                 C   r   )Nidentity)r   r=   r   r]   r]   r^   r     r   zGraphClient.identityc                 C   r   );Get the list of application templates in this organization.applicationTemplates)r(   r
   r=   r   r]   r]   r^   application_templates  r   z!GraphClient.application_templatesc                 C   r   )r   "authenticationMethodConfigurations)r(   r   r=   r   r]   r]   r^   $authentication_method_configurations  
   z0GraphClient.authentication_method_configurationsc                 C   r   )2Get the list of applications in this organization.applications)r	   r=   r   r]   r]   r^   r     r   zGraphClient.applicationsc                 C   r   )r   !certificateBasedAuthConfiguration)r(   r   r=   r   r]   r]   r^   $certificate_based_auth_configuration  r   z0GraphClient.certificate_based_auth_configurationc                 C   r   )z,Retrieve a list of servicePrincipal objects.servicePrincipals)r#   r=   r   r]   r]   r^   service_principals  r   zGraphClient.service_principalsc                 C   r   )r   organization)r(   r-   r=   r   r]   r]   r^   r     r   zGraphClient.organizationc                 C   r   )zJGet the list of commercial subscriptions that an organization has acquiredsubscribedSkus)r(   r   r=   r   r]   r]   r^   subscribed_skus  r   zGraphClient.subscribed_skusc                 C   r   )z>A collection of lifecycle policies for a Microsoft 365 groups.groupLifecyclePolicies)r(   r   r=   r   r]   r]   r^   group_lifecycle_policies  r   z$GraphClient.group_lifecycle_policiesc                 C      ddl m} || tdS )r   r   )GroupSettinggroupSettings)"office365.directory.groups.settingr   r=   )rW   r   r]   r]   r^   group_settings     zGraphClient.group_settingsc                 C   r   )z!Cloud communications API endpointcommunications)r   r=   r   r]   r]   r^   r     r   zGraphClient.communicationsc                 C   r   )z!The identity governance singletonidentityGovernance)r   r=   r   r]   r]   r^   identity_governance  r   zGraphClient.identity_governancec                 C   r   )z}
        Exposes methods that you can use to get Microsoft Purview Information Protection labels and label policies.
        informationProtection)r   r=   r   r]   r]   r^   information_protection     z"GraphClient.information_protectionc                 C   r   )z
        Retrieve the properties and relationships of webhook subscriptions,
        based on the app ID, the user, and the user's role with a tenant.
        subscriptions)rB   r=   r   r]   r]   r^   r        zGraphClient.subscriptionsc                 C   r   )zBGet a list of the externalConnection objects and their properties.r   )ExternalConnectionconnections)$office365.search.external.connectionr   r(   r=   )rW   r   r]   r]   r^   r     s   zGraphClient.connectionsc                 C   r   )z3Represent the various type of tenant relationships.tenantRelationships)r$   r=   r   r]   r]   r^   tenant_relationships  r   z GraphClient.tenant_relationshipsc                 C   r   )z@Gets the list of audit logs generated by Azure Active Directory.	auditLogs)r   r=   r   r]   r]   r^   
audit_logs  r   zGraphClient.audit_logsc                 C   r   )zGets all places in a tenantplaces)r(   r2   r=   r   r]   r]   r^   r     r   zGraphClient.placesc                 C   r   )zPermission grants containeroauth2PermissionGrants)r   r   r=   r   r]   r]   r^   oauth2_permission_grants  r   z$GraphClient.oauth2_permission_grantsc                 C   s   t | ttdtdS )z#Gets all the room lists in a tenantzmicrosoft.graph.roomlistr   )r(   r3   r=   r   r]   r]   r^   
room_lists  s
   zGraphClient.room_listsc                 C   r   )zQRepresents a container for Azure Active Directory (Azure AD) reporting resources.reports)r5   r=   r   r]   r]   r^   r     r   zGraphClient.reportsc                 C   r   )zURepresents a Microsoft 365 role-based access control (RBAC) role management containerroleManagement)r    r=   r   r]   r]   r^   role_management  r   zGraphClient.role_managementc                 C   r   )N	solutions)r   r=   r   r]   r]   r^   r   "  r   zGraphClient.solutionsc                 C   r   )z Get the list of teams templates.teamsTemplates)r(   rF   r=   r   r]   r]   r^   teams_templates&  r   zGraphClient.teams_templatesc                 C   r   )z
        The planner resource is the entry point for the Planner object model.
        It returns a singleton planner resource. It doesn't contain any usable properties.
        planner)r4   r=   r   r]   r]   r^   r  +  r   zGraphClient.plannerc                 C   r   )z,List all resource-specific permission grantspermissionGrants)r(   r   r=   r   r]   r]   r^   permission_grants3  r   zGraphClient.permission_grantsc                 C   r   )z>Used to manage printers and print jobs within Universal Print.r   )Printprint)office365.intune.printing.printr  r=   )rW   r  r]   r]   r^   r  :  r   zGraphClient.printc                 C   r   )zNThe search endpoint is the entry point for Microsoft Search API to query data.search)r@   r=   r   r]   r]   r^   r	  A  r   zGraphClient.searchc                 C   r   )zAn alias to EmployeeExperienceemployeeExperience)rG   r=   r   r]   r]   r^   employee_experienceF  r   zGraphClient.employee_experiencec                 C   r   )zj
        The /education namespace exposes functionality that is specific to the education sector.
        	education)r'   r=   r   r]   r]   r^   r  K  r   zGraphClient.educationc                 C   r   )zHResource type exposing navigation properties for the policies singleton.policies)r   r=   r   r]   r]   r^   r  R  r   zGraphClient.policiesc                 C   r   )z)A logical container for external sources.external)rA   r=   r   r]   r]   r^   r  W  r   zGraphClient.externalc                 C   r   )zThe security resource is the entry point for the Security object model.
        It returns a singleton security resource. It doesn't contain any usable properties.
        security)r"   r=   r   r]   r]   r^   r  \  r   zGraphClient.securityc                 C   r   )z4Get a list of schemaExtension objects in your tenantschemaExtensions)r(   r   r=   r   r]   r]   r^   schema_extensionsc  r   zGraphClient.schema_extensions)rM   rJ   )NNrN   )r   )J__name__
__module____qualname____doc__rP   staticmethodrw   ry   r   r   r   r   r   r   r   propertyr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r	  r  r  r  r  r  r  __classcell__r]   r]   r[   r^   rL   \   s   $&
%























































rL   N)typingr   r   r   r    office365.booking.solutions.rootr   -office365.communications.cloud_communicationsr   office365.delta_collectionr   +office365.directory.applications.collectionr	   )office365.directory.applications.templater
   "office365.directory.audit.log_rootr   7office365.directory.authentication.method_configurationr   3office365.directory.certificates.auth_configurationr   office365.directory.directoryr   "office365.directory.domains.domainr   %office365.directory.extensions.schemar   %office365.directory.groups.collectionr   +office365.directory.groups.lifecycle_policyr   +office365.directory.groups.setting_templater   (office365.directory.identities.containerr   'office365.directory.identities.providerr   1office365.directory.identitygovernance.governancer   %office365.directory.internal.paths.mer   *office365.directory.invitations.collectionr   +office365.directory.licenses.subscribed_skur   %office365.directory.object_collectionr   -office365.directory.permissions.grants.oauth2r   8office365.directory.permissions.grants.resource_specificr   !office365.directory.policies.rootr   *office365.directory.protection.informationr   #office365.directory.protection.rootr   -office365.directory.rolemanagement.managementr    'office365.directory.rolemanagement.roler!   %office365.directory.security.securityr"   0office365.directory.serviceprincipals.collectionr#   'office365.directory.tenant_relationshipr$   $office365.directory.users.collectionr%   office365.directory.users.userr&   office365.education.rootr'   office365.entity_collectionr(   'office365.intune.devices.app_managementr)   #office365.intune.devices.collectionr*   .office365.intune.devices.management.managementr+   &office365.intune.organizations.contactr,   +office365.intune.organizations.organizationr-   office365.onedrive.adminr.   office365.onedrive.drives.driver/   $office365.onedrive.shares.collectionr0   (office365.onedrive.sites.sites_with_rootr1    office365.outlook.calendar.placer2   %office365.outlook.calendar.rooms.listr3   office365.planner.plannerr4   office365.reports.rootr5   %office365.runtime.auth.token_responser6   (office365.runtime.client_runtime_contextr7   "office365.runtime.http.http_methodr8   &office365.runtime.http.request_optionsr9   office365.runtime.odata.requestr:   (office365.runtime.odata.v4.batch_requestr;   &office365.runtime.odata.v4.json_formatr<   %office365.runtime.paths.resource_pathr=   'office365.runtime.queries.delete_entityr>   'office365.runtime.queries.update_entityr?   office365.search.entityr@   "office365.search.external.externalrA   "office365.subscriptions.collectionrB   office365.teams.apps.catalogrC    office365.teams.chats.collectionrD   office365.teams.collectionrE   office365.teams.templaterF   (office365.teams.viva.employee_experiencerG   rS   rL   r]   r]   r]   r^   <module>   s    