Skip to content

Commit 6b97b62

Browse files
authored
[AutoPR graphrbac/data-plane] Added OAuth2 GET and POST to GraphRBAC.json spec (#3063)
* Generated from 7e6768db7f5cf3600aa596cf9c488c6b5ca34ca2 OAuth2 Permissions added to GraphRBAC stable * Generated from dfc2c5676d5c7be8c4ec55a4356e36cc677ee916 OAuth2Permissions and added Service Principal query by AppId * Generated from 6aa96687989842d043047ab3b93cd2e5e66b5dd5 OAuth2 Permissions added to GraphRBAC stable cleanup and validate * Generated from d2bcb30a79b50cc976ba2b049ff780f8ab8d8292 Permissions added to GraphRBAC model rename and linter issues addressed * Generated from 34825096e936c6c8ee69981113b58cd094f18e8f Add description to post body for OAuth2 Permissions
1 parent de96a68 commit 6b97b62

File tree

6 files changed

+233
-1
lines changed

6 files changed

+233
-1
lines changed

azure-graphrbac/azure/graphrbac/graph_rbac_management_client.py

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from .operations.service_principals_operations import ServicePrincipalsOperations
2020
from .operations.users_operations import UsersOperations
2121
from .operations.domains_operations import DomainsOperations
22+
from .operations.oauth2_operations import OAuth2Operations
2223
from . import models
2324

2425

@@ -72,6 +73,8 @@ class GraphRbacManagementClient(object):
7273
:vartype users: azure.graphrbac.operations.UsersOperations
7374
:ivar domains: Domains operations
7475
:vartype domains: azure.graphrbac.operations.DomainsOperations
76+
:ivar oauth2: OAuth2 operations
77+
:vartype oauth2: azure.graphrbac.operations.OAuth2Operations
7578
7679
:param credentials: Credentials needed for the client to connect to Azure.
7780
:type credentials: :mod:`A msrestazure Credentials
@@ -104,3 +107,5 @@ def __init__(
104107
self._client, self.config, self._serialize, self._deserialize)
105108
self.domains = DomainsOperations(
106109
self._client, self.config, self._serialize, self._deserialize)
110+
self.oauth2 = OAuth2Operations(
111+
self._client, self.config, self._serialize, self._deserialize)

azure-graphrbac/azure/graphrbac/models/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
from .user_get_member_groups_parameters import UserGetMemberGroupsParameters
4040
from .get_objects_parameters import GetObjectsParameters
4141
from .domain import Domain
42+
from .permissions import Permissions
4243
from .aad_object_paged import AADObjectPaged
4344
from .application_paged import ApplicationPaged
4445
from .directory_object_paged import DirectoryObjectPaged
@@ -84,6 +85,7 @@
8485
'UserGetMemberGroupsParameters',
8586
'GetObjectsParameters',
8687
'Domain',
88+
'Permissions',
8789
'AADObjectPaged',
8890
'ApplicationPaged',
8991
'DirectoryObjectPaged',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# coding=utf-8
2+
# --------------------------------------------------------------------------
3+
# Copyright (c) Microsoft Corporation. All rights reserved.
4+
# Licensed under the MIT License. See License.txt in the project root for
5+
# license information.
6+
#
7+
# Code generated by Microsoft (R) AutoRest Code Generator.
8+
# Changes may cause incorrect behavior and will be lost if the code is
9+
# regenerated.
10+
# --------------------------------------------------------------------------
11+
12+
from msrest.serialization import Model
13+
14+
15+
class Permissions(Model):
16+
"""Permissions.
17+
18+
:param odatatype: Microsoft.DirectoryServices.OAuth2PermissionGrant
19+
:type odatatype: str
20+
:param client_id: The objectId of the Service Principal associated with
21+
the app
22+
:type client_id: str
23+
:param consent_type: Typically set to AllPrincipals
24+
:type consent_type: str
25+
:param principal_id: Set to null if AllPrincipals is set
26+
:type principal_id: object
27+
:param resource_id: Service Principal Id of the resource you want to grant
28+
:type resource_id: str
29+
:param scope: Typically set to user_impersonation
30+
:type scope: str
31+
:param start_time: Start time for TTL
32+
:type start_time: str
33+
:param expiry_time: Expiry time for TTL
34+
:type expiry_time: str
35+
"""
36+
37+
_attribute_map = {
38+
'odatatype': {'key': 'odata\\.type', 'type': 'str'},
39+
'client_id': {'key': 'clientId', 'type': 'str'},
40+
'consent_type': {'key': 'consentType', 'type': 'str'},
41+
'principal_id': {'key': 'principalId', 'type': 'object'},
42+
'resource_id': {'key': 'resourceId', 'type': 'str'},
43+
'scope': {'key': 'scope', 'type': 'str'},
44+
'start_time': {'key': 'startTime', 'type': 'str'},
45+
'expiry_time': {'key': 'expiryTime', 'type': 'str'},
46+
}
47+
48+
def __init__(self, odatatype=None, client_id=None, consent_type=None, principal_id=None, resource_id=None, scope=None, start_time=None, expiry_time=None):
49+
super(Permissions, self).__init__()
50+
self.odatatype = odatatype
51+
self.client_id = client_id
52+
self.consent_type = consent_type
53+
self.principal_id = principal_id
54+
self.resource_id = resource_id
55+
self.scope = scope
56+
self.start_time = start_time
57+
self.expiry_time = expiry_time

azure-graphrbac/azure/graphrbac/operations/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from .service_principals_operations import ServicePrincipalsOperations
1616
from .users_operations import UsersOperations
1717
from .domains_operations import DomainsOperations
18+
from .oauth2_operations import OAuth2Operations
1819

1920
__all__ = [
2021
'ObjectsOperations',
@@ -23,4 +24,5 @@
2324
'ServicePrincipalsOperations',
2425
'UsersOperations',
2526
'DomainsOperations',
27+
'OAuth2Operations',
2628
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
# coding=utf-8
2+
# --------------------------------------------------------------------------
3+
# Copyright (c) Microsoft Corporation. All rights reserved.
4+
# Licensed under the MIT License. See License.txt in the project root for
5+
# license information.
6+
#
7+
# Code generated by Microsoft (R) AutoRest Code Generator.
8+
# Changes may cause incorrect behavior and will be lost if the code is
9+
# regenerated.
10+
# --------------------------------------------------------------------------
11+
12+
import uuid
13+
from msrest.pipeline import ClientRawResponse
14+
from msrestazure.azure_exceptions import CloudError
15+
16+
from .. import models
17+
18+
19+
class OAuth2Operations(object):
20+
"""OAuth2Operations operations.
21+
22+
:param client: Client for service requests.
23+
:param config: Configuration of service client.
24+
:param serializer: An object model serializer.
25+
:param deserializer: An object model deserializer.
26+
:ivar api_version: Client API version. Constant value: "1.6".
27+
"""
28+
29+
models = models
30+
31+
def __init__(self, client, config, serializer, deserializer):
32+
33+
self._client = client
34+
self._serialize = serializer
35+
self._deserialize = deserializer
36+
self.api_version = "1.6"
37+
38+
self.config = config
39+
40+
def get(
41+
self, filter=None, custom_headers=None, raw=False, **operation_config):
42+
"""Queries OAuth2 permissions for the relevant SP ObjectId of an app.
43+
44+
:param filter: This is the Service Principal ObjectId associated with
45+
the app
46+
:type filter: str
47+
:param dict custom_headers: headers that will be added to the request
48+
:param bool raw: returns the direct response alongside the
49+
deserialized response
50+
:param operation_config: :ref:`Operation configuration
51+
overrides<msrest:optionsforoperations>`.
52+
:return: Permissions or ClientRawResponse if raw=true
53+
:rtype: ~azure.graphrbac.models.Permissions or
54+
~msrest.pipeline.ClientRawResponse
55+
:raises: :class:`CloudError<msrestazure.azure_exceptions.CloudError>`
56+
"""
57+
# Construct URL
58+
url = self.get.metadata['url']
59+
path_format_arguments = {
60+
'tenantID': self._serialize.url("self.config.tenant_id", self.config.tenant_id, 'str')
61+
}
62+
url = self._client.format_url(url, **path_format_arguments)
63+
64+
# Construct parameters
65+
query_parameters = {}
66+
if filter is not None:
67+
query_parameters['$filter'] = self._serialize.query("filter", filter, 'str')
68+
query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str')
69+
70+
# Construct headers
71+
header_parameters = {}
72+
header_parameters['Content-Type'] = 'application/json; charset=utf-8'
73+
if self.config.generate_client_request_id:
74+
header_parameters['x-ms-client-request-id'] = str(uuid.uuid1())
75+
if custom_headers:
76+
header_parameters.update(custom_headers)
77+
if self.config.accept_language is not None:
78+
header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str')
79+
80+
# Construct and send request
81+
request = self._client.get(url, query_parameters)
82+
response = self._client.send(request, header_parameters, stream=False, **operation_config)
83+
84+
if response.status_code not in [200]:
85+
exp = CloudError(response)
86+
exp.request_id = response.headers.get('x-ms-request-id')
87+
raise exp
88+
89+
deserialized = None
90+
91+
if response.status_code == 200:
92+
deserialized = self._deserialize('Permissions', response)
93+
94+
if raw:
95+
client_raw_response = ClientRawResponse(deserialized, response)
96+
return client_raw_response
97+
98+
return deserialized
99+
get.metadata = {'url': '/{tenantID}/oauth2PermissionGrants'}
100+
101+
def post(
102+
self, body=None, custom_headers=None, raw=False, **operation_config):
103+
"""Grants OAuth2 permissions for the relevant resource Ids of an app.
104+
105+
:param body: The relevant app Service Principal Object Id and the
106+
Service Principal Objecit Id you want to grant.
107+
:type body: ~azure.graphrbac.models.Permissions
108+
:param dict custom_headers: headers that will be added to the request
109+
:param bool raw: returns the direct response alongside the
110+
deserialized response
111+
:param operation_config: :ref:`Operation configuration
112+
overrides<msrest:optionsforoperations>`.
113+
:return: Permissions or ClientRawResponse if raw=true
114+
:rtype: ~azure.graphrbac.models.Permissions or
115+
~msrest.pipeline.ClientRawResponse
116+
:raises: :class:`CloudError<msrestazure.azure_exceptions.CloudError>`
117+
"""
118+
# Construct URL
119+
url = self.post.metadata['url']
120+
path_format_arguments = {
121+
'tenantID': self._serialize.url("self.config.tenant_id", self.config.tenant_id, 'str')
122+
}
123+
url = self._client.format_url(url, **path_format_arguments)
124+
125+
# Construct parameters
126+
query_parameters = {}
127+
query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str')
128+
129+
# Construct headers
130+
header_parameters = {}
131+
header_parameters['Content-Type'] = 'application/json; charset=utf-8'
132+
if self.config.generate_client_request_id:
133+
header_parameters['x-ms-client-request-id'] = str(uuid.uuid1())
134+
if custom_headers:
135+
header_parameters.update(custom_headers)
136+
if self.config.accept_language is not None:
137+
header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str')
138+
139+
# Construct body
140+
if body is not None:
141+
body_content = self._serialize.body(body, 'Permissions')
142+
else:
143+
body_content = None
144+
145+
# Construct and send request
146+
request = self._client.post(url, query_parameters)
147+
response = self._client.send(
148+
request, header_parameters, body_content, stream=False, **operation_config)
149+
150+
if response.status_code not in [201]:
151+
exp = CloudError(response)
152+
exp.request_id = response.headers.get('x-ms-request-id')
153+
raise exp
154+
155+
deserialized = None
156+
157+
if response.status_code == 201:
158+
deserialized = self._deserialize('Permissions', response)
159+
160+
if raw:
161+
client_raw_response = ClientRawResponse(deserialized, response)
162+
return client_raw_response
163+
164+
return deserialized
165+
post.metadata = {'url': '/{tenantID}/oauth2PermissionGrants'}

azure-graphrbac/azure/graphrbac/operations/service_principals_operations.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,8 @@ def delete(
224224

225225
def get(
226226
self, object_id, custom_headers=None, raw=False, **operation_config):
227-
"""Gets service principal information from the directory.
227+
"""Gets service principal information from the directory. Query by
228+
objectId or pass a filter to query by appId.
228229
229230
:param object_id: The object ID of the service principal to get.
230231
:type object_id: str

0 commit comments

Comments
 (0)