Skip to content

Commit 75b1fee

Browse files
committed
directory namespace enhancements: new types & methods
1 parent bfc775e commit 75b1fee

File tree

18 files changed

+199
-31
lines changed

18 files changed

+199
-31
lines changed

examples/sharepoint/connect_and_set_proxy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
def set_proxy(request):
1010
print("Inject proxy settings...")
11-
proxies = {settings.get('default', 'site_url'): 'https://127.0.0.1:8888'}
12-
request.proxies = proxies
11+
#proxies = {settings.get('default', 'site_url'): 'https://127.0.0.1:8888'}
12+
#request.proxies = proxies
1313

1414

1515
ctx = ClientContext(settings.get('default', 'site_url'))\

office365/directory/applications/application.py

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from office365.directory.applications.public_client import PublicClientApplication
12
from office365.directory.object_collection import DirectoryObjectCollection
23
from office365.directory.object import DirectoryObject
34
from office365.directory.extensions.extension_property import ExtensionProperty
@@ -137,6 +138,13 @@ def identifier_uris(self):
137138
"""
138139
return self.properties.get('identifierUris', StringCollection())
139140

141+
@property
142+
def public_client(self):
143+
"""
144+
Specifies settings for installed clients such as desktop or mobile devices.
145+
"""
146+
return self.properties.get('publicClient', PublicClientApplication())
147+
140148
@property
141149
def signin_audience(self):
142150
"""
@@ -149,20 +157,33 @@ def signin_audience(self):
149157
return self.properties.get('signInAudience', None)
150158

