|
| 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'} |
0 commit comments