Skip to content

Commit 9b8e099

Browse files
authored
Add MQTT generate token implementation (#36303)
* generate new REST client * implement MQTT Generate Token * add test case * ignore check spell words * update changelog * update changelog * update latest version * update changelog * add EOL * change field name to webpubsub_client_access * rename to webpubsub_client_protocol * rename to client_protocol * update changelog --------- Co-authored-by: chuongnguyen <[email protected]>
1 parent 7e187b9 commit 9b8e099

File tree

26 files changed

+1733
-725
lines changed

26 files changed

+1733
-725
lines changed

sdk/webpubsub/azure-messaging-webpubsubservice/CHANGELOG.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
# Release History
22

3-
## 1.1.1 (Unreleased)
3+
## 1.2.0 (2024-08-02)
44

55
### Features Added
6-
7-
### Breaking Changes
8-
9-
### Bugs Fixed
10-
11-
### Other Changes
6+
- Change API version to `2024-01-01`
7+
- Added a `webpubsub_client_access` option to specify the type of client access when generating token. This is used to generate token and client connection URL for a specific client endpoint type
8+
- Added operations `add_connections_to_groups` and `remove_connections_from_groups`
129

1310
## 1.1.0 (2024-04-24)
1411

sdk/webpubsub/azure-messaging-webpubsubservice/azure/messaging/webpubsubservice/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@
1313

1414
try:
1515
from ._patch import __all__ as _patch_all
16-
from ._patch import * # type: ignore # pylint: disable=unused-wildcard-import
16+
from ._patch import * # pylint: disable=unused-wildcard-import
1717
except ImportError:
1818
_patch_all = []
1919
from ._patch import patch_sdk as _patch_sdk
2020

21-
__all__ = ["WebPubSubServiceClient"]
21+
__all__ = [
22+
"WebPubSubServiceClient",
23+
]
2224
__all__.extend([p for p in _patch_all if p not in __all__])
2325

2426
_patch_sdk()

sdk/webpubsub/azure-messaging-webpubsubservice/azure/messaging/webpubsubservice/_client.py

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88

99
from copy import deepcopy
1010
from typing import Any, TYPE_CHECKING
11+
from typing_extensions import Self
1112

1213
from azure.core import PipelineClient
14+
from azure.core.pipeline import policies
1315
from azure.core.rest import HttpRequest, HttpResponse
1416

1517
from ._configuration import WebPubSubServiceClientConfiguration
@@ -33,21 +35,38 @@ class WebPubSubServiceClient(
3335
:type endpoint: str
3436
:param credential: Credential needed for the client to connect to Azure. Required.
3537
:type credential: ~azure.core.credentials.TokenCredential
36-
:keyword api_version: Api Version. Default value is "2022-11-01". Note that overriding this
38+
:keyword api_version: Api Version. Default value is "2024-01-01". Note that overriding this
3739
default value may result in unsupported behavior.
3840
:paramtype api_version: str
3941
"""
4042

4143
def __init__(self, hub: str, endpoint: str, credential: "TokenCredential", **kwargs: Any) -> None:
42-
_endpoint = "{Endpoint}"
44+
_endpoint = "{endpoint}"
4345
self._config = WebPubSubServiceClientConfiguration(hub=hub, endpoint=endpoint, credential=credential, **kwargs)
44-
self._client = PipelineClient(base_url=_endpoint, config=self._config, **kwargs)
46+
_policies = kwargs.pop("policies", None)
47+
if _policies is None:
48+
_policies = [
49+
policies.RequestIdPolicy(**kwargs),
50+
self._config.headers_policy,
51+
self._config.user_agent_policy,
52+
self._config.proxy_policy,
53+
policies.ContentDecodePolicy(**kwargs),
54+
self._config.redirect_policy,
55+
self._config.retry_policy,
56+
self._config.authentication_policy,
57+
self._config.custom_hook_policy,
58+
self._config.logging_policy,
59+
policies.DistributedTracingPolicy(**kwargs),
60+
policies.SensitiveHeaderCleanupPolicy(**kwargs) if self._config.redirect_policy else None,
61+
self._config.http_logging_policy,
62+
]
63+
self._client: PipelineClient = PipelineClient(base_url=_endpoint, policies=_policies, **kwargs)
4564

4665
self._serialize = Serializer()
4766
self._deserialize = Deserializer()
4867
self._serialize.client_side_validation = False
4968

50-
def send_request(self, request: HttpRequest, **kwargs: Any) -> HttpResponse:
69+
def send_request(self, request: HttpRequest, *, stream: bool = False, **kwargs: Any) -> HttpResponse:
5170
"""Runs the network request through the client's chained policies.
5271
5372
>>> from azure.core.rest import HttpRequest
@@ -67,21 +86,18 @@ def send_request(self, request: HttpRequest, **kwargs: Any) -> HttpResponse:
6786

6887
request_copy = deepcopy(request)
6988
path_format_arguments = {
70-
"Endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True),
89+
"endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True),
7190
}
7291

7392
request_copy.url = self._client.format_url(request_copy.url, **path_format_arguments)
74-
return self._client.send_request(request_copy, **kwargs)
93+
return self._client.send_request(request_copy, stream=stream, **kwargs) # type: ignore
7594

76-
def close(self):
77-
# type: () -> None
95+
def close(self) -> None:
7896
self._client.close()
7997

80-
def __enter__(self):
81-
# type: () -> WebPubSubServiceClient
98+
def __enter__(self) -> Self:
8299
self._client.__enter__()
83100
return self
84101

85-
def __exit__(self, *exc_details):
86-
# type: (Any) -> None
102+
def __exit__(self, *exc_details: Any) -> None:
87103
self._client.__exit__(*exc_details)

sdk/webpubsub/azure-messaging-webpubsubservice/azure/messaging/webpubsubservice/_configuration.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
from typing import Any, TYPE_CHECKING
1010

11-
from azure.core.configuration import Configuration
1211
from azure.core.pipeline import policies
1312

1413
from ._version import VERSION
@@ -18,7 +17,7 @@
1817
from azure.core.credentials import TokenCredential
1918

2019

21-
class WebPubSubServiceClientConfiguration(Configuration): # pylint: disable=too-many-instance-attributes
20+
class WebPubSubServiceClientConfiguration: # pylint: disable=too-many-instance-attributes,name-too-long
2221
"""Configuration for WebPubSubServiceClient.
2322
2423
Note that all parameters used to create this instance are saved as instance
@@ -31,14 +30,13 @@ class WebPubSubServiceClientConfiguration(Configuration): # pylint: disable=too
3130
:type endpoint: str
3231
:param credential: Credential needed for the client to connect to Azure. Required.
3332
:type credential: ~azure.core.credentials.TokenCredential
34-
:keyword api_version: Api Version. Default value is "2022-11-01". Note that overriding this
33+
:keyword api_version: Api Version. Default value is "2024-01-01". Note that overriding this
3534
default value may result in unsupported behavior.
3635
:paramtype api_version: str
3736
"""
3837

3938
def __init__(self, hub: str, endpoint: str, credential: "TokenCredential", **kwargs: Any) -> None:
40-
super(WebPubSubServiceClientConfiguration, self).__init__(**kwargs)
41-
api_version = kwargs.pop("api_version", "2022-11-01") # type: str
39+
api_version: str = kwargs.pop("api_version", "2024-01-01")
4240

4341
if hub is None:
4442
raise ValueError("Parameter 'hub' must not be None.")
@@ -53,20 +51,18 @@ def __init__(self, hub: str, endpoint: str, credential: "TokenCredential", **kwa
5351
self.api_version = api_version
5452
self.credential_scopes = kwargs.pop("credential_scopes", ["https://webpubsub.azure.com/.default"])
5553
kwargs.setdefault("sdk_moniker", "messaging-webpubsubservice/{}".format(VERSION))
54+
self.polling_interval = kwargs.get("polling_interval", 30)
5655
self._configure(**kwargs)
5756

58-
def _configure(
59-
self, **kwargs # type: Any
60-
):
61-
# type: (...) -> None
57+
def _configure(self, **kwargs: Any) -> None:
6258
self.user_agent_policy = kwargs.get("user_agent_policy") or policies.UserAgentPolicy(**kwargs)
6359
self.headers_policy = kwargs.get("headers_policy") or policies.HeadersPolicy(**kwargs)
6460
self.proxy_policy = kwargs.get("proxy_policy") or policies.ProxyPolicy(**kwargs)
6561
self.logging_policy = kwargs.get("logging_policy") or policies.NetworkTraceLoggingPolicy(**kwargs)
6662
self.http_logging_policy = kwargs.get("http_logging_policy") or policies.HttpLoggingPolicy(**kwargs)
67-
self.retry_policy = kwargs.get("retry_policy") or policies.RetryPolicy(**kwargs)
6863
self.custom_hook_policy = kwargs.get("custom_hook_policy") or policies.CustomHookPolicy(**kwargs)
6964
self.redirect_policy = kwargs.get("redirect_policy") or policies.RedirectPolicy(**kwargs)
65+
self.retry_policy = kwargs.get("retry_policy") or policies.RetryPolicy(**kwargs)
7066
self.authentication_policy = kwargs.get("authentication_policy")
7167
if self.credential and not self.authentication_policy:
7268
self.authentication_policy = policies.BearerTokenCredentialPolicy(

sdk/webpubsub/azure-messaging-webpubsubservice/azure/messaging/webpubsubservice/_operations/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from ._operations import WebPubSubServiceClientOperationsMixin
1010

1111
from ._patch import __all__ as _patch_all
12-
from ._patch import * # type: ignore # pylint: disable=unused-wildcard-import
12+
from ._patch import * # pylint: disable=unused-wildcard-import
1313
from ._patch import patch_sdk as _patch_sdk
1414

1515
__all__ = [

0 commit comments

Comments
 (0)