Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def from_connection_string(
@distributed_trace
def get_relay_configuration(
self,
user, # type: CommunicationUserIdentifier
user=None, # type: CommunicationUserIdentifier
**kwargs # type: Any
):
# type: (Any) -> CommunicationRelayConfiguration
Expand All @@ -94,6 +94,9 @@ def get_relay_configuration(
:return: CommunicationRelayConfiguration
:rtype: ~azure.communication.networktraversal.CommunicationRelayConfiguration
"""
if user is None:
return self._network_traversal_service_client.communication_network_traversal.issue_relay_configuration(
None, **kwargs)
return self._network_traversal_service_client.communication_network_traversal.issue_relay_configuration(
user.properties['id'],
**kwargs)
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,30 @@
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------

from copy import deepcopy
from typing import TYPE_CHECKING

from azure.core import PipelineClient
from msrest import Deserializer, Serializer

from . import models
from ._configuration import CommunicationNetworkTraversalClientConfiguration
from .operations import CommunicationNetworkTraversalOperations

if TYPE_CHECKING:
# pylint: disable=unused-import,ungrouped-imports
from typing import Any

from azure.core.pipeline.transport import HttpRequest, HttpResponse

from ._configuration import CommunicationNetworkTraversalClientConfiguration
from .operations import CommunicationNetworkTraversalOperations
from . import models

from azure.core.rest import HttpRequest, HttpResponse

class CommunicationNetworkTraversalClient(object):
"""Azure Communication Networking Service.

:ivar communication_network_traversal: CommunicationNetworkTraversalOperations operations
:vartype communication_network_traversal: azure.communication.networktraversal.operations.CommunicationNetworkTraversalOperations
:param endpoint: The communication resource, for example https://my-resource.communication.azure.com.
:vartype communication_network_traversal:
azure.communication.networktraversal.operations.CommunicationNetworkTraversalOperations
:param endpoint: The communication resource, for example
https://my-resource.communication.azure.com.
:type endpoint: str
"""

Expand All @@ -37,35 +39,47 @@ def __init__(
**kwargs # type: Any
):
# type: (...) -> None
base_url = '{endpoint}'
_base_url = '{endpoint}'
self._config = CommunicationNetworkTraversalClientConfiguration(endpoint, **kwargs)
self._client = PipelineClient(base_url=base_url, config=self._config, **kwargs)
self._client = PipelineClient(base_url=_base_url, config=self._config, **kwargs)

client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)}
self._serialize = Serializer(client_models)
self._serialize.client_side_validation = False
self._deserialize = Deserializer(client_models)
self._serialize.client_side_validation = False
self.communication_network_traversal = CommunicationNetworkTraversalOperations(self._client, self._config, self._serialize, self._deserialize)

self.communication_network_traversal = CommunicationNetworkTraversalOperations(
self._client, self._config, self._serialize, self._deserialize)

def _send_request(self, http_request, **kwargs):
# type: (HttpRequest, Any) -> HttpResponse
def _send_request(
self,
request, # type: HttpRequest
**kwargs # type: Any
):
# type: (...) -> HttpResponse
"""Runs the network request through the client's chained policies.

:param http_request: The network request you want to make. Required.
:type http_request: ~azure.core.pipeline.transport.HttpRequest
:keyword bool stream: Whether the response payload will be streamed. Defaults to True.
>>> from azure.core.rest import HttpRequest
>>> request = HttpRequest("GET", "https://www.example.org/")
<HttpRequest [GET], url: 'https://www.example.org/'>
>>> response = client._send_request(request)
<HttpResponse: 200 OK>

For more information on this code flow, see https://aka.ms/azsdk/python/protocol/quickstart

:param request: The network request you want to make. Required.
:type request: ~azure.core.rest.HttpRequest
:keyword bool stream: Whether the response payload will be streamed. Defaults to False.
:return: The response of your network call. Does not do error handling on your response.
:rtype: ~azure.core.pipeline.transport.HttpResponse
:rtype: ~azure.core.rest.HttpResponse
"""

request_copy = deepcopy(request)
path_format_arguments = {
'endpoint': self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True),
"endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True),
}
http_request.url = self._client.format_url(http_request.url, **path_format_arguments)
stream = kwargs.pop("stream", True)
pipeline_response = self._client._pipeline.run(http_request, stream=stream, **kwargs)
return pipeline_response.http_response

request_copy.url = self._client.format_url(request_copy.url, **path_format_arguments)
return self._client.send_request(request_copy, **kwargs)

def close(self):
# type: () -> None
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------

from azure.core.pipeline.transport import HttpRequest

def _convert_request(request, files=None):
data = request.content if not files else None
request = HttpRequest(method=request.method, url=request.url, headers=request.headers, data=data)
if files:
request.set_formdata_body(files)
return request
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,25 @@
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------

from typing import Any
from copy import deepcopy
from typing import Any, Awaitable

from azure.core import AsyncPipelineClient
from azure.core.pipeline.transport import AsyncHttpResponse, HttpRequest
from azure.core.rest import AsyncHttpResponse, HttpRequest
from msrest import Deserializer, Serializer

from .. import models
from ._configuration import CommunicationNetworkTraversalClientConfiguration
from .operations import CommunicationNetworkTraversalOperations
from .. import models


class CommunicationNetworkTraversalClient(object):
class CommunicationNetworkTraversalClient:
"""Azure Communication Networking Service.

:ivar communication_network_traversal: CommunicationNetworkTraversalOperations operations
:vartype communication_network_traversal: azure.communication.networktraversal.aio.operations.CommunicationNetworkTraversalOperations
:param endpoint: The communication resource, for example https://my-resource.communication.azure.com.
:vartype communication_network_traversal:
azure.communication.networktraversal.aio.operations.CommunicationNetworkTraversalOperations
:param endpoint: The communication resource, for example
https://my-resource.communication.azure.com.
:type endpoint: str
"""

Expand All @@ -31,34 +33,46 @@ def __init__(
endpoint: str,
**kwargs: Any
) -> None:
base_url = '{endpoint}'
_base_url = '{endpoint}'
self._config = CommunicationNetworkTraversalClientConfiguration(endpoint, **kwargs)
self._client = AsyncPipelineClient(base_url=base_url, config=self._config, **kwargs)
self._client = AsyncPipelineClient(base_url=_base_url, config=self._config, **kwargs)

client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)}
self._serialize = Serializer(client_models)
self._serialize.client_side_validation = False
self._deserialize = Deserializer(client_models)
self._serialize.client_side_validation = False
self.communication_network_traversal = CommunicationNetworkTraversalOperations(self._client, self._config, self._serialize, self._deserialize)

self.communication_network_traversal = CommunicationNetworkTraversalOperations(
self._client, self._config, self._serialize, self._deserialize)

async def _send_request(self, http_request: HttpRequest, **kwargs: Any) -> AsyncHttpResponse:
def _send_request(
self,
request: HttpRequest,
**kwargs: Any
) -> Awaitable[AsyncHttpResponse]:
"""Runs the network request through the client's chained policies.

:param http_request: The network request you want to make. Required.
:type http_request: ~azure.core.pipeline.transport.HttpRequest
:keyword bool stream: Whether the response payload will be streamed. Defaults to True.
>>> from azure.core.rest import HttpRequest
>>> request = HttpRequest("GET", "https://www.example.org/")
<HttpRequest [GET], url: 'https://www.example.org/'>
>>> response = await client._send_request(request)
<AsyncHttpResponse: 200 OK>

For more information on this code flow, see https://aka.ms/azsdk/python/protocol/quickstart

:param request: The network request you want to make. Required.
:type request: ~azure.core.rest.HttpRequest
:keyword bool stream: Whether the response payload will be streamed. Defaults to False.
:return: The response of your network call. Does not do error handling on your response.
:rtype: ~azure.core.pipeline.transport.AsyncHttpResponse
:rtype: ~azure.core.rest.AsyncHttpResponse
"""

request_copy = deepcopy(request)
path_format_arguments = {
'endpoint': self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True),
"endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curious why you're switching from ' to " here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know, this is the autogenerated and not sure why it changed.

}
http_request.url = self._client.format_url(http_request.url, **path_format_arguments)
stream = kwargs.pop("stream", True)
pipeline_response = await self._client._pipeline.run(http_request, stream=stream, **kwargs)
return pipeline_response.http_response

request_copy.url = self._client.format_url(request_copy.url, **path_format_arguments)
return self._client.send_request(request_copy, **kwargs)

async def close(self) -> None:
await self._client.close()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,19 @@
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------
import functools
from typing import Any, Callable, Dict, Generic, Optional, TypeVar
import warnings

from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error
from azure.core.pipeline import PipelineResponse
from azure.core.pipeline.transport import AsyncHttpResponse, HttpRequest
from azure.core.pipeline.transport import AsyncHttpResponse
from azure.core.rest import HttpRequest
from azure.core.tracing.decorator_async import distributed_trace_async

from ... import models as _models
from ..._vendor import _convert_request
from ...operations._communication_network_traversal_operations import build_issue_relay_configuration_request

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

@distributed_trace_async
async def issue_relay_configuration(
self,
id: str,
id: Optional[str] = None,
**kwargs: Any
) -> "_models.CommunicationRelayConfiguration":
"""Issue a configuration for an STUN/TURN server for an existing identity.
Expand All @@ -61,37 +67,31 @@ async def issue_relay_configuration(
}
error_map.update(kwargs.pop('error_map', {}))

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

# Construct URL
url = self.issue_relay_configuration.metadata['url'] # type: ignore
_body = _models.CommunicationRelayConfigurationRequest(id=id)
if _body is not None:
json = self._serialize.body(_body, 'CommunicationRelayConfigurationRequest')
else:
json = None

request = build_issue_relay_configuration_request(
content_type=content_type,
json=json,
template_url=self.issue_relay_configuration.metadata['url'],
)
request = _convert_request(request)
path_format_arguments = {
'endpoint': self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True),
"endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True),
}
url = self._client.format_url(url, **path_format_arguments)

# Construct parameters
query_parameters = {} # type: Dict[str, Any]
query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str')

# Construct headers
header_parameters = {} # type: Dict[str, Any]
header_parameters['Content-Type'] = self._serialize.header("content_type", content_type, 'str')
header_parameters['Accept'] = self._serialize.header("accept", accept, 'str')

body_content_kwargs = {} # type: Dict[str, Any]
body_content = self._serialize.body(_body, 'CommunicationRelayConfigurationRequest')
body_content_kwargs['content'] = body_content
request = self._client.post(url, query_parameters, header_parameters, **body_content_kwargs)
pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
request.url = self._client.format_url(request.url, **path_format_arguments)

pipeline_response = await self._client.send_request(request, stream=False, _return_pipeline_response=True, **kwargs)
response = pipeline_response.http_response

if response.status_code not in [200]:
map_error(status_code=response.status_code, response=response, error_map=error_map)
error = self._deserialize.failsafe_deserialize(_models.CommunicationErrorResponse, response)
error = self._deserialize.failsafe_deserialize(_models.CommunicationErrorResponse, pipeline_response)
raise HttpResponseError(response=response, model=error)

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

return deserialized

issue_relay_configuration.metadata = {'url': '/networktraversal/:issueRelayConfiguration'} # type: ignore

Loading