151159
@property
152-
def owners(self):
153-
"""Directory objects that are owners of the application. Read-only.
160+
def created_on_behalf_of(self):
161+
""""""
162+
return self.properties.get('createdOnBehalfOf',
163+
DirectoryObject(self.context, ResourcePath("createdOnBehalfOf", self.resource_path)))
154164

155-
:rtype: DirectoryObjectCollection
165+
@property
166+
def owners(self):
167+
"""Directory objects that are owners of the application.
156168
"""
157-
return self.get_property('owners',
158-
DirectoryObjectCollection(self.context, ResourcePath("owners", self.resource_path)))
169+
return self.properties.get('owners',
170+
DirectoryObjectCollection(self.context, ResourcePath("owners", self.resource_path)))
159171

160172
@property
161173
def extension_properties(self):
162174
"""List extension properties on an application object.
163-
164-
:rtype: EntityCollection
165175
"""
166-
return self.get_property('extensionProperties',
167-
EntityCollection(self.context, ExtensionProperty,
168-
ResourcePath("extensionProperties", self.resource_path)))
176+
return self.properties.get('extensionProperties',
177+
EntityCollection(self.context, ExtensionProperty,
178+
ResourcePath("extensionProperties", self.resource_path)))
179+
180+
def get_property(self, name, default_value=None):
181+
if default_value is None:
182+
property_mapping = {
183+
"createdOnBehalfOf": self.created_on_behalf_of,
184+
"extensionProperties": self.extension_properties,
185+
"keyCredentials": self.key_credentials,
186+
"publicClient": self.public_client
187+
}
188+
default_value = property_mapping.get(name, None)
189+
return super(Application, self).get_property(name, default_value)

office365/directory/applications/service_principal.py

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
from office365.directory.applications.app_role_assignment import AppRoleAssignmentCollection
12
from office365.directory.certificates.self_signed import SelfSignedCertificate
23
from office365.directory.key_credential import KeyCredential
34
from office365.directory.object_collection import DirectoryObjectCollection
45
from office365.directory.object import DirectoryObject
6+
from office365.directory.password_credential import PasswordCredential
57
from office365.directory.permissions.scope import PermissionScope
68
from office365.runtime.client_result import ClientResult
79
from office365.runtime.client_value_collection import ClientValueCollection
@@ -35,9 +37,16 @@ def add_key(self, key_credential, password_credential, proof):
3537
self.context.add_query(qry)
3638
return return_type
3739

38-
def add_password(self):
39-
""""""
40-
pass
40+
def add_password(self, display_name=None):
41+
"""Adds a strong password to an application.
42+
43+
:param str display_name: App display name
44+
"""
45+
params = PasswordCredential(display_name=display_name)
46+
return_type = ClientResult(self.context, params)
47+
qry = ServiceOperationQuery(self, "addPassword", None, params, None, return_type)
48+
self.context.add_query(qry)
49+
return return_type
4150

4251
def add_token_signing_certificate(self, display_name, end_datetime=None):
4352
"""
@@ -79,6 +88,15 @@ def app_display_name(self):
7988
"""
8089
return self.properties.get('appDisplayName', None)
8190

91+
@property
92+
def app_role_assigned_to(self):
93+
"""
94+
App role assignments for this app or service, granted to users, groups, and other service principals.
95+
Supports $expand."""
96+
return self.properties.get('appRoleAssignedTo',
97+
AppRoleAssignmentCollection(self.context,
98+
ResourcePath("appRoleAssignedTo", self.resource_path)))
99+
82100
@property
83101
def service_principal_type(self):
84102
"""
@@ -120,10 +138,27 @@ def oauth2_permission_scopes(self):
120138
"""
121139
return self.properties.get("oauth2PermissionScopes", ClientValueCollection(PermissionScope))
122140

141+
@property
142+
def created_objects(self):
143+
"""Directory objects created by this service principal. """
144+
return self.properties.get('createdObjects',
145+
DirectoryObjectCollection(self.context,
146+
ResourcePath("createdObjects", self.resource_path)))
147+
148+
@property
149+
def owned_objects(self):
150+
"""Directory objects that are owned by this service principal. """
151+
return self.properties.get('ownedObjects',
152+
DirectoryObjectCollection(self.context,
153+
ResourcePath("ownedObjects", self.resource_path)))
154+
123155
def get_property(self, name, default_value=None):
124156
if default_value is None:
125157
property_mapping = {
126-
"oauth2PermissionScopes": self.oauth2_permission_scopes
158+
"app_role_assigned_to": self.app_role_assigned_to,
159+
"created_objects": self.created_objects,
160+
"oauth2PermissionScopes": self.oauth2_permission_scopes,
161+
"ownedObjects": self.owned_objects
127162
}
128163
default_value = property_mapping.get(name, None)
129164
return super(ServicePrincipal, self).get_property(name, default_value)

office365/directory/identities/basic_authentication.py renamed to office365/directory/authentication/basic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from office365.directory.identities.authentication_configuration_base import ApiAuthenticationConfigurationBase
1+
from office365.directory.authentication.configuration_base import ApiAuthenticationConfigurationBase
22

33

44
class BasicAuthentication(ApiAuthenticationConfigurationBase):
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from office365.directory.authentication.configuration_base import ApiAuthenticationConfigurationBase
2+
from office365.directory.certificates.pkcs12_information import Pkcs12CertificateInformation
3+
from office365.runtime.client_value_collection import ClientValueCollection
4+
5+
6+
class ClientCertificateAuthentication(ApiAuthenticationConfigurationBase):
7+
"""
8+
A type derived from apiAuthenticationConfigurationBase that is used to represent
9+
a Pkcs12-based client certificate authentication.
10+
This is used to retrieve the public properties of uploaded certificates.
11+
"""
12+
13+
def __init__(self):
14+
super().__init__()
15+
self.certificateList = ClientValueCollection(Pkcs12CertificateInformation)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from office365.runtime.client_value import ClientValue
2+
3+
4+
class Pkcs12CertificateInformation(ClientValue):
5+
""""""

office365/directory/extensions/extended_property.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from office365.entity import Entity
2+
from office365.runtime.types.collections import StringCollection
23

34

45
class SingleValueLegacyExtendedProperty(Entity):
@@ -8,4 +9,8 @@ class SingleValueLegacyExtendedProperty(Entity):
89

910
class MultiValueLegacyExtendedProperty(Entity):
1011
"""An extended property that contains a collection of values."""
11-
pass
12+
13+
@property
14+
def value(self):
15+
"""A collection of property values."""
16+
return self.properties.get("value", StringCollection())

office365/directory/identities/api_connector.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from office365.directory.identities.authentication_configuration_base import ApiAuthenticationConfigurationBase
1+
from office365.directory.authentication.configuration_base import ApiAuthenticationConfigurationBase
22
from office365.entity import Entity
33
from office365.runtime.queries.service_operation import ServiceOperationQuery
44

office365/directory/roles/role.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@ class DirectoryRole(DirectoryObject):
88
@property
99
def members(self):
1010
"""
11-
Users that are members of this directory role. HTTP Methods: GET, POST, DELETE. Read-only. Nullable.
12-
13-
:rtype: office365.directory.object_collection.DirectoryObjectCollection
11+
Users that are members of this directory role.
1412
"""
1513
from office365.directory.object_collection import DirectoryObjectCollection
16-
return self.get_property('members',
17-
DirectoryObjectCollection(self.context, ResourcePath("members", self.resource_path)))
14+
return self.properties.get('members',
15+
DirectoryObjectCollection(self.context, ResourcePath("members", self.resource_path)))

0 commit comments

Comments
 (0)