Skip to content

Commit 808b31a

Browse files
Making identity optional when getting TURN credentials (Azure#21023)
* SDK update to allow User Id to be optional when getting Turn credentials * Fix Pylint issue * Fix build issues * Update shared_requirements.txt Co-authored-by: Xiang Yan <[email protected]>
1 parent 1a89eab commit 808b31a

20 files changed

+499
-182
lines changed

sdk/communication/azure-communication-networktraversal/azure/communication/networktraversal/_communication_relay_client.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def from_connection_string(
8585
@distributed_trace
8686
def get_relay_configuration(
8787
self,
88-
user, # type: CommunicationUserIdentifier
88+
user=None, # type: CommunicationUserIdentifier
8989
**kwargs # type: Any
9090
):
9191
# type: (Any) -> CommunicationRelayConfiguration
@@ -94,6 +94,9 @@ def get_relay_configuration(
9494
:return: CommunicationRelayConfiguration
9595
:rtype: ~azure.communication.networktraversal.CommunicationRelayConfiguration
9696
"""
97+
if user is None:
98+
return self._network_traversal_service_client.communication_network_traversal.issue_relay_configuration(
99+
None, **kwargs)
97100
return self._network_traversal_service_client.communication_network_traversal.issue_relay_configuration(
98101
user.properties['id'],
99102
**kwargs)

sdk/communication/azure-communication-networktraversal/azure/communication/networktraversal/_generated/_communication_network_traversal_client.py

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,30 @@
66
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
77
# --------------------------------------------------------------------------
88

9+
from copy import deepcopy
910
from typing import TYPE_CHECKING
1011

1112
from azure.core import PipelineClient
1213
from msrest import Deserializer, Serializer
1314

15+
from . import models
16+
from ._configuration import CommunicationNetworkTraversalClientConfiguration
17+
from .operations import CommunicationNetworkTraversalOperations
18+
1419
if TYPE_CHECKING:
1520
# pylint: disable=unused-import,ungrouped-imports
1621
from typing import Any
1722

18-
from azure.core.pipeline.transport import HttpRequest, HttpResponse
19-
20-
from ._configuration import CommunicationNetworkTraversalClientConfiguration
21-
from .operations import CommunicationNetworkTraversalOperations
22-
from . import models
23-
23+
from azure.core.rest import HttpRequest, HttpResponse
2424

2525
class CommunicationNetworkTraversalClient(object):
2626
"""Azure Communication Networking Service.
2727
2828
:ivar communication_network_traversal: CommunicationNetworkTraversalOperations operations
29-
:vartype communication_network_traversal: azure.communication.networktraversal.operations.CommunicationNetworkTraversalOperations
30-
:param endpoint: The communication resource, for example https://my-resource.communication.azure.com.
29+
:vartype communication_network_traversal:
30+
azure.communication.networktraversal.operations.CommunicationNetworkTraversalOperations
31+
:param endpoint: The communication resource, for example
32+
https://my-resource.communication.azure.com.
3133
:type endpoint: str
3234
"""
3335

@@ -37,35 +39,47 @@ def __init__(
3739
**kwargs # type: Any
3840
):
3941
# type: (...) -> None
40-
base_url = '{endpoint}'
42+
_base_url = '{endpoint}'
4143
self._config = CommunicationNetworkTraversalClientConfiguration(endpoint, **kwargs)
42-
self._client = PipelineClient(base_url=base_url, config=self._config, **kwargs)
44+
self._client = PipelineClient(base_url=_base_url, config=self._config, **kwargs)
4345

4446
client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)}
4547
self._serialize = Serializer(client_models)
46-
self._serialize.client_side_validation = False
4748
self._deserialize = Deserializer(client_models)
49+
self._serialize.client_side_validation = False
50+
self.communication_network_traversal = CommunicationNetworkTraversalOperations(self._client, self._config, self._serialize, self._deserialize)
4851

49-
self.communication_network_traversal = CommunicationNetworkTraversalOperations(
50-
self._client, self._config, self._serialize, self._deserialize)
5152

52-
def _send_request(self, http_request, **kwargs):
53-
# type: (HttpRequest, Any) -> HttpResponse
53+
def _send_request(
54+
self,
55+
request, # type: HttpRequest
56+
**kwargs # type: Any
57+
):
58+
# type: (...) -> HttpResponse
5459
"""Runs the network request through the client's chained policies.
5560
56-
:param http_request: The network request you want to make. Required.
57-
:type http_request: ~azure.core.pipeline.transport.HttpRequest
58-
:keyword bool stream: Whether the response payload will be streamed. Defaults to True.
61+
>>> from azure.core.rest import HttpRequest
62+
>>> request = HttpRequest("GET", "https://www.example.org/")
63+
<HttpRequest [GET], url: 'https://www.example.org/'>
64+
>>> response = client._send_request(request)
65+
<HttpResponse: 200 OK>
66+
67+
For more information on this code flow, see https://aka.ms/azsdk/python/protocol/quickstart
68+
69+
:param request: The network request you want to make. Required.
70+
:type request: ~azure.core.rest.HttpRequest
71+
:keyword bool stream: Whether the response payload will be streamed. Defaults to False.
5972
:return: The response of your network call. Does not do error handling on your response.
60-
:rtype: ~azure.core.pipeline.transport.HttpResponse
73+
:rtype: ~azure.core.rest.HttpResponse
6174
"""
75+
76+
request_copy = deepcopy(request)
6277
path_format_arguments = {
63-
'endpoint': self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True),
78+
"endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True),
6479
}
65-
http_request.url = self._client.format_url(http_request.url, **path_format_arguments)
66-
stream = kwargs.pop("stream", True)
67-
pipeline_response = self._client._pipeline.run(http_request, stream=stream, **kwargs)
68-
return pipeline_response.http_response
80+
81+
request_copy.url = self._client.format_url(request_copy.url, **path_format_arguments)
82+
return self._client.send_request(request_copy, **kwargs)
6983

7084
def close(self):
7185
# type: () -> None
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# --------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
# Code generated by Microsoft (R) AutoRest Code Generator.
5+
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
6+
# --------------------------------------------------------------------------
7+
8+
from azure.core.pipeline.transport import HttpRequest
9+
10+
def _convert_request(request, files=None):
11+
data = request.content if not files else None
12+
request = HttpRequest(method=request.method, url=request.url, headers=request.headers, data=data)
13+
if files:
14+
request.set_formdata_body(files)
15+
return request

sdk/communication/azure-communication-networktraversal/azure/communication/networktraversal/_generated/aio/_communication_network_traversal_client.py

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,25 @@
66
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
77
# --------------------------------------------------------------------------
88

9-
from typing import Any
9+
from copy import deepcopy
10+
from typing import Any, Awaitable
1011

1112
from azure.core import AsyncPipelineClient
12-
from azure.core.pipeline.transport import AsyncHttpResponse, HttpRequest
13+
from azure.core.rest import AsyncHttpResponse, HttpRequest
1314
from msrest import Deserializer, Serializer
1415

16+
from .. import models
1517
from ._configuration import CommunicationNetworkTraversalClientConfiguration
1618
from .operations import CommunicationNetworkTraversalOperations
17-
from .. import models
18-
1919

20-
class CommunicationNetworkTraversalClient(object):
20+
class CommunicationNetworkTraversalClient:
2121
"""Azure Communication Networking Service.
2222
2323
:ivar communication_network_traversal: CommunicationNetworkTraversalOperations operations
24-
:vartype communication_network_traversal: azure.communication.networktraversal.aio.operations.CommunicationNetworkTraversalOperations
25-
:param endpoint: The communication resource, for example https://my-resource.communication.azure.com.
24+
:vartype communication_network_traversal:
25+
azure.communication.networktraversal.aio.operations.CommunicationNetworkTraversalOperations
26+
:param endpoint: The communication resource, for example
27+
https://my-resource.communication.azure.com.
2628
:type endpoint: str
2729
"""
2830

@@ -31,34 +33,46 @@ def __init__(
3133
endpoint: str,
3234
**kwargs: Any
3335
) -> None:
34-
base_url = '{endpoint}'
36+
_base_url = '{endpoint}'
3537
self._config = CommunicationNetworkTraversalClientConfiguration(endpoint, **kwargs)
36-
self._client = AsyncPipelineClient(base_url=base_url, config=self._config, **kwargs)
38+
self._client = AsyncPipelineClient(base_url=_base_url, config=self._config, **kwargs)
3739

3840
client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)}
3941
self._serialize = Serializer(client_models)
40-
self._serialize.client_side_validation = False
4142
self._deserialize = Deserializer(client_models)
43+
self._serialize.client_side_validation = False
44+
self.communication_network_traversal = CommunicationNetworkTraversalOperations(self._client, self._config, self._serialize, self._deserialize)
4245

43-
self.communication_network_traversal = CommunicationNetworkTraversalOperations(
44-
self._client, self._config, self._serialize, self._deserialize)
4546

46-
async def _send_request(self, http_request: HttpRequest, **kwargs: Any) -> AsyncHttpResponse:
47+
def _send_request(
48+
self,
49+
request: HttpRequest,
50+
**kwargs: Any
51+
) -> Awaitable[AsyncHttpResponse]:
4752
"""Runs the network request through the client's chained policies.
4853
49-
:param http_request: The network request you want to make. Required.
50-
:type http_request: ~azure.core.pipeline.transport.HttpRequest
51-
:keyword bool stream: Whether the response payload will be streamed. Defaults to True.
54+
>>> from azure.core.rest import HttpRequest
55+
>>> request = HttpRequest("GET", "https://www.example.org/")
56+
<HttpRequest [GET], url: 'https://www.example.org/'>
57+
>>> response = await client._send_request(request)
58+
<AsyncHttpResponse: 200 OK>
59+
60+
For more information on this code flow, see https://aka.ms/azsdk/python/protocol/quickstart
61+
62+
:param request: The network request you want to make. Required.
63+
:type request: ~azure.core.rest.HttpRequest
64+
:keyword bool stream: Whether the response payload will be streamed. Defaults to False.
5265
:return: The response of your network call. Does not do error handling on your response.
53-
:rtype: ~azure.core.pipeline.transport.AsyncHttpResponse
66+
:rtype: ~azure.core.rest.AsyncHttpResponse
5467
"""
68+
69+
request_copy = deepcopy(request)
5570
path_format_arguments = {
56-
'endpoint': self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True),
71+
"endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True),
5772
}
58-
http_request.url = self._client.format_url(http_request.url, **path_format_arguments)
59-
stream = kwargs.pop("stream", True)
60-
pipeline_response = await self._client._pipeline.run(http_request, stream=stream, **kwargs)
61-
return pipeline_response.http_response
73+
74+
request_copy.url = self._client.format_url(request_copy.url, **path_format_arguments)
75+
return self._client.send_request(request_copy, **kwargs)
6276

6377
async def close(self) -> None:
6478
await self._client.close()

sdk/communication/azure-communication-networktraversal/azure/communication/networktraversal/_generated/aio/operations/_communication_network_traversal_operations.py

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,19 @@
55
# Code generated by Microsoft (R) AutoRest Code Generator.
66
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
77
# --------------------------------------------------------------------------
8+
import functools
89
from typing import Any, Callable, Dict, Generic, Optional, TypeVar
910
import warnings
1011

1112
from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error
1213
from azure.core.pipeline import PipelineResponse
13-
from azure.core.pipeline.transport import AsyncHttpResponse, HttpRequest
14+
from azure.core.pipeline.transport import AsyncHttpResponse
15+
from azure.core.rest import HttpRequest
16+
from azure.core.tracing.decorator_async import distributed_trace_async
1417

1518
from ... import models as _models
19+
from ..._vendor import _convert_request
20+
from ...operations._communication_network_traversal_operations import build_issue_relay_configuration_request
1621

1722
T = TypeVar('T')
1823
ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]]
@@ -39,9 +44,10 @@ def __init__(self, client, config, serializer, deserializer) -> None:
3944
self._deserialize = deserializer
4045
self._config = config
4146

47+
@distributed_trace_async
4248
async def issue_relay_configuration(
4349
self,
44-
id: str,
50+
id: Optional[str] = None,
4551
**kwargs: Any
4652
) -> "_models.CommunicationRelayConfiguration":
4753
"""Issue a configuration for an STUN/TURN server for an existing identity.
@@ -61,37 +67,31 @@ async def issue_relay_configuration(
6167
}
6268
error_map.update(kwargs.pop('error_map', {}))
6369

64-
_body = _models.CommunicationRelayConfigurationRequest(id=id)
65-
api_version = "2021-06-21-preview"
66-
content_type = kwargs.pop("content_type", "application/json")
67-
accept = "application/json"
70+
content_type = kwargs.pop('content_type', "application/json") # type: Optional[str]
6871

69-
# Construct URL
70-
url = self.issue_relay_configuration.metadata['url'] # type: ignore
72+
_body = _models.CommunicationRelayConfigurationRequest(id=id)
73+
if _body is not None:
74+
json = self._serialize.body(_body, 'CommunicationRelayConfigurationRequest')
75+
else:
76+
json = None
77+
78+
request = build_issue_relay_configuration_request(
79+
content_type=content_type,
80+
json=json,
81+
template_url=self.issue_relay_configuration.metadata['url'],
82+
)
83+
request = _convert_request(request)
7184
path_format_arguments = {
72-
'endpoint': self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True),
85+
"endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True),
7386
}
74-
url = self._client.format_url(url, **path_format_arguments)
75-
76-
# Construct parameters
77-
query_parameters = {} # type: Dict[str, Any]
78-
query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str')
79-
80-
# Construct headers
81-
header_parameters = {} # type: Dict[str, Any]
82-
header_parameters['Content-Type'] = self._serialize.header("content_type", content_type, 'str')
83-
header_parameters['Accept'] = self._serialize.header("accept", accept, 'str')
84-
85-
body_content_kwargs = {} # type: Dict[str, Any]
86-
body_content = self._serialize.body(_body, 'CommunicationRelayConfigurationRequest')
87-
body_content_kwargs['content'] = body_content
88-
request = self._client.post(url, query_parameters, header_parameters, **body_content_kwargs)
89-
pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
87+
request.url = self._client.format_url(request.url, **path_format_arguments)
88+
89+
pipeline_response = await self._client.send_request(request, stream=False, _return_pipeline_response=True, **kwargs)
9090
response = pipeline_response.http_response
9191

9292
if response.status_code not in [200]:
9393
map_error(status_code=response.status_code, response=response, error_map=error_map)
94-
error = self._deserialize.failsafe_deserialize(_models.CommunicationErrorResponse, response)
94+
error = self._deserialize.failsafe_deserialize(_models.CommunicationErrorResponse, pipeline_response)
9595
raise HttpResponseError(response=response, model=error)
9696

9797
deserialized = self._deserialize('CommunicationRelayConfiguration', pipeline_response)
@@ -100,4 +100,6 @@ async def issue_relay_configuration(
100100
return cls(pipeline_response, deserialized, {})
101101

102102
return deserialized
103+
103104
issue_relay_configuration.metadata = {'url': '/networktraversal/:issueRelayConfiguration'} # type: ignore
105+

0 commit comments

Comments
 (0)