Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TURN: Adding RouteType optional parameter to GetRelayConfiguration #21698

Merged
merged 6 commits into from
Nov 17, 2021
Merged
Show file tree
Hide file tree
Changes from 5 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 @@ -6,3 +6,4 @@

# pylint: disable=bad-option-value, unused-import
from ._communication_relay_client import CommunicationRelayClient
from ._generated.models import RouteType
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Licensed under the MIT License.
# ------------------------------------

from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING

from azure.core.tracing.decorator import distributed_trace

Expand All @@ -18,6 +18,7 @@
if TYPE_CHECKING:
from azure.core.credentials import TokenCredential
from azure.communication.identity import CommunicationUserIdentifier
from azure.communication.networktraversal import RouteType

class CommunicationRelayClient(object):
"""Azure Communication Services Relay client.
Expand Down Expand Up @@ -86,17 +87,22 @@ def from_connection_string(
def get_relay_configuration(
self,
user=None, # type: CommunicationUserIdentifier
route_type=None, # type: Optional[Union[str, "RouteType"]]
**kwargs # type: Any
):
# type: (Any) -> CommunicationRelayConfiguration
# type: (...) -> CommunicationRelayConfiguration
"""get a Communication Relay configuration
:param: CommunicationUserIdentifier user: A user from which we will get an id
:param user: Azure Communication User
:type user: ~azure.communication.identity.CommunicationUserIdentifier
:param route_type: Azure Communication Route Type
:type route_type: ~azure.communication.networktraversal.RouteType
:return: CommunicationRelayConfiguration
:rtype: ~azure.communication.networktraversal.CommunicationRelayConfiguration
:rtype: ~azure.communication.networktraversal.models.CommunicationRelayConfiguration
"""
if user is None:
return self._network_traversal_service_client.communication_network_traversal.issue_relay_configuration(
None, **kwargs)
None, route_type, **kwargs)
return self._network_traversal_service_client.communication_network_traversal.issue_relay_configuration(
user.properties['id'],
route_type,
**kwargs)
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ class CommunicationNetworkTraversalClient(object):
:param endpoint: The communication resource, for example
https://my-resource.communication.azure.com.
:type endpoint: str
:keyword api_version: Api Version. The default value is "2021-10-08-preview". Note that
overriding this default value may result in unsupported behavior.
:paramtype api_version: str
"""

