Skip to content

Commit

Permalink
TURN: Adding RouteType optional parameter to GetRelayConfiguration (A…
Browse files Browse the repository at this point in the history
…zure#21698)

* Add autogenerated code

* RouteType option and tests

* Update PR, fixes with API view

* Update PR

* Update PR

* Update Changelog and Readme
  • Loading branch information
AriZavala2 authored and rakshith91 committed Nov 18, 2021
1 parent 63d5673 commit dc7433f
Show file tree
Hide file tree
Showing 30 changed files with 751 additions and 140 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
# Release History

## 1.0.0-beta.2 (2021-11-18)

### Features Added

- Made User Identity an optional parameter when getting a Relay Configuration.
- Added RouteType as optional parameter when getting a Relay Configuration so users can
choose the routing type protocol of the requested Relay Configuration.

### Breaking Changes

### Bugs Fixed

### Other Changes

## 1.0.0b1 (2021-08-16)

- Preview release of `azure-communication-networktraversal`.

The first preview of the Azure Communication Relay Client has the following features:

- get a Relay Configuration by creating a CommunicationRelayClient

### Added

- Added CommunicationRelayClient in preview.
- Added CommunicationRelayClient.get_relay_configuration in preview.

Expand Down
38 changes: 37 additions & 1 deletion sdk/communication/azure-communication-networktraversal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ identity_client = CommunicationIdentityClient.from_connection_string(self.connec
relay_client = CommunicationRelayClient.from_connection_string(self.connection_string)
```

### Getting the relay configuration
### Getting the relay configuration providing a user

```python
# We need a user from Identity
Expand All @@ -77,6 +77,42 @@ for iceServer in config.ice_servers:
print('Url:' + url)
```

### Getting the relay configuration without providing a user

```python
relay_configuration = relay_client.get_relay_configuration()

for iceServer in config.ice_servers:
assert iceServer.username is not None
print('Username: ' + iceServer.username)

assert iceServer.credential is not None
print('Credential: ' + iceServer.credential)

assert iceServer.urls is not None
for url in iceServer.urls:
print('Url:' + url)
```

### Getting the relay configuration without providing a RouteType

```python
# We need a user from Identity
user = identity_client.create_user()
relay_configuration = relay_client.get_relay_configuration(user, RouteType.NEAREST)

for iceServer in config.ice_servers:
assert iceServer.username is not None
print('Username: ' + iceServer.username)

assert iceServer.credential is not None
print('Credential: ' + iceServer.credential)

assert iceServer.urls is not None
for url in iceServer.urls:
print('Url:' + url)
```

# Troubleshooting

The Azure Communication Relay client will raise exceptions defined in [Azure Core][azure_core].
Expand Down
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

0 comments on commit dc7433f

Please sign in to comment.