def __init__(
Expand All @@ -40,7 +43,7 @@ def __init__(
):
# type: (...) -> None
_base_url = '{endpoint}'
self._config = CommunicationNetworkTraversalClientConfiguration(endpoint, **kwargs)
self._config = CommunicationNetworkTraversalClientConfiguration(endpoint=endpoint, **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)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class CommunicationNetworkTraversalClientConfiguration(Configuration):

:param endpoint: The communication resource, for example https://my-resource.communication.azure.com.
:type endpoint: str
:keyword api_version: Api Version. The default value is "2021-10-08-preview". Note that overriding this default value may result in unsupported behavior.
:paramtype api_version: str
"""

def __init__(
Expand All @@ -33,12 +35,14 @@ def __init__(
**kwargs # type: Any
):
# type: (...) -> None
super(CommunicationNetworkTraversalClientConfiguration, self).__init__(**kwargs)
api_version = kwargs.pop('api_version', "2021-10-08-preview") # type: str

if endpoint is None:
raise ValueError("Parameter 'endpoint' must not be None.")
super(CommunicationNetworkTraversalClientConfiguration, self).__init__(**kwargs)

self.endpoint = endpoint
self.api_version = "2021-06-21-preview"
self.api_version = api_version
kwargs.setdefault('sdk_moniker', 'communicationnetworktraversalclient/{}'.format(VERSION))
self._configure(**kwargs)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@

from ._communication_network_traversal_client import CommunicationNetworkTraversalClient
__all__ = ['CommunicationNetworkTraversalClient']

try:
from ._patch import patch_sdk # type: ignore
patch_sdk()
except ImportError:
pass
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class CommunicationNetworkTraversalClient:
:param endpoint: The communication resource, for example
https://my-resource.communication.azure.com.
:type endpoint: str
:keyword api_version: Api Version. The default value is "2021-10-08-preview". Note that
overriding this default value may result in unsupported behavior.
:paramtype api_version: str
"""

def __init__(
Expand All @@ -34,7 +37,7 @@ def __init__(
**kwargs: Any
) -> None:
_base_url = '{endpoint}'
self._config = CommunicationNetworkTraversalClientConfiguration(endpoint, **kwargs)
self._config = CommunicationNetworkTraversalClientConfiguration(endpoint=endpoint, **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)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,23 @@ class CommunicationNetworkTraversalClientConfiguration(Configuration):
:param endpoint: The communication resource, for example https://my-resource.communication.azure.com.
:type endpoint: str
:keyword api_version: Api Version. The default value is "2021-10-08-preview". Note that overriding this default value may result in unsupported behavior.
:paramtype api_version: str
"""

def __init__(
self,
endpoint: str,
**kwargs: Any
) -> None:
super(CommunicationNetworkTraversalClientConfiguration, self).__init__(**kwargs)
api_version = kwargs.pop('api_version', "2021-10-08-preview") # type: str

if endpoint is None:
raise ValueError("Parameter 'endpoint' must not be None.")
super(CommunicationNetworkTraversalClientConfiguration, self).__init__(**kwargs)

self.endpoint = endpoint
self.api_version = "2021-06-21-preview"
self.api_version = api_version
kwargs.setdefault('sdk_moniker', 'communicationnetworktraversalclient/{}'.format(VERSION))
self._configure(**kwargs)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# 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
from typing import Any, Callable, Dict, Generic, Optional, TypeVar, Union
import warnings

from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error
Expand All @@ -18,7 +18,6 @@
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 Down Expand Up @@ -48,6 +47,7 @@ def __init__(self, client, config, serializer, deserializer) -> None:
async def issue_relay_configuration(
self,
id: Optional[str] = None,
route_type: Optional[Union[str, "_models.RouteType"]] = None,
**kwargs: Any
) -> "_models.CommunicationRelayConfiguration":
"""Issue a configuration for an STUN/TURN server for an existing identity.
Expand All @@ -56,6 +56,12 @@ async def issue_relay_configuration(

:param id: An existing ACS identity.
:type id: str
:param route_type: The routing methodology to where the ICE server will be located from the
client.
:type route_type: str or ~azure.communication.networktraversal.models.RouteType
:keyword api_version: Api Version. The default value is "2021-10-08-preview". Note that
overriding this default value may result in unsupported behavior.
:paramtype api_version: str
:keyword callable cls: A custom type or function that will be passed the direct response
:return: CommunicationRelayConfiguration, or the result of cls(response)
:rtype: ~azure.communication.networktraversal.models.CommunicationRelayConfiguration
Expand All @@ -67,15 +73,17 @@ async def issue_relay_configuration(
}
error_map.update(kwargs.pop('error_map', {}))

api_version = kwargs.pop('api_version', "2021-10-08-preview") # type: str
content_type = kwargs.pop('content_type', "application/json") # type: Optional[str]

_body = _models.CommunicationRelayConfigurationRequest(id=id)
_body = _models.CommunicationRelayConfigurationRequest(id=id, route_type=route_type)
if _body is not None:
json = self._serialize.body(_body, 'CommunicationRelayConfigurationRequest')
else:
json = None

request = build_issue_relay_configuration_request(
api_version=api_version,
content_type=content_type,
json=json,
template_url=self.issue_relay_configuration.metadata['url'],
Expand All @@ -86,7 +94,7 @@ async def issue_relay_configuration(
}
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)
pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
response = pipeline_response.http_response

if response.status_code not in [200]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@
from ._models import CommunicationRelayConfiguration # type: ignore
from ._models import CommunicationRelayConfigurationRequest # type: ignore

from ._communication_network_traversal_client_enums import (
RouteType,
)

__all__ = [
'CommunicationError',
'CommunicationErrorResponse',
'CommunicationIceServer',
'CommunicationRelayConfiguration',
'CommunicationRelayConfigurationRequest',
'RouteType',
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# coding=utf-8
# --------------------------------------------------------------------------
# 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 enum import Enum
from six import with_metaclass
from azure.core import CaseInsensitiveEnumMeta


class RouteType(with_metaclass(CaseInsensitiveEnumMeta, str, Enum)):
"""The routing methodology to where the ICE server will be located from the client.
"""

ANY = "any"
NEAREST = "nearest"
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,23 @@ class CommunicationIceServer(msrest.serialization.Model):
:vartype username: str
:ivar credential: Required. Credential for the server.
:vartype credential: str
:ivar route_type: Required. The routing methodology to where the ICE server will be located
from the client. Possible values include: "any", "nearest".
:vartype route_type: str or ~azure.communication.networktraversal.models.RouteType
"""

_validation = {
'urls': {'required': True},
'username': {'required': True},
'credential': {'required': True},
'route_type': {'required': True},
}

_attribute_map = {
'urls': {'key': 'urls', 'type': '[str]'},
'username': {'key': 'username', 'type': 'str'},
'credential': {'key': 'credential', 'type': 'str'},
'route_type': {'key': 'routeType', 'type': 'str'},
}

def __init__(
Expand All @@ -128,11 +133,15 @@ def __init__(
:paramtype username: str
:keyword credential: Required. Credential for the server.
:paramtype credential: str
:keyword route_type: Required. The routing methodology to where the ICE server will be located
from the client. Possible values include: "any", "nearest".
:paramtype route_type: str or ~azure.communication.networktraversal.models.RouteType
"""
super(CommunicationIceServer, self).__init__(**kwargs)
self.urls = kwargs['urls']
self.username = kwargs['username']
self.credential = kwargs['credential']
self.route_type = kwargs['route_type']


class CommunicationRelayConfiguration(msrest.serialization.Model):
Expand Down Expand Up @@ -181,10 +190,14 @@ class CommunicationRelayConfigurationRequest(msrest.serialization.Model):
:ivar id: An existing ACS identity.
:vartype id: str
:ivar route_type: The routing methodology to where the ICE server will be located from the
client. Possible values include: "any", "nearest".
:vartype route_type: str or ~azure.communication.networktraversal.models.RouteType
"""

_attribute_map = {
'id': {'key': 'id', 'type': 'str'},
'route_type': {'key': 'routeType', 'type': 'str'},
}

def __init__(
Expand All @@ -194,6 +207,10 @@ def __init__(
"""
:keyword id: An existing ACS identity.
:paramtype id: str
:keyword route_type: The routing methodology to where the ICE server will be located from the
client. Possible values include: "any", "nearest".
:paramtype route_type: str or ~azure.communication.networktraversal.models.RouteType
"""
super(CommunicationRelayConfigurationRequest, self).__init__(**kwargs)
self.id = kwargs.get('id', None)
self.route_type = kwargs.get('route_type', None)
Loading