From 28e3609e39ef750fb699e398001df8038c155c7a Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Tue, 9 Nov 2021 17:41:12 -0800 Subject: [PATCH 1/4] regen with hub on client --- .../webpubsubservice/_configuration.py | 6 + .../_operations/_operations.py | 121 +++---------- .../_web_pub_sub_service_client.py | 6 +- .../webpubsubservice/aio/_configuration.py | 6 + .../aio/_operations/_operations.py | 120 +++---------- .../aio/_web_pub_sub_service_client.py | 6 +- .../swagger/README.md | 164 +++++++++++++++++- 7 files changed, 226 insertions(+), 203 deletions(-) diff --git a/sdk/webpubsub/azure-messaging-webpubsubservice/azure/messaging/webpubsubservice/_configuration.py b/sdk/webpubsub/azure-messaging-webpubsubservice/azure/messaging/webpubsubservice/_configuration.py index 44defc058a54..0ad85a86eb78 100644 --- a/sdk/webpubsub/azure-messaging-webpubsubservice/azure/messaging/webpubsubservice/_configuration.py +++ b/sdk/webpubsub/azure-messaging-webpubsubservice/azure/messaging/webpubsubservice/_configuration.py @@ -26,6 +26,8 @@ class WebPubSubServiceClientConfiguration(Configuration): Note that all parameters used to create this instance are saved as instance attributes. + :param hub: Target hub name, which should start with alphabetic characters and only contain alpha-numeric characters or underscore. + :type hub: str :param endpoint: HTTP or HTTPS endpoint for the Web PubSub service instance. :type endpoint: str :param credential: Credential needed for the client to connect to Azure. @@ -36,6 +38,7 @@ class WebPubSubServiceClientConfiguration(Configuration): def __init__( self, + hub, # type: str endpoint, # type: str credential, # type: "TokenCredential" **kwargs # type: Any @@ -44,11 +47,14 @@ def __init__( super(WebPubSubServiceClientConfiguration, self).__init__(**kwargs) api_version = kwargs.pop('api_version', "2021-10-01") # type: str + if hub is None: + raise ValueError("Parameter 'hub' must not be None.") if endpoint is None: raise ValueError("Parameter 'endpoint' must not be None.") if credential is None: raise ValueError("Parameter 'credential' must not be None.") + self.hub = hub self.endpoint = endpoint self.credential = credential self.api_version = api_version diff --git a/sdk/webpubsub/azure-messaging-webpubsubservice/azure/messaging/webpubsubservice/_operations/_operations.py b/sdk/webpubsub/azure-messaging-webpubsubservice/azure/messaging/webpubsubservice/_operations/_operations.py index 1eb379f1551b..a3e45932a41a 100644 --- a/sdk/webpubsub/azure-messaging-webpubsubservice/azure/messaging/webpubsubservice/_operations/_operations.py +++ b/sdk/webpubsub/azure-messaging-webpubsubservice/azure/messaging/webpubsubservice/_operations/_operations.py @@ -26,6 +26,7 @@ ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] _SERIALIZER = Serializer() +_SERIALIZER.client_side_validation = False # fmt: off def build_get_client_access_token_request( @@ -798,7 +799,6 @@ class WebPubSubServiceClientOperationsMixin(object): @distributed_trace def get_client_access_token( self, - hub, # type: str **kwargs # type: Any ): # type: (...) -> JSONType @@ -806,9 +806,6 @@ def get_client_access_token( Generate token for the client to connect Azure Web PubSub service. - :param hub: Target hub name, which should start with alphabetic characters and only contain - alpha-numeric characters or underscore. - :type hub: str :keyword user_id: User Id. :paramtype user_id: str :keyword roles: Roles that the connection with the generated token will have. @@ -843,7 +840,7 @@ def get_client_access_token( request = build_get_client_access_token_request( - hub=hub, + hub=self._config.hub, api_version=api_version, user_id=user_id, roles=roles, @@ -878,7 +875,6 @@ def get_client_access_token( @distributed_trace def close_all_connections( self, - hub, # type: str **kwargs # type: Any ): # type: (...) -> None @@ -886,9 +882,6 @@ def close_all_connections( Close the connections in the hub. - :param hub: Target hub name, which should start with alphabetic characters and only contain - alpha-numeric characters or underscore. - :type hub: str :keyword excluded: Exclude these connectionIds when closing the connections in the hub. :paramtype excluded: list[str] :keyword reason: The reason closing the client connection. @@ -912,7 +905,7 @@ def close_all_connections( request = build_close_all_connections_request( - hub=hub, + hub=self._config.hub, api_version=api_version, excluded=excluded, reason=reason, @@ -939,7 +932,6 @@ def close_all_connections( @distributed_trace def send_to_all( self, - hub, # type: str message, # type: Union[IO, str, JSONType] **kwargs # type: Any ): @@ -948,9 +940,6 @@ def send_to_all( Broadcast content inside request body to all the connected client connections. - :param hub: Target hub name, which should start with alphabetic characters and only contain - alpha-numeric characters or underscore. - :type hub: str :param message: The payload body. :type message: IO or str or JSONType :keyword excluded: Excluded connection Ids. @@ -988,7 +977,7 @@ def send_to_all( ) request = build_send_to_all_request( - hub=hub, + hub=self._config.hub, api_version=api_version, content_type=content_type, json=json, @@ -1017,7 +1006,6 @@ def send_to_all( @distributed_trace def connection_exists( self, - hub, # type: str connection_id, # type: str **kwargs # type: Any ): @@ -1026,9 +1014,6 @@ def connection_exists( Check if the connection with the given connectionId exists. - :param hub: Target hub name, which should start with alphabetic characters and only contain - alpha-numeric characters or underscore. - :type hub: str :param connection_id: The connection Id. :type connection_id: str :keyword api_version: Api Version. The default value is "2021-10-01". Note that overriding this @@ -1048,7 +1033,7 @@ def connection_exists( request = build_connection_exists_request( - hub=hub, + hub=self._config.hub, connection_id=connection_id, api_version=api_version, template_url=self.connection_exists.metadata['url'], @@ -1075,7 +1060,6 @@ def connection_exists( @distributed_trace def close_connection( self, - hub, # type: str connection_id, # type: str **kwargs # type: Any ): @@ -1084,9 +1068,6 @@ def close_connection( Close the client connection. - :param hub: Target hub name, which should start with alphabetic characters and only contain - alpha-numeric characters or underscore. - :type hub: str :param connection_id: Target connection Id. :type connection_id: str :keyword reason: The reason closing the client connection. @@ -1109,7 +1090,7 @@ def close_connection( request = build_close_connection_request( - hub=hub, + hub=self._config.hub, connection_id=connection_id, api_version=api_version, reason=reason, @@ -1136,7 +1117,6 @@ def close_connection( @distributed_trace def send_to_connection( self, - hub, # type: str connection_id, # type: str message, # type: Union[IO, str, JSONType] **kwargs # type: Any @@ -1146,9 +1126,6 @@ def send_to_connection( Send content inside request body to the specific connection. - :param hub: Target hub name, which should start with alphabetic characters and only contain - alpha-numeric characters or underscore. - :type hub: str :param connection_id: The connection Id. :type connection_id: str :param message: The payload body. @@ -1185,7 +1162,7 @@ def send_to_connection( ) request = build_send_to_connection_request( - hub=hub, + hub=self._config.hub, connection_id=connection_id, api_version=api_version, content_type=content_type, @@ -1214,7 +1191,6 @@ def send_to_connection( @distributed_trace def group_exists( self, - hub, # type: str group, # type: str **kwargs # type: Any ): @@ -1223,9 +1199,6 @@ def group_exists( Check if there are any client connections inside the given group. - :param hub: Target hub name, which should start with alphabetic characters and only contain - alpha-numeric characters or underscore. - :type hub: str :param group: Target group name, which length should be greater than 0 and less than 1025. :type group: str :keyword api_version: Api Version. The default value is "2021-10-01". Note that overriding this @@ -1245,7 +1218,7 @@ def group_exists( request = build_group_exists_request( - hub=hub, + hub=self._config.hub, group=group, api_version=api_version, template_url=self.group_exists.metadata['url'], @@ -1272,7 +1245,6 @@ def group_exists( @distributed_trace def close_group_connections( self, - hub, # type: str group, # type: str **kwargs # type: Any ): @@ -1281,9 +1253,6 @@ def close_group_connections( Close connections in the specific group. - :param hub: Target hub name, which should start with alphabetic characters and only contain - alpha-numeric characters or underscore. - :type hub: str :param group: Target group name, which length should be greater than 0 and less than 1025. :type group: str :keyword excluded: Exclude these connectionIds when closing the connections in the group. @@ -1309,7 +1278,7 @@ def close_group_connections( request = build_close_group_connections_request( - hub=hub, + hub=self._config.hub, group=group, api_version=api_version, excluded=excluded, @@ -1337,7 +1306,6 @@ def close_group_connections( @distributed_trace def send_to_group( self, - hub, # type: str group, # type: str message, # type: Union[IO, str, JSONType] **kwargs # type: Any @@ -1347,9 +1315,6 @@ def send_to_group( Send content inside request body to a group of connections. - :param hub: Target hub name, which should start with alphabetic characters and only contain - alpha-numeric characters or underscore. - :type hub: str :param group: Target group name, which length should be greater than 0 and less than 1025. :type group: str :param message: The payload body. @@ -1389,7 +1354,7 @@ def send_to_group( ) request = build_send_to_group_request( - hub=hub, + hub=self._config.hub, group=group, api_version=api_version, content_type=content_type, @@ -1419,7 +1384,6 @@ def send_to_group( @distributed_trace def add_connection_to_group( self, - hub, # type: str group, # type: str connection_id, # type: str **kwargs # type: Any @@ -1429,9 +1393,6 @@ def add_connection_to_group( Add a connection to the target group. - :param hub: Target hub name, which should start with alphabetic characters and only contain - alpha-numeric characters or underscore. - :type hub: str :param group: Target group name, which length should be greater than 0 and less than 1025. :type group: str :param connection_id: Target connection Id. @@ -1453,7 +1414,7 @@ def add_connection_to_group( request = build_add_connection_to_group_request( - hub=hub, + hub=self._config.hub, group=group, connection_id=connection_id, api_version=api_version, @@ -1480,7 +1441,6 @@ def add_connection_to_group( @distributed_trace def remove_connection_from_group( self, - hub, # type: str group, # type: str connection_id, # type: str **kwargs # type: Any @@ -1490,9 +1450,6 @@ def remove_connection_from_group( Remove a connection from the target group. - :param hub: Target hub name, which should start with alphabetic characters and only contain - alpha-numeric characters or underscore. - :type hub: str :param group: Target group name, which length should be greater than 0 and less than 1025. :type group: str :param connection_id: Target connection Id. @@ -1514,7 +1471,7 @@ def remove_connection_from_group( request = build_remove_connection_from_group_request( - hub=hub, + hub=self._config.hub, group=group, connection_id=connection_id, api_version=api_version, @@ -1541,7 +1498,6 @@ def remove_connection_from_group( @distributed_trace def user_exists( self, - hub, # type: str user_id, # type: str **kwargs # type: Any ): @@ -1550,9 +1506,6 @@ def user_exists( Check if there are any client connections connected for the given user. - :param hub: Target hub name, which should start with alphabetic characters and only contain - alpha-numeric characters or underscore. - :type hub: str :param user_id: Target user Id. :type user_id: str :keyword api_version: Api Version. The default value is "2021-10-01". Note that overriding this @@ -1572,7 +1525,7 @@ def user_exists( request = build_user_exists_request( - hub=hub, + hub=self._config.hub, user_id=user_id, api_version=api_version, template_url=self.user_exists.metadata['url'], @@ -1599,7 +1552,6 @@ def user_exists( @distributed_trace def close_user_connections( self, - hub, # type: str user_id, # type: str **kwargs # type: Any ): @@ -1608,9 +1560,6 @@ def close_user_connections( Close connections for the specific user. - :param hub: Target hub name, which should start with alphabetic characters and only contain - alpha-numeric characters or underscore. - :type hub: str :param user_id: The user Id. :type user_id: str :keyword excluded: Exclude these connectionIds when closing the connections for the user. @@ -1636,7 +1585,7 @@ def close_user_connections( request = build_close_user_connections_request( - hub=hub, + hub=self._config.hub, user_id=user_id, api_version=api_version, excluded=excluded, @@ -1664,7 +1613,6 @@ def close_user_connections( @distributed_trace def send_to_user( self, - hub, # type: str user_id, # type: str message, # type: Union[IO, str, JSONType] **kwargs # type: Any @@ -1674,9 +1622,6 @@ def send_to_user( Send content inside request body to the specific user. - :param hub: Target hub name, which should start with alphabetic characters and only contain - alpha-numeric characters or underscore. - :type hub: str :param user_id: The user Id. :type user_id: str :param message: The payload body. @@ -1713,7 +1658,7 @@ def send_to_user( ) request = build_send_to_user_request( - hub=hub, + hub=self._config.hub, user_id=user_id, api_version=api_version, content_type=content_type, @@ -1742,7 +1687,6 @@ def send_to_user( @distributed_trace def add_user_to_group( self, - hub, # type: str group, # type: str user_id, # type: str **kwargs # type: Any @@ -1752,9 +1696,6 @@ def add_user_to_group( Add a user to the target group. - :param hub: Target hub name, which should start with alphabetic characters and only contain - alpha-numeric characters or underscore. - :type hub: str :param group: Target group name, which length should be greater than 0 and less than 1025. :type group: str :param user_id: Target user Id. @@ -1776,7 +1717,7 @@ def add_user_to_group( request = build_add_user_to_group_request( - hub=hub, + hub=self._config.hub, group=group, user_id=user_id, api_version=api_version, @@ -1803,7 +1744,6 @@ def add_user_to_group( @distributed_trace def remove_user_from_group( self, - hub, # type: str group, # type: str user_id, # type: str **kwargs # type: Any @@ -1813,9 +1753,6 @@ def remove_user_from_group( Remove a user from the target group. - :param hub: Target hub name, which should start with alphabetic characters and only contain - alpha-numeric characters or underscore. - :type hub: str :param group: Target group name, which length should be greater than 0 and less than 1025. :type group: str :param user_id: Target user Id. @@ -1837,7 +1774,7 @@ def remove_user_from_group( request = build_remove_user_from_group_request( - hub=hub, + hub=self._config.hub, group=group, user_id=user_id, api_version=api_version, @@ -1864,7 +1801,6 @@ def remove_user_from_group( @distributed_trace def remove_user_from_all_groups( self, - hub, # type: str user_id, # type: str **kwargs # type: Any ): @@ -1873,9 +1809,6 @@ def remove_user_from_all_groups( Remove a user from all groups. - :param hub: Target hub name, which should start with alphabetic characters and only contain - alpha-numeric characters or underscore. - :type hub: str :param user_id: Target user Id. :type user_id: str :keyword api_version: Api Version. The default value is "2021-10-01". Note that overriding this @@ -1895,7 +1828,7 @@ def remove_user_from_all_groups( request = build_remove_user_from_all_groups_request( - hub=hub, + hub=self._config.hub, user_id=user_id, api_version=api_version, template_url=self.remove_user_from_all_groups.metadata['url'], @@ -1921,7 +1854,6 @@ def remove_user_from_all_groups( @distributed_trace def grant_permission( self, - hub, # type: str permission, # type: str connection_id, # type: str **kwargs # type: Any @@ -1931,9 +1863,6 @@ def grant_permission( Grant permission to the connection. - :param hub: Target hub name, which should start with alphabetic characters and only contain - alpha-numeric characters or underscore. - :type hub: str :param permission: The permission: current supported actions are joinLeaveGroup and sendToGroup. Possible values are: "sendToGroup" or "joinLeaveGroup". :type permission: str @@ -1960,7 +1889,7 @@ def grant_permission( request = build_grant_permission_request( - hub=hub, + hub=self._config.hub, permission=permission, connection_id=connection_id, api_version=api_version, @@ -1988,7 +1917,6 @@ def grant_permission( @distributed_trace def revoke_permission( self, - hub, # type: str permission, # type: str connection_id, # type: str **kwargs # type: Any @@ -1998,9 +1926,6 @@ def revoke_permission( Revoke permission for the connection. - :param hub: Target hub name, which should start with alphabetic characters and only contain - alpha-numeric characters or underscore. - :type hub: str :param permission: The permission: current supported actions are joinLeaveGroup and sendToGroup. Possible values are: "sendToGroup" or "joinLeaveGroup". :type permission: str @@ -2027,7 +1952,7 @@ def revoke_permission( request = build_revoke_permission_request( - hub=hub, + hub=self._config.hub, permission=permission, connection_id=connection_id, api_version=api_version, @@ -2055,7 +1980,6 @@ def revoke_permission( @distributed_trace def has_permission( self, - hub, # type: str permission, # type: str connection_id, # type: str **kwargs # type: Any @@ -2065,9 +1989,6 @@ def has_permission( Check if a connection has permission to the specified action. - :param hub: Target hub name, which should start with alphabetic characters and only contain - alpha-numeric characters or underscore. - :type hub: str :param permission: The permission: current supported actions are joinLeaveGroup and sendToGroup. Possible values are: "sendToGroup" or "joinLeaveGroup". :type permission: str @@ -2094,7 +2015,7 @@ def has_permission( request = build_has_permission_request( - hub=hub, + hub=self._config.hub, permission=permission, connection_id=connection_id, api_version=api_version, diff --git a/sdk/webpubsub/azure-messaging-webpubsubservice/azure/messaging/webpubsubservice/_web_pub_sub_service_client.py b/sdk/webpubsub/azure-messaging-webpubsubservice/azure/messaging/webpubsubservice/_web_pub_sub_service_client.py index 0c8702bf159f..9d96f87e1225 100644 --- a/sdk/webpubsub/azure-messaging-webpubsubservice/azure/messaging/webpubsubservice/_web_pub_sub_service_client.py +++ b/sdk/webpubsub/azure-messaging-webpubsubservice/azure/messaging/webpubsubservice/_web_pub_sub_service_client.py @@ -25,6 +25,9 @@ class WebPubSubServiceClient(WebPubSubServiceClientOperationsMixin): """WebPubSubServiceClient. + :param hub: Target hub name, which should start with alphabetic characters and only contain + alpha-numeric characters or underscore. + :type hub: str :param endpoint: HTTP or HTTPS endpoint for the Web PubSub service instance. :type endpoint: str :param credential: Credential needed for the client to connect to Azure. @@ -36,13 +39,14 @@ class WebPubSubServiceClient(WebPubSubServiceClientOperationsMixin): def __init__( self, + hub, # type: str endpoint, # type: str credential, # type: "TokenCredential" **kwargs # type: Any ): # type: (...) -> None _endpoint = '{Endpoint}' - self._config = WebPubSubServiceClientConfiguration(endpoint=endpoint, credential=credential, **kwargs) + self._config = WebPubSubServiceClientConfiguration(hub=hub, endpoint=endpoint, credential=credential, **kwargs) self._client = PipelineClient(base_url=_endpoint, config=self._config, **kwargs) self._serialize = Serializer() diff --git a/sdk/webpubsub/azure-messaging-webpubsubservice/azure/messaging/webpubsubservice/aio/_configuration.py b/sdk/webpubsub/azure-messaging-webpubsubservice/azure/messaging/webpubsubservice/aio/_configuration.py index c9c68386762d..24dea080d9bd 100644 --- a/sdk/webpubsub/azure-messaging-webpubsubservice/azure/messaging/webpubsubservice/aio/_configuration.py +++ b/sdk/webpubsub/azure-messaging-webpubsubservice/azure/messaging/webpubsubservice/aio/_configuration.py @@ -24,6 +24,8 @@ class WebPubSubServiceClientConfiguration(Configuration): Note that all parameters used to create this instance are saved as instance attributes. + :param hub: Target hub name, which should start with alphabetic characters and only contain alpha-numeric characters or underscore. + :type hub: str :param endpoint: HTTP or HTTPS endpoint for the Web PubSub service instance. :type endpoint: str :param credential: Credential needed for the client to connect to Azure. @@ -34,6 +36,7 @@ class WebPubSubServiceClientConfiguration(Configuration): def __init__( self, + hub: str, endpoint: str, credential: "AsyncTokenCredential", **kwargs: Any @@ -41,11 +44,14 @@ def __init__( super(WebPubSubServiceClientConfiguration, self).__init__(**kwargs) api_version = kwargs.pop('api_version', "2021-10-01") # type: str + if hub is None: + raise ValueError("Parameter 'hub' must not be None.") if endpoint is None: raise ValueError("Parameter 'endpoint' must not be None.") if credential is None: raise ValueError("Parameter 'credential' must not be None.") + self.hub = hub self.endpoint = endpoint self.credential = credential self.api_version = api_version diff --git a/sdk/webpubsub/azure-messaging-webpubsubservice/azure/messaging/webpubsubservice/aio/_operations/_operations.py b/sdk/webpubsub/azure-messaging-webpubsubservice/azure/messaging/webpubsubservice/aio/_operations/_operations.py index ebd1f4541681..0fe699744e5b 100644 --- a/sdk/webpubsub/azure-messaging-webpubsubservice/azure/messaging/webpubsubservice/aio/_operations/_operations.py +++ b/sdk/webpubsub/azure-messaging-webpubsubservice/azure/messaging/webpubsubservice/aio/_operations/_operations.py @@ -25,7 +25,6 @@ class WebPubSubServiceClientOperationsMixin: @distributed_trace_async async def get_client_access_token( self, - hub: str, *, user_id: Optional[str] = None, roles: Optional[List[str]] = None, @@ -36,9 +35,6 @@ async def get_client_access_token( Generate token for the client to connect Azure Web PubSub service. - :param hub: Target hub name, which should start with alphabetic characters and only contain - alpha-numeric characters or underscore. - :type hub: str :keyword user_id: User Id. :paramtype user_id: str :keyword roles: Roles that the connection with the generated token will have. @@ -70,7 +66,7 @@ async def get_client_access_token( request = build_get_client_access_token_request( - hub=hub, + hub=self._config.hub, api_version=api_version, user_id=user_id, roles=roles, @@ -105,7 +101,6 @@ async def get_client_access_token( @distributed_trace_async async def close_all_connections( self, - hub: str, *, excluded: Optional[List[str]] = None, reason: Optional[str] = None, @@ -115,9 +110,6 @@ async def close_all_connections( Close the connections in the hub. - :param hub: Target hub name, which should start with alphabetic characters and only contain - alpha-numeric characters or underscore. - :type hub: str :keyword excluded: Exclude these connectionIds when closing the connections in the hub. :paramtype excluded: list[str] :keyword reason: The reason closing the client connection. @@ -139,7 +131,7 @@ async def close_all_connections( request = build_close_all_connections_request( - hub=hub, + hub=self._config.hub, api_version=api_version, excluded=excluded, reason=reason, @@ -166,7 +158,6 @@ async def close_all_connections( @distributed_trace_async async def send_to_all( self, - hub: str, message: Union[IO, str, JSONType], *, excluded: Optional[List[str]] = None, @@ -176,9 +167,6 @@ async def send_to_all( Broadcast content inside request body to all the connected client connections. - :param hub: Target hub name, which should start with alphabetic characters and only contain - alpha-numeric characters or underscore. - :type hub: str :param message: The payload body. :type message: IO or str or JSONType :keyword excluded: Excluded connection Ids. @@ -215,7 +203,7 @@ async def send_to_all( ) request = build_send_to_all_request( - hub=hub, + hub=self._config.hub, api_version=api_version, content_type=content_type, json=json, @@ -244,7 +232,6 @@ async def send_to_all( @distributed_trace_async async def connection_exists( self, - hub: str, connection_id: str, **kwargs: Any ) -> bool: @@ -252,9 +239,6 @@ async def connection_exists( Check if the connection with the given connectionId exists. - :param hub: Target hub name, which should start with alphabetic characters and only contain - alpha-numeric characters or underscore. - :type hub: str :param connection_id: The connection Id. :type connection_id: str :keyword api_version: Api Version. The default value is "2021-10-01". Note that overriding this @@ -274,7 +258,7 @@ async def connection_exists( request = build_connection_exists_request( - hub=hub, + hub=self._config.hub, connection_id=connection_id, api_version=api_version, template_url=self.connection_exists.metadata['url'], @@ -301,7 +285,6 @@ async def connection_exists( @distributed_trace_async async def close_connection( self, - hub: str, connection_id: str, *, reason: Optional[str] = None, @@ -311,9 +294,6 @@ async def close_connection( Close the client connection. - :param hub: Target hub name, which should start with alphabetic characters and only contain - alpha-numeric characters or underscore. - :type hub: str :param connection_id: Target connection Id. :type connection_id: str :keyword reason: The reason closing the client connection. @@ -335,7 +315,7 @@ async def close_connection( request = build_close_connection_request( - hub=hub, + hub=self._config.hub, connection_id=connection_id, api_version=api_version, reason=reason, @@ -362,7 +342,6 @@ async def close_connection( @distributed_trace_async async def send_to_connection( self, - hub: str, connection_id: str, message: Union[IO, str, JSONType], **kwargs: Any @@ -371,9 +350,6 @@ async def send_to_connection( Send content inside request body to the specific connection. - :param hub: Target hub name, which should start with alphabetic characters and only contain - alpha-numeric characters or underscore. - :type hub: str :param connection_id: The connection Id. :type connection_id: str :param message: The payload body. @@ -410,7 +386,7 @@ async def send_to_connection( ) request = build_send_to_connection_request( - hub=hub, + hub=self._config.hub, connection_id=connection_id, api_version=api_version, content_type=content_type, @@ -439,7 +415,6 @@ async def send_to_connection( @distributed_trace_async async def group_exists( self, - hub: str, group: str, **kwargs: Any ) -> bool: @@ -447,9 +422,6 @@ async def group_exists( Check if there are any client connections inside the given group. - :param hub: Target hub name, which should start with alphabetic characters and only contain - alpha-numeric characters or underscore. - :type hub: str :param group: Target group name, which length should be greater than 0 and less than 1025. :type group: str :keyword api_version: Api Version. The default value is "2021-10-01". Note that overriding this @@ -469,7 +441,7 @@ async def group_exists( request = build_group_exists_request( - hub=hub, + hub=self._config.hub, group=group, api_version=api_version, template_url=self.group_exists.metadata['url'], @@ -496,7 +468,6 @@ async def group_exists( @distributed_trace_async async def close_group_connections( self, - hub: str, group: str, *, excluded: Optional[List[str]] = None, @@ -507,9 +478,6 @@ async def close_group_connections( Close connections in the specific group. - :param hub: Target hub name, which should start with alphabetic characters and only contain - alpha-numeric characters or underscore. - :type hub: str :param group: Target group name, which length should be greater than 0 and less than 1025. :type group: str :keyword excluded: Exclude these connectionIds when closing the connections in the group. @@ -533,7 +501,7 @@ async def close_group_connections( request = build_close_group_connections_request( - hub=hub, + hub=self._config.hub, group=group, api_version=api_version, excluded=excluded, @@ -561,7 +529,6 @@ async def close_group_connections( @distributed_trace_async async def send_to_group( self, - hub: str, group: str, message: Union[IO, str, JSONType], *, @@ -572,9 +539,6 @@ async def send_to_group( Send content inside request body to a group of connections. - :param hub: Target hub name, which should start with alphabetic characters and only contain - alpha-numeric characters or underscore. - :type hub: str :param group: Target group name, which length should be greater than 0 and less than 1025. :type group: str :param message: The payload body. @@ -613,7 +577,7 @@ async def send_to_group( ) request = build_send_to_group_request( - hub=hub, + hub=self._config.hub, group=group, api_version=api_version, content_type=content_type, @@ -643,7 +607,6 @@ async def send_to_group( @distributed_trace_async async def add_connection_to_group( self, - hub: str, group: str, connection_id: str, **kwargs: Any @@ -652,9 +615,6 @@ async def add_connection_to_group( Add a connection to the target group. - :param hub: Target hub name, which should start with alphabetic characters and only contain - alpha-numeric characters or underscore. - :type hub: str :param group: Target group name, which length should be greater than 0 and less than 1025. :type group: str :param connection_id: Target connection Id. @@ -676,7 +636,7 @@ async def add_connection_to_group( request = build_add_connection_to_group_request( - hub=hub, + hub=self._config.hub, group=group, connection_id=connection_id, api_version=api_version, @@ -703,7 +663,6 @@ async def add_connection_to_group( @distributed_trace_async async def remove_connection_from_group( self, - hub: str, group: str, connection_id: str, **kwargs: Any @@ -712,9 +671,6 @@ async def remove_connection_from_group( Remove a connection from the target group. - :param hub: Target hub name, which should start with alphabetic characters and only contain - alpha-numeric characters or underscore. - :type hub: str :param group: Target group name, which length should be greater than 0 and less than 1025. :type group: str :param connection_id: Target connection Id. @@ -736,7 +692,7 @@ async def remove_connection_from_group( request = build_remove_connection_from_group_request( - hub=hub, + hub=self._config.hub, group=group, connection_id=connection_id, api_version=api_version, @@ -763,7 +719,6 @@ async def remove_connection_from_group( @distributed_trace_async async def user_exists( self, - hub: str, user_id: str, **kwargs: Any ) -> bool: @@ -771,9 +726,6 @@ async def user_exists( Check if there are any client connections connected for the given user. - :param hub: Target hub name, which should start with alphabetic characters and only contain - alpha-numeric characters or underscore. - :type hub: str :param user_id: Target user Id. :type user_id: str :keyword api_version: Api Version. The default value is "2021-10-01". Note that overriding this @@ -793,7 +745,7 @@ async def user_exists( request = build_user_exists_request( - hub=hub, + hub=self._config.hub, user_id=user_id, api_version=api_version, template_url=self.user_exists.metadata['url'], @@ -820,7 +772,6 @@ async def user_exists( @distributed_trace_async async def close_user_connections( self, - hub: str, user_id: str, *, excluded: Optional[List[str]] = None, @@ -831,9 +782,6 @@ async def close_user_connections( Close connections for the specific user. - :param hub: Target hub name, which should start with alphabetic characters and only contain - alpha-numeric characters or underscore. - :type hub: str :param user_id: The user Id. :type user_id: str :keyword excluded: Exclude these connectionIds when closing the connections for the user. @@ -857,7 +805,7 @@ async def close_user_connections( request = build_close_user_connections_request( - hub=hub, + hub=self._config.hub, user_id=user_id, api_version=api_version, excluded=excluded, @@ -885,7 +833,6 @@ async def close_user_connections( @distributed_trace_async async def send_to_user( self, - hub: str, user_id: str, message: Union[IO, str, JSONType], **kwargs: Any @@ -894,9 +841,6 @@ async def send_to_user( Send content inside request body to the specific user. - :param hub: Target hub name, which should start with alphabetic characters and only contain - alpha-numeric characters or underscore. - :type hub: str :param user_id: The user Id. :type user_id: str :param message: The payload body. @@ -933,7 +877,7 @@ async def send_to_user( ) request = build_send_to_user_request( - hub=hub, + hub=self._config.hub, user_id=user_id, api_version=api_version, content_type=content_type, @@ -962,7 +906,6 @@ async def send_to_user( @distributed_trace_async async def add_user_to_group( self, - hub: str, group: str, user_id: str, **kwargs: Any @@ -971,9 +914,6 @@ async def add_user_to_group( Add a user to the target group. - :param hub: Target hub name, which should start with alphabetic characters and only contain - alpha-numeric characters or underscore. - :type hub: str :param group: Target group name, which length should be greater than 0 and less than 1025. :type group: str :param user_id: Target user Id. @@ -995,7 +935,7 @@ async def add_user_to_group( request = build_add_user_to_group_request( - hub=hub, + hub=self._config.hub, group=group, user_id=user_id, api_version=api_version, @@ -1022,7 +962,6 @@ async def add_user_to_group( @distributed_trace_async async def remove_user_from_group( self, - hub: str, group: str, user_id: str, **kwargs: Any @@ -1031,9 +970,6 @@ async def remove_user_from_group( Remove a user from the target group. - :param hub: Target hub name, which should start with alphabetic characters and only contain - alpha-numeric characters or underscore. - :type hub: str :param group: Target group name, which length should be greater than 0 and less than 1025. :type group: str :param user_id: Target user Id. @@ -1055,7 +991,7 @@ async def remove_user_from_group( request = build_remove_user_from_group_request( - hub=hub, + hub=self._config.hub, group=group, user_id=user_id, api_version=api_version, @@ -1082,7 +1018,6 @@ async def remove_user_from_group( @distributed_trace_async async def remove_user_from_all_groups( self, - hub: str, user_id: str, **kwargs: Any ) -> None: @@ -1090,9 +1025,6 @@ async def remove_user_from_all_groups( Remove a user from all groups. - :param hub: Target hub name, which should start with alphabetic characters and only contain - alpha-numeric characters or underscore. - :type hub: str :param user_id: Target user Id. :type user_id: str :keyword api_version: Api Version. The default value is "2021-10-01". Note that overriding this @@ -1112,7 +1044,7 @@ async def remove_user_from_all_groups( request = build_remove_user_from_all_groups_request( - hub=hub, + hub=self._config.hub, user_id=user_id, api_version=api_version, template_url=self.remove_user_from_all_groups.metadata['url'], @@ -1138,7 +1070,6 @@ async def remove_user_from_all_groups( @distributed_trace_async async def grant_permission( self, - hub: str, permission: str, connection_id: str, *, @@ -1149,9 +1080,6 @@ async def grant_permission( Grant permission to the connection. - :param hub: Target hub name, which should start with alphabetic characters and only contain - alpha-numeric characters or underscore. - :type hub: str :param permission: The permission: current supported actions are joinLeaveGroup and sendToGroup. Possible values are: "sendToGroup" or "joinLeaveGroup". :type permission: str @@ -1177,7 +1105,7 @@ async def grant_permission( request = build_grant_permission_request( - hub=hub, + hub=self._config.hub, permission=permission, connection_id=connection_id, api_version=api_version, @@ -1205,7 +1133,6 @@ async def grant_permission( @distributed_trace_async async def revoke_permission( self, - hub: str, permission: str, connection_id: str, *, @@ -1216,9 +1143,6 @@ async def revoke_permission( Revoke permission for the connection. - :param hub: Target hub name, which should start with alphabetic characters and only contain - alpha-numeric characters or underscore. - :type hub: str :param permission: The permission: current supported actions are joinLeaveGroup and sendToGroup. Possible values are: "sendToGroup" or "joinLeaveGroup". :type permission: str @@ -1244,7 +1168,7 @@ async def revoke_permission( request = build_revoke_permission_request( - hub=hub, + hub=self._config.hub, permission=permission, connection_id=connection_id, api_version=api_version, @@ -1272,7 +1196,6 @@ async def revoke_permission( @distributed_trace_async async def has_permission( self, - hub: str, permission: str, connection_id: str, *, @@ -1283,9 +1206,6 @@ async def has_permission( Check if a connection has permission to the specified action. - :param hub: Target hub name, which should start with alphabetic characters and only contain - alpha-numeric characters or underscore. - :type hub: str :param permission: The permission: current supported actions are joinLeaveGroup and sendToGroup. Possible values are: "sendToGroup" or "joinLeaveGroup". :type permission: str @@ -1311,7 +1231,7 @@ async def has_permission( request = build_has_permission_request( - hub=hub, + hub=self._config.hub, permission=permission, connection_id=connection_id, api_version=api_version, diff --git a/sdk/webpubsub/azure-messaging-webpubsubservice/azure/messaging/webpubsubservice/aio/_web_pub_sub_service_client.py b/sdk/webpubsub/azure-messaging-webpubsubservice/azure/messaging/webpubsubservice/aio/_web_pub_sub_service_client.py index 6ee270bc5bf6..340adac20cc3 100644 --- a/sdk/webpubsub/azure-messaging-webpubsubservice/azure/messaging/webpubsubservice/aio/_web_pub_sub_service_client.py +++ b/sdk/webpubsub/azure-messaging-webpubsubservice/azure/messaging/webpubsubservice/aio/_web_pub_sub_service_client.py @@ -25,6 +25,9 @@ class WebPubSubServiceClient(WebPubSubServiceClientOperationsMixin): """WebPubSubServiceClient. + :param hub: Target hub name, which should start with alphabetic characters and only contain + alpha-numeric characters or underscore. + :type hub: str :param endpoint: HTTP or HTTPS endpoint for the Web PubSub service instance. :type endpoint: str :param credential: Credential needed for the client to connect to Azure. @@ -36,12 +39,13 @@ class WebPubSubServiceClient(WebPubSubServiceClientOperationsMixin): def __init__( self, + hub: str, endpoint: str, credential: "AsyncTokenCredential", **kwargs: Any ) -> None: _endpoint = '{Endpoint}' - self._config = WebPubSubServiceClientConfiguration(endpoint=endpoint, credential=credential, **kwargs) + self._config = WebPubSubServiceClientConfiguration(hub=hub, endpoint=endpoint, credential=credential, **kwargs) self._client = AsyncPipelineClient(base_url=_endpoint, config=self._config, **kwargs) self._serialize = Serializer() diff --git a/sdk/webpubsub/azure-messaging-webpubsubservice/swagger/README.md b/sdk/webpubsub/azure-messaging-webpubsubservice/swagger/README.md index d9baae2ca7e4..1e36db4cab71 100644 --- a/sdk/webpubsub/azure-messaging-webpubsubservice/swagger/README.md +++ b/sdk/webpubsub/azure-messaging-webpubsubservice/swagger/README.md @@ -82,4 +82,166 @@ directive: - from: swagger-document where: $["paths"]["/api/hubs/{hub}/:generateToken"].post transform: $["operationId"] = "GetClientAccessToken" -``` \ No newline at end of file +``` + +### Add hub to client on generate token + +``` yaml +directive: +- from: swagger-document + where: $.paths["/api/hubs/{hub}/:generateToken"].post.parameters["0"] + transform: $["x-ms-parameter-location"] = "client" +``` + +### SendToAll + +``` yaml +directive: +- from: swagger-document + where: $.paths["/api/hubs/{hub}/:send"].post.parameters["0"] + transform: $["x-ms-parameter-location"] = "client" +``` + +### ConnectionExistsImpl +``` yaml +directive: +- from: swagger-document + where: $.paths["/api/hubs/{hub}/connections/{connectionId}"].head.parameters["0"] + transform: $["x-ms-parameter-location"] = "client" +``` + +### CloseConnection +``` yaml +directive: +- from: swagger-document + where: $.paths["/api/hubs/{hub}/connections/{connectionId}"].delete.parameters["0"] + transform: $["x-ms-parameter-location"] = "client" +``` + +### SendToConnection +``` yaml +directive: +- from: swagger-document + where: $.paths["/api/hubs/{hub}/connections/{connectionId}/:send"].post.parameters["0"] + transform: $["x-ms-parameter-location"] = "client" +``` + +### GroupExistsImpl +``` yaml +directive: +- from: swagger-document + where: $.paths["/api/hubs/{hub}/groups/{group}"].head.parameters["0"] + transform: $["x-ms-parameter-location"] = "client" +``` + +### SendToGroup +``` yaml +directive: +- from: swagger-document + where: $.paths["/api/hubs/{hub}/groups/{group}/:send"].post.parameters["0"] + transform: $["x-ms-parameter-location"] = "client" +``` + +### AddConnectionToGroup +``` yaml +directive: +- from: swagger-document + where: $.paths["/api/hubs/{hub}/groups/{group}/connections/{connectionId}"].put.parameters["0"] + transform: $["x-ms-parameter-location"] = "client" +``` + +### RemoveConnectionFromGroup +``` yaml +directive: +- from: swagger-document + where: $.paths["/api/hubs/{hub}/groups/{group}/connections/{connectionId}"].delete.parameters["0"] + transform: $["x-ms-parameter-location"] = "client" +``` + +### UserExistsImpl +``` yaml +directive: +- from: swagger-document + where: $.paths["/api/hubs/{hub}/users/{userId}"].head.parameters["0"] + transform: $["x-ms-parameter-location"] = "client" +``` + +### SendToUser +``` yaml +directive: +- from: swagger-document + where: $.paths["/api/hubs/{hub}/users/{userId}/:send"].post.parameters["0"] + transform: $["x-ms-parameter-location"] = "client" +``` + +### AddUserToGroup +``` yaml +directive: +- from: swagger-document + where: $.paths["/api/hubs/{hub}/users/{userId}/groups/{group}"].put.parameters["0"] + transform: $["x-ms-parameter-location"] = "client" +``` + +### RemoveUserFromGroup +``` yaml +directive: +- from: swagger-document + where: $.paths["/api/hubs/{hub}/users/{userId}/groups/{group}"].delete.parameters["0"] + transform: $["x-ms-parameter-location"] = "client" +``` + +### RemoveUserFromAllGroups +``` yaml +directive: +- from: swagger-document + where: $.paths["/api/hubs/{hub}/users/{userId}/groups"].delete.parameters["0"] + transform: $["x-ms-parameter-location"] = "client" +``` + +### GrantPermission +``` yaml +directive: +- from: swagger-document + where: $.paths["/api/hubs/{hub}/permissions/{permission}/connections/{connectionId}"].put.parameters["0"] + transform: $["x-ms-parameter-location"] = "client" +``` + +### RevokePermission +``` yaml +directive: +- from: swagger-document + where: $.paths["/api/hubs/{hub}/permissions/{permission}/connections/{connectionId}"].delete.parameters["0"] + transform: $["x-ms-parameter-location"] = "client" +``` + +### CheckPermission +``` yaml +directive: +- from: swagger-document + where: $.paths["/api/hubs/{hub}/permissions/{permission}/connections/{connectionId}"].head.parameters["0"] + transform: $["x-ms-parameter-location"] = "client" +``` + +### CloseAllConnections +``` yaml +directive: +- from: swagger-document + where: $.paths["/api/hubs/{hub}/:closeConnections"].post.parameters["0"] + transform: $["x-ms-parameter-location"] = "client" +``` + +### CloseGroupConnections +``` yaml +directive: +- from: swagger-document + where: $.paths["/api/hubs/{hub}/groups/{group}/:closeConnections"].post.parameters["0"] + transform: $["x-ms-parameter-location"] = "client" +``` + +### CloseUserConnections +``` yaml +directive: +- from: swagger-document + where: $.paths["/api/hubs/{hub}/users/{userId}/:closeConnections"].post.parameters["0"] + transform: $["x-ms-parameter-location"] = "client" +``` From 40850d347bbe9b331e95a2ad5aeec9a8553f2e67 Mon Sep 17 00:00:00 2001 From: msyyc <70930885+msyyc@users.noreply.github.com> Date: Wed, 10 Nov 2021 11:51:57 +0800 Subject: [PATCH 2/4] update test and sample --- .../messaging/webpubsubservice/_patch.py | 30 +++++++++++++------ .../messaging/webpubsubservice/aio/_patch.py | 30 +++++++++++++------ .../samples/get_client_access_token.py | 8 ++--- .../samples/get_client_access_token_async.py | 8 ++--- .../samples/send_messages_aad.py | 8 ++--- .../samples/send_messages_aad_apim_proxy.py | 8 ++--- .../send_messages_connection_string.py | 8 ++--- ...d_messages_connection_string_apim_proxy.py | 8 ++--- ...st_smoke.test_get_client_access_token.yaml | 8 +++-- ...est_smoke.test_webpubsub_send_request.yaml | 6 ++-- ...test_smoke.test_webpubsub_send_to_all.yaml | 8 +++-- ...bsub_send_to_all_api_management_proxy.yaml | 8 +++-- ...ke_async.test_get_client_access_token.yaml | 7 +++-- ...moke_async.test_webpubsub_send_to_all.yaml | 9 +++--- ...test_webpubsub_send_to_all_apim_proxy.yaml | 9 +++--- .../tests/test_smoke.py | 18 +++++------ .../tests/test_smoke_async.py | 16 +++++----- .../tests/testcase.py | 3 +- .../tests/testcase_async.py | 7 +++-- 19 files changed, 122 insertions(+), 85 deletions(-) diff --git a/sdk/webpubsub/azure-messaging-webpubsubservice/azure/messaging/webpubsubservice/_patch.py b/sdk/webpubsub/azure-messaging-webpubsubservice/azure/messaging/webpubsubservice/_patch.py index 039d21c58596..15d37d87aabd 100644 --- a/sdk/webpubsub/azure-messaging-webpubsubservice/azure/messaging/webpubsubservice/_patch.py +++ b/sdk/webpubsub/azure-messaging-webpubsubservice/azure/messaging/webpubsubservice/_patch.py @@ -212,6 +212,8 @@ class WebPubSubServiceClientConfiguration(Configuration): Note that all parameters used to create this instance are saved as instance attributes. + :param hub: Target hub name, which should start with alphabetic characters and only contain alpha-numeric characters or underscore. + :type hub: str :param endpoint: HTTP or HTTPS endpoint for the Web PubSub service instance. :type endpoint: str :param credential: Credential needed for the client to connect to Azure. @@ -221,6 +223,7 @@ class WebPubSubServiceClientConfiguration(Configuration): def __init__( self, + hub, # type: str endpoint, # type: str credential, # type: Union[TokenCredential, AzureKeyCredential] **kwargs # type: Any @@ -229,11 +232,14 @@ def __init__( super(WebPubSubServiceClientConfiguration, self).__init__(**kwargs) api_version = kwargs.pop('api_version', "2021-10-01") # type: str + if hub is None: + raise ValueError("Parameter 'hub' must not be None.") if endpoint is None: raise ValueError("Parameter 'endpoint' must not be None.") if credential is None: raise ValueError("Parameter 'credential' must not be None.") + self.hub = hub self.endpoint = endpoint self.credential = credential self.api_version = api_version @@ -267,6 +273,9 @@ class WebPubSubServiceClient(GeneratedWebPubSubServiceClient): :param endpoint: HTTP or HTTPS endpoint for the Web PubSub service instance. :type endpoint: str + :param hub: Target hub name, which should start with alphabetic characters and only contain + alpha-numeric characters or underscore. + :type hub: str :param credential: Credential needed for the client to connect to Azure. :type credential: ~azure.core.credentials.TokenCredential :keyword api_version: Api Version. The default value is "2021-10-01". Note that overriding this @@ -277,13 +286,14 @@ class WebPubSubServiceClient(GeneratedWebPubSubServiceClient): def __init__( self, endpoint, # type: str + hub, # type: str credential, # type: Union[TokenCredential, AzureKeyCredential] **kwargs # type: Any ): # type: (...) -> None kwargs['origin_endpoint'] = endpoint _endpoint = '{Endpoint}' - self._config = WebPubSubServiceClientConfiguration(endpoint, credential, **kwargs) + self._config = WebPubSubServiceClientConfiguration(hub=hub, endpoint=endpoint, credential=credential, **kwargs) self._client = PipelineClient(base_url=_endpoint, config=self._config, **kwargs) self._serialize = Serializer() @@ -291,26 +301,27 @@ def __init__( self._serialize.client_side_validation = False @classmethod - def from_connection_string(cls, connection_string, **kwargs): - # type: (Type[ClientType], str, Any) -> ClientType + def from_connection_string(cls, connection_string, hub, **kwargs): + # type: (Type[ClientType], str, str, Any) -> ClientType """Create a new WebPubSubServiceClient from a connection string. :param connection_string: Connection string :type connection_string: str + :param hub: Target hub name, which should start with alphabetic characters and only contain + alpha-numeric characters or underscore. + :type hub: str :rtype: WebPubSubServiceClient """ kwargs = _parse_connection_string(connection_string, **kwargs) credential = AzureKeyCredential(kwargs.pop("accesskey")) - return cls(credential=credential, **kwargs) + return cls(hub=hub, credential=credential, **kwargs) @distributed_trace - def get_client_access_token(self, hub, **kwargs): + def get_client_access_token(self, **kwargs): # type: (str, Any) -> Dict[Any] """Build an authentication token. - :keyword hub: The hub to give access to. - :type hub: str :keyword user_id: User Id. :paramtype user_id: str :keyword roles: Roles that the connection with the generated token will have. @@ -321,7 +332,7 @@ def get_client_access_token(self, hub, **kwargs): :rtype: ~dict Example: - >>> get_client_access_token(hub='theHub') + >>> get_client_access_token() { 'baseUrl': 'wss://contoso.com/api/webpubsub/client/hubs/theHub', 'token': 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ...', @@ -341,11 +352,12 @@ def get_client_access_token(self, hub, **kwargs): # Switch from http(s) to ws(s) scheme client_endpoint = "ws" + endpoint[4:] + hub = self._config.hub client_url = "{}/client/hubs/{}".format(client_endpoint, hub) if isinstance(self._config.credential, AzureKeyCredential): token = _get_token_by_key(endpoint, hub, self._config.credential.key, **kwargs) else: - token = super(WebPubSubServiceClient, self).get_client_access_token(hub, **kwargs).get('token') + token = super(WebPubSubServiceClient, self).get_client_access_token(**kwargs).get('token') return { "baseUrl": client_url, diff --git a/sdk/webpubsub/azure-messaging-webpubsubservice/azure/messaging/webpubsubservice/aio/_patch.py b/sdk/webpubsub/azure-messaging-webpubsubservice/azure/messaging/webpubsubservice/aio/_patch.py index 4a7de4f3967e..f90fcb882a1b 100644 --- a/sdk/webpubsub/azure-messaging-webpubsubservice/azure/messaging/webpubsubservice/aio/_patch.py +++ b/sdk/webpubsub/azure-messaging-webpubsubservice/azure/messaging/webpubsubservice/aio/_patch.py @@ -63,6 +63,8 @@ class WebPubSubServiceClientConfiguration(Configuration): Note that all parameters used to create this instance are saved as instance attributes. + :param hub: Target hub name, which should start with alphabetic characters and only contain alpha-numeric characters or underscore. + :type hub: str :param endpoint: HTTP or HTTPS endpoint for the Web PubSub service instance. :type endpoint: str :param credential: Credential needed for the client to connect to Azure. @@ -73,6 +75,7 @@ class WebPubSubServiceClientConfiguration(Configuration): def __init__( self, + hub: str, endpoint: str, credential: Union["AsyncTokenCredential", "AzureKeyCredential"], **kwargs: Any @@ -80,11 +83,14 @@ def __init__( super(WebPubSubServiceClientConfiguration, self).__init__(**kwargs) api_version = kwargs.pop('api_version', "2021-10-01") # type: str + if hub is None: + raise ValueError("Parameter 'hub' must not be None.") if endpoint is None: raise ValueError("Parameter 'endpoint' must not be None.") if credential is None: raise ValueError("Parameter 'credential' must not be None.") + self.hub = hub self.endpoint = endpoint self.credential = credential self.api_version = api_version @@ -117,6 +123,9 @@ class WebPubSubServiceClient(GeneratedWebPubSubServiceClient): :param endpoint: HTTP or HTTPS endpoint for the Web PubSub service instance. :type endpoint: str + :param hub: Target hub name, which should start with alphabetic characters and only contain + alpha-numeric characters or underscore. + :type hub: str :param credential: Credential needed for the client to connect to Azure. :type credential: ~azure.core.credentials_async.AsyncTokenCredential :keyword api_version: Api Version. The default value is "2021-10-01". Note that overriding this @@ -127,12 +136,13 @@ class WebPubSubServiceClient(GeneratedWebPubSubServiceClient): def __init__( self, endpoint: str, + hub: str, credential: Union["AsyncTokenCredential", "AzureKeyCredential"], **kwargs: Any ) -> None: kwargs['origin_endpoint'] = endpoint _endpoint = '{Endpoint}' - self._config = WebPubSubServiceClientConfiguration(endpoint, credential, **kwargs) + self._config = WebPubSubServiceClientConfiguration(hub=hub, endpoint=endpoint, credential=credential, **kwargs) self._client = AsyncPipelineClient(base_url=_endpoint, config=self._config, **kwargs) self._serialize = Serializer() @@ -140,25 +150,26 @@ def __init__( self._serialize.client_side_validation = False @classmethod - def from_connection_string(cls, connection_string, **kwargs): - # type: (Type[ClientType], str, Any) -> ClientType + def from_connection_string(cls, connection_string, hub, **kwargs): + # type: (Type[ClientType], str, str, Any) -> ClientType """Create a new WebPubSubServiceClient from a connection string. :param connection_string: Connection string :type connection_string: ~str + :param hub: Target hub name, which should start with alphabetic characters and only contain + alpha-numeric characters or underscore. + :type hub: str :rtype: WebPubSubServiceClient """ kwargs = _parse_connection_string(connection_string, **kwargs) credential = AzureKeyCredential(kwargs.pop("accesskey")) - return cls(credential=credential, **kwargs) + return cls(hub=hub, credential=credential, **kwargs) @distributed_trace_async - async def get_client_access_token(self, hub, **kwargs): + async def get_client_access_token(self, **kwargs): # type: (str, Any) -> Dict[Any] """Build an authentication token. - :keyword hub: The hub to give access to. - :type hub: str :keyword user_id: User Id. :paramtype user_id: str :keyword roles: Roles that the connection with the generated token will have. @@ -169,7 +180,7 @@ async def get_client_access_token(self, hub, **kwargs): :rtype: ~dict Example: - >>> get_client_access_token(hub='theHub') + >>> get_client_access_token() { 'baseUrl': 'wss://contoso.com/api/webpubsub/client/hubs/theHub', 'token': 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ...', @@ -189,11 +200,12 @@ async def get_client_access_token(self, hub, **kwargs): # Switch from http(s) to ws(s) scheme client_endpoint = "ws" + endpoint[4:] + hub = self._config.hub client_url = "{}/client/hubs/{}".format(client_endpoint, hub) if isinstance(self._config.credential, AzureKeyCredential): token = _get_token_by_key(endpoint, hub, self._config.credential.key, **kwargs) else: - access_token = await super().get_client_access_token(hub, **kwargs) + access_token = await super().get_client_access_token(**kwargs) token = access_token.get('token') return { diff --git a/sdk/webpubsub/azure-messaging-webpubsubservice/samples/get_client_access_token.py b/sdk/webpubsub/azure-messaging-webpubsubservice/samples/get_client_access_token.py index 74a2de3c890d..561ea26a3c23 100644 --- a/sdk/webpubsub/azure-messaging-webpubsubservice/samples/get_client_access_token.py +++ b/sdk/webpubsub/azure-messaging-webpubsubservice/samples/get_client_access_token.py @@ -43,15 +43,15 @@ exit() # Build a client through AAD -client_aad = WebPubSubServiceClient(credential=DefaultAzureCredential(), endpoint=endpoint) +client_aad = WebPubSubServiceClient(credential=DefaultAzureCredential(), endpoint=endpoint, hub='hub') # Build authentication token -token_aad = client_aad.get_client_access_token(hub='hub') +token_aad = client_aad.get_client_access_token() print('token by AAD: {}'.format(token_aad)) # Build a client through connection string -client_key = WebPubSubServiceClient.from_connection_string(connection_string) +client_key = WebPubSubServiceClient.from_connection_string(connection_string, hub='hub') # Build authentication token -token_key = client_key.get_client_access_token(hub='hub') +token_key = client_key.get_client_access_token() print('token by access key: {}'.format(token_key)) diff --git a/sdk/webpubsub/azure-messaging-webpubsubservice/samples/get_client_access_token_async.py b/sdk/webpubsub/azure-messaging-webpubsubservice/samples/get_client_access_token_async.py index 7f010812cb00..b3b354d60eeb 100644 --- a/sdk/webpubsub/azure-messaging-webpubsubservice/samples/get_client_access_token_async.py +++ b/sdk/webpubsub/azure-messaging-webpubsubservice/samples/get_client_access_token_async.py @@ -47,15 +47,15 @@ async def main(): # Build a client through AAD(async) async with DefaultAzureCredential() as credential: - async with WebPubSubServiceClientAsync(credential=credential, endpoint=endpoint) as client_aad_async: + async with WebPubSubServiceClientAsync(credential=credential, endpoint=endpoint, hub='hub') as client_aad_async: # Build authentication token(async) - token_aad_async = await client_aad_async.get_client_access_token(hub='hub') + token_aad_async = await client_aad_async.get_client_access_token() print('token by AAD(async): {}'.format(token_aad_async)) # Build a client through connection string(async) - async with WebPubSubServiceClientAsync.from_connection_string(connection_string) as client_key_async: + async with WebPubSubServiceClientAsync.from_connection_string(connection_string, hub='hub') as client_key_async: # Build authentication token(async) - token_key_async = await client_key_async.get_client_access_token(hub='hub') + token_key_async = await client_key_async.get_client_access_token() print('token by access key(async): {}'.format(token_key_async)) if __name__ == '__main__': diff --git a/sdk/webpubsub/azure-messaging-webpubsubservice/samples/send_messages_aad.py b/sdk/webpubsub/azure-messaging-webpubsubservice/samples/send_messages_aad.py index 3aea2b863fcd..b84b2c51c19e 100644 --- a/sdk/webpubsub/azure-messaging-webpubsubservice/samples/send_messages_aad.py +++ b/sdk/webpubsub/azure-messaging-webpubsubservice/samples/send_messages_aad.py @@ -44,12 +44,12 @@ exit() # Build a client through AAD -client = WebPubSubServiceClient(credential=DefaultAzureCredential(), endpoint=endpoint) +client = WebPubSubServiceClient(credential=DefaultAzureCredential(), endpoint=endpoint, hub='hub') # Send a json message to everybody on the given hub... try: # Raise an exception if the service rejected the call - client.send_to_all('Hub', message={'Hello': 'all'}) + client.send_to_all(message={'Hello': 'all'}) print('Successfully sent a JSON message') except HttpResponseError as e: print('Failed to send JSON message: {}'.format(e.response.json())) @@ -57,7 +57,7 @@ # Send a text message to everybody on the given hub... try: # Raise an exception if the service rejected the call - client.send_to_all('Hub', message='hello, text!', content_type='text/plain') + client.send_to_all(message='hello, text!', content_type='text/plain') print('Successfully sent a text message') except HttpResponseError as e: print('Failed to send text message: {}'.format(e.response.json())) @@ -66,7 +66,7 @@ # Send a json message from a stream to everybody on the given hub... try: # Raise an exception if the service rejected the call - client.send_to_all('Hub', message=io.BytesIO(b'{ "hello": "world" }'), content_type='application/octet-stream') + client.send_to_all(message=io.BytesIO(b'{ "hello": "world" }'), content_type='application/octet-stream') print('Successfully sent a JSON message') except HttpResponseError as e: print('Failed to send JSON message: {}'.format(e.response.json())) diff --git a/sdk/webpubsub/azure-messaging-webpubsubservice/samples/send_messages_aad_apim_proxy.py b/sdk/webpubsub/azure-messaging-webpubsubservice/samples/send_messages_aad_apim_proxy.py index d5acc6d8938a..662f1c4f94d9 100644 --- a/sdk/webpubsub/azure-messaging-webpubsubservice/samples/send_messages_aad_apim_proxy.py +++ b/sdk/webpubsub/azure-messaging-webpubsubservice/samples/send_messages_aad_apim_proxy.py @@ -46,12 +46,12 @@ # Build a client through AAD # If you want to know more about the effect of `reverse_proxy_endpoint`, please reference: https://github.com/Azure/azure-webpubsub/issues/194 -client = WebPubSubServiceClient(credential=DefaultAzureCredential(), endpoint=endpoint, reverse_proxy_endpoint=reverse_proxy_endpoint) +client = WebPubSubServiceClient(credential=DefaultAzureCredential(), endpoint=endpoint, hub='hub', reverse_proxy_endpoint=reverse_proxy_endpoint) # Send a json message to everybody on the given hub... try: # Raise an exception if the service rejected the call - client.send_to_all('Hub', message={'Hello': 'reverse_proxy_endpoint!'}) + client.send_to_all(message={'Hello': 'reverse_proxy_endpoint!'}) print('Successfully sent a JSON message') except HttpResponseError as e: print('Failed to send JSON message: {}'.format(e.response.json())) @@ -59,7 +59,7 @@ # Send a text message to everybody on the given hub... try: # Raise an exception if the service rejected the call - client.send_to_all('Hub', message='hello, reverse_proxy_endpoint!', content_type='text/plain') + client.send_to_all(message='hello, reverse_proxy_endpoint!', content_type='text/plain') print('Successfully sent a JSON message') except HttpResponseError as e: print('Failed to send JSON message: {}'.format(e.response.json())) @@ -68,7 +68,7 @@ # Send a json message from a stream to everybody on the given hub... try: # Raise an exception if the service rejected the call - client.send_to_all('Hub', message=io.BytesIO(b'{ "hello": "reverse_proxy_endpoint" }'), content_type='application/octet-stream') + client.send_to_all(message=io.BytesIO(b'{ "hello": "reverse_proxy_endpoint" }'), content_type='application/octet-stream') print('Successfully sent a JSON message') except HttpResponseError as e: print('Failed to send JSON message: {}'.format(e.response.json())) diff --git a/sdk/webpubsub/azure-messaging-webpubsubservice/samples/send_messages_connection_string.py b/sdk/webpubsub/azure-messaging-webpubsubservice/samples/send_messages_connection_string.py index ab24eec4c48b..124fded6b5f7 100644 --- a/sdk/webpubsub/azure-messaging-webpubsubservice/samples/send_messages_connection_string.py +++ b/sdk/webpubsub/azure-messaging-webpubsubservice/samples/send_messages_connection_string.py @@ -42,11 +42,11 @@ # Build a client from the connection string. And for this example, we have enabled debug # tracing. For production code, this should be turned off. -client = WebPubSubServiceClient.from_connection_string(connection_string, logging_enable=True) +client = WebPubSubServiceClient.from_connection_string(connection_string, hub='hub', logging_enable=True) try: # Raise an exception if the service rejected the call - client.send_to_all('Hub', message={'Hello': 'all!'}) + client.send_to_all(message={'Hello': 'all!'}) print('Successfully sent a JSON message') except HttpResponseError as e: print('Failed to send JSON message: {}'.format(e.response.json())) @@ -54,7 +54,7 @@ # Send a text message to everybody on the given hub... try: # Raise an exception if the service rejected the call - client.send_to_all('Hub', message='hello, text!', content_type='text/plain') + client.send_to_all(message='hello, text!', content_type='text/plain') print('Successfully sent a JSON message') except HttpResponseError as e: print('Failed to send JSON message: {}'.format(e.response.json())) @@ -63,7 +63,7 @@ # Send a json message from a stream to everybody on the given hub... try: # Raise an exception if the service rejected the call - client.send_to_all('Hub', message=io.BytesIO(b'{ "hello": "world" }'), content_type='application/octet-stream') + client.send_to_all(message=io.BytesIO(b'{ "hello": "world" }'), content_type='application/octet-stream') print('Successfully sent a JSON message') except HttpResponseError as e: print('Failed to send JSON message: {}'.format(e.response.json())) diff --git a/sdk/webpubsub/azure-messaging-webpubsubservice/samples/send_messages_connection_string_apim_proxy.py b/sdk/webpubsub/azure-messaging-webpubsubservice/samples/send_messages_connection_string_apim_proxy.py index cf3b0ed94d04..2025dc7f838c 100644 --- a/sdk/webpubsub/azure-messaging-webpubsubservice/samples/send_messages_connection_string_apim_proxy.py +++ b/sdk/webpubsub/azure-messaging-webpubsubservice/samples/send_messages_connection_string_apim_proxy.py @@ -44,11 +44,11 @@ # Build a client from the connection string. And for this example, we have enabled debug # tracing. For production code, this should be turned off. # If you want to know more about the effect of `reverse_proxy_endpoint`, please reference: https://github.com/Azure/azure-webpubsub/issues/194 -client = WebPubSubServiceClient.from_connection_string(connection_string, logging_enable=True, reverse_proxy_endpoint=reverse_proxy_endpoint) +client = WebPubSubServiceClient.from_connection_string(connection_string, hub='hub', logging_enable=True, reverse_proxy_endpoint=reverse_proxy_endpoint) try: # Raise an exception if the service rejected the call - client.send_to_all('Hub', message={'Hello': 'connection_string_reverse_proxy!'}) + client.send_to_all(message={'Hello': 'connection_string_reverse_proxy!'}) print('Successfully sent a JSON message') except HttpResponseError as e: print('Failed to send JSON message: {}'.format(e.response.json())) @@ -56,7 +56,7 @@ # Send a text message to everybody on the given hub... try: # Raise an exception if the service rejected the call - client.send_to_all('Hub', message='hello, connection_string_reverse_proxy!', content_type='text/plain') + client.send_to_all(message='hello, connection_string_reverse_proxy!', content_type='text/plain') print('Successfully sent a JSON message') except HttpResponseError as e: print('Failed to send JSON message: {}'.format(e.response.json())) @@ -65,7 +65,7 @@ # Send a json message from a stream to everybody on the given hub... try: # Raise an exception if the service rejected the call - client.send_to_all('Hub', message=io.BytesIO(b'{ "hello": "connection_string_reverse_proxy" }'), content_type='application/octet-stream') + client.send_to_all(message=io.BytesIO(b'{ "hello": "connection_string_reverse_proxy" }'), content_type='application/octet-stream') print('Successfully sent a JSON message') except HttpResponseError as e: print('Failed to send JSON message: {}'.format(e.response.json())) diff --git a/sdk/webpubsub/azure-messaging-webpubsubservice/tests/recordings/test_smoke.test_get_client_access_token.yaml b/sdk/webpubsub/azure-messaging-webpubsubservice/tests/recordings/test_smoke.test_get_client_access_token.yaml index 05cdb35df965..21b9680f4384 100644 --- a/sdk/webpubsub/azure-messaging-webpubsubservice/tests/recordings/test_smoke.test_get_client_access_token.yaml +++ b/sdk/webpubsub/azure-messaging-webpubsubservice/tests/recordings/test_smoke.test_get_client_access_token.yaml @@ -11,13 +11,15 @@ interactions: Content-Length: - '0' User-Agent: - - azsdk-python-messaging-webpubsubservice/1.0.0 Python/3.9.5 (macOS-11.6-x86_64-i386-64bit) + - azsdk-python-messaging-webpubsubservice/1.0.0 Python/3.7.3 (Windows-10-10.0.19041-SP0) method: POST uri: https://myservice.webpubsub.azure.com/api/hubs/hub/:generateToken?minutesToExpire=60&api-version=2021-10-01 response: body: - string: '{"token":"eyJhbGciOiJIUzI1NiIsImtpZCI6InMtYTdhODUzZjMtZGE1NS00MGU5LWE0OGEtZTVhNTcxN2U4Yjk4IiwidHlwIjoiSldUIn0.eyJuYmYiOjE2MzY0MDczMjIsImV4cCI6MTYzNjQxMDkyMiwiaWF0IjoxNjM2NDA3MzIyLCJhdWQiOiJodHRwczovL3dlYnB1YnN1Yi15eWMud2VicHVic3ViLmF6dXJlLmNvbS9jbGllbnQvaHVicy9odWIifQ.MXXNoxwYlH5LVLeyWkPQU8E_Y0m1WXIBE5JWy2xFyXs"}' + string: '{"token":"eyJhbGciOiJIUzI1NiIsImtpZCI6InMtYTdhODUzZjMtZGE1NS00MGU5LWE0OGEtZTVhNTcxN2U4Yjk4IiwidHlwIjoiSldUIn0.eyJuYmYiOjE2MzY1MTYyNzEsImV4cCI6MTYzNjUxOTg3MSwiaWF0IjoxNjM2NTE2MjcxLCJhdWQiOiJodHRwczovL3dlYnB1YnN1Yi15eWMud2VicHVic3ViLmF6dXJlLmNvbS9jbGllbnQvaHVicy9odWIifQ.Wn9-TPRUG54A0GpMUwah86XG8yQxvH8HcQincCf7pAE"}' headers: + api-supported-versions: + - '2021-10-01' connection: - keep-alive content-length: @@ -25,7 +27,7 @@ interactions: content-type: - application/json; charset=utf-8 date: - - Mon, 08 Nov 2021 21:35:22 GMT + - Wed, 10 Nov 2021 03:51:11 GMT strict-transport-security: - max-age=15724800; includeSubDomains transfer-encoding: diff --git a/sdk/webpubsub/azure-messaging-webpubsubservice/tests/recordings/test_smoke.test_webpubsub_send_request.yaml b/sdk/webpubsub/azure-messaging-webpubsubservice/tests/recordings/test_smoke.test_webpubsub_send_request.yaml index f295ab2a4034..05404f3c3963 100644 --- a/sdk/webpubsub/azure-messaging-webpubsubservice/tests/recordings/test_smoke.test_webpubsub_send_request.yaml +++ b/sdk/webpubsub/azure-messaging-webpubsubservice/tests/recordings/test_smoke.test_webpubsub_send_request.yaml @@ -13,19 +13,21 @@ interactions: Content-Type: - text/plain User-Agent: - - azsdk-python-messaging-webpubsubservice/1.0.0b3 Python/3.7.3 (Windows-10-10.0.19041-SP0) + - azsdk-python-messaging-webpubsubservice/1.0.0 Python/3.7.3 (Windows-10-10.0.19041-SP0) method: POST uri: https://myservice.webpubsub.azure.com/api/hubs/Hub/:send?api-version=2021-10-01 response: body: string: '' headers: + api-supported-versions: + - '2021-10-01' connection: - keep-alive content-length: - '0' date: - - Thu, 04 Nov 2021 03:43:19 GMT + - Wed, 10 Nov 2021 03:51:15 GMT strict-transport-security: - max-age=15724800; includeSubDomains status: diff --git a/sdk/webpubsub/azure-messaging-webpubsubservice/tests/recordings/test_smoke.test_webpubsub_send_to_all.yaml b/sdk/webpubsub/azure-messaging-webpubsubservice/tests/recordings/test_smoke.test_webpubsub_send_to_all.yaml index da7a63247a36..d6d6d0049321 100644 --- a/sdk/webpubsub/azure-messaging-webpubsubservice/tests/recordings/test_smoke.test_webpubsub_send_to_all.yaml +++ b/sdk/webpubsub/azure-messaging-webpubsubservice/tests/recordings/test_smoke.test_webpubsub_send_to_all.yaml @@ -13,19 +13,21 @@ interactions: Content-Type: - application/json User-Agent: - - azsdk-python-messaging-webpubsubservice/1.0.0b3 Python/3.7.3 (Windows-10-10.0.19041-SP0) + - azsdk-python-messaging-webpubsubservice/1.0.0 Python/3.7.3 (Windows-10-10.0.19041-SP0) method: POST - uri: https://myservice.webpubsub.azure.com/api/hubs/Hub/:send?api-version=2021-10-01 + uri: https://myservice.webpubsub.azure.com/api/hubs/hub/:send?api-version=2021-10-01 response: body: string: '' headers: + api-supported-versions: + - '2021-10-01' connection: - keep-alive content-length: - '0' date: - - Thu, 04 Nov 2021 03:43:22 GMT + - Wed, 10 Nov 2021 03:51:17 GMT strict-transport-security: - max-age=15724800; includeSubDomains status: diff --git a/sdk/webpubsub/azure-messaging-webpubsubservice/tests/recordings/test_smoke.test_webpubsub_send_to_all_api_management_proxy.yaml b/sdk/webpubsub/azure-messaging-webpubsubservice/tests/recordings/test_smoke.test_webpubsub_send_to_all_api_management_proxy.yaml index 4cea0647a08d..142a7b0f15f7 100644 --- a/sdk/webpubsub/azure-messaging-webpubsubservice/tests/recordings/test_smoke.test_webpubsub_send_to_all_api_management_proxy.yaml +++ b/sdk/webpubsub/azure-messaging-webpubsubservice/tests/recordings/test_smoke.test_webpubsub_send_to_all_api_management_proxy.yaml @@ -13,17 +13,19 @@ interactions: Content-Type: - application/json User-Agent: - - azsdk-python-messaging-webpubsubservice/1.0.0b3 Python/3.7.3 (Windows-10-10.0.19041-SP0) + - azsdk-python-messaging-webpubsubservice/1.0.0 Python/3.7.3 (Windows-10-10.0.19041-SP0) method: POST - uri: https://myservice.azure-api.net/api/hubs/Hub/:send?api-version=2021-10-01 + uri: https://myservice.azure-api.net/api/hubs/hub/:send?api-version=2021-10-01 response: body: string: '' headers: + api-supported-versions: + - '2021-10-01' content-length: - '0' date: - - Thu, 04 Nov 2021 03:43:25 GMT + - Wed, 10 Nov 2021 03:51:19 GMT strict-transport-security: - max-age=15724800; includeSubDomains status: diff --git a/sdk/webpubsub/azure-messaging-webpubsubservice/tests/recordings/test_smoke_async.test_get_client_access_token.yaml b/sdk/webpubsub/azure-messaging-webpubsubservice/tests/recordings/test_smoke_async.test_get_client_access_token.yaml index e7f32435a510..6551a36dc7c3 100644 --- a/sdk/webpubsub/azure-messaging-webpubsubservice/tests/recordings/test_smoke_async.test_get_client_access_token.yaml +++ b/sdk/webpubsub/azure-messaging-webpubsubservice/tests/recordings/test_smoke_async.test_get_client_access_token.yaml @@ -5,16 +5,17 @@ interactions: Accept: - application/json, text/json User-Agent: - - azsdk-python-messaging-webpubsubservice/1.0.0 Python/3.9.5 (macOS-11.6-x86_64-i386-64bit) + - azsdk-python-messaging-webpubsubservice/1.0.0 Python/3.7.3 (Windows-10-10.0.19041-SP0) method: POST uri: https://myservice.webpubsub.azure.com/api/hubs/hub/:generateToken?minutesToExpire=60&api-version=2021-10-01 response: body: - string: '{"token":"eyJhbGciOiJIUzI1NiIsImtpZCI6InMtYTdhODUzZjMtZGE1NS00MGU5LWE0OGEtZTVhNTcxN2U4Yjk4IiwidHlwIjoiSldUIn0.eyJuYmYiOjE2MzY0MDczMjMsImV4cCI6MTYzNjQxMDkyMywiaWF0IjoxNjM2NDA3MzIzLCJhdWQiOiJodHRwczovL3dlYnB1YnN1Yi15eWMud2VicHVic3ViLmF6dXJlLmNvbS9jbGllbnQvaHVicy9odWIifQ.XCY7TIIyvjJvlC3gY5-oXd7xX-3wNzGVv35Hsm0Bwts"}' + string: '{"token":"eyJhbGciOiJIUzI1NiIsImtpZCI6InMtYTdhODUzZjMtZGE1NS00MGU5LWE0OGEtZTVhNTcxN2U4Yjk4IiwidHlwIjoiSldUIn0.eyJuYmYiOjE2MzY1MTYyOTEsImV4cCI6MTYzNjUxOTg5MSwiaWF0IjoxNjM2NTE2MjkxLCJhdWQiOiJodHRwczovL3dlYnB1YnN1Yi15eWMud2VicHVic3ViLmF6dXJlLmNvbS9jbGllbnQvaHVicy9odWIifQ.B0e9vJguSn_tYlz48vV-4YeaeRnSz8LtCk3NLg2PZPY"}' headers: + api-supported-versions: '2021-10-01' connection: keep-alive content-type: application/json; charset=utf-8 - date: Mon, 08 Nov 2021 21:35:23 GMT + date: Wed, 10 Nov 2021 03:51:31 GMT strict-transport-security: max-age=15724800; includeSubDomains transfer-encoding: chunked vary: Accept-Encoding diff --git a/sdk/webpubsub/azure-messaging-webpubsubservice/tests/recordings/test_smoke_async.test_webpubsub_send_to_all.yaml b/sdk/webpubsub/azure-messaging-webpubsubservice/tests/recordings/test_smoke_async.test_webpubsub_send_to_all.yaml index 1d06e0e8b263..c64196a94947 100644 --- a/sdk/webpubsub/azure-messaging-webpubsubservice/tests/recordings/test_smoke_async.test_webpubsub_send_to_all.yaml +++ b/sdk/webpubsub/azure-messaging-webpubsubservice/tests/recordings/test_smoke_async.test_webpubsub_send_to_all.yaml @@ -9,19 +9,20 @@ interactions: Content-Type: - application/json User-Agent: - - azsdk-python-messaging-webpubsubservice/1.0.0b3 Python/3.7.3 (Windows-10-10.0.19041-SP0) + - azsdk-python-messaging-webpubsubservice/1.0.0 Python/3.7.3 (Windows-10-10.0.19041-SP0) method: POST - uri: https://myservice.webpubsub.azure.com/api/hubs/Hub/:send?api-version=2021-10-01 + uri: https://myservice.webpubsub.azure.com/api/hubs/hub/:send?api-version=2021-10-01 response: body: string: '' headers: + api-supported-versions: '2021-10-01' connection: keep-alive content-length: '0' - date: Fri, 05 Nov 2021 05:03:57 GMT + date: Wed, 10 Nov 2021 03:51:33 GMT strict-transport-security: max-age=15724800; includeSubDomains status: code: 202 message: Accepted - url: https://webpubsub-yyc.webpubsub.azure.com/api/hubs/Hub/:send?api-version=2021-10-01 + url: https://webpubsub-yyc.webpubsub.azure.com/api/hubs/hub/:send?api-version=2021-10-01 version: 1 diff --git a/sdk/webpubsub/azure-messaging-webpubsubservice/tests/recordings/test_smoke_async.test_webpubsub_send_to_all_apim_proxy.yaml b/sdk/webpubsub/azure-messaging-webpubsubservice/tests/recordings/test_smoke_async.test_webpubsub_send_to_all_apim_proxy.yaml index 4818dba79a5d..d9eefa1e2bc7 100644 --- a/sdk/webpubsub/azure-messaging-webpubsubservice/tests/recordings/test_smoke_async.test_webpubsub_send_to_all_apim_proxy.yaml +++ b/sdk/webpubsub/azure-messaging-webpubsubservice/tests/recordings/test_smoke_async.test_webpubsub_send_to_all_apim_proxy.yaml @@ -9,18 +9,19 @@ interactions: Content-Type: - application/json User-Agent: - - azsdk-python-messaging-webpubsubservice/1.0.0b3 Python/3.7.3 (Windows-10-10.0.19041-SP0) + - azsdk-python-messaging-webpubsubservice/1.0.0 Python/3.7.3 (Windows-10-10.0.19041-SP0) method: POST - uri: https://myservice.azure-api.net/api/hubs/Hub/:send?api-version=2021-10-01 + uri: https://myservice.azure-api.net/api/hubs/hub/:send?api-version=2021-10-01 response: body: string: '' headers: + api-supported-versions: '2021-10-01' content-length: '0' - date: Fri, 05 Nov 2021 05:04:00 GMT + date: Wed, 10 Nov 2021 03:51:35 GMT strict-transport-security: max-age=15724800; includeSubDomains status: code: 202 message: Accepted - url: https://apimanagement-yyc.azure-api.net/api/hubs/Hub/:send?api-version=2021-10-01 + url: https://apimanagement-yyc.azure-api.net/api/hubs/hub/:send?api-version=2021-10-01 version: 1 diff --git a/sdk/webpubsub/azure-messaging-webpubsubservice/tests/test_smoke.py b/sdk/webpubsub/azure-messaging-webpubsubservice/tests/test_smoke.py index 30cf81ff165e..e6d503e8915a 100644 --- a/sdk/webpubsub/azure-messaging-webpubsubservice/tests/test_smoke.py +++ b/sdk/webpubsub/azure-messaging-webpubsubservice/tests/test_smoke.py @@ -14,17 +14,17 @@ class WebpubsubSmokeTest(WebpubsubTest): @WebpubsubPowerShellPreparer() def test_webpubsub_send_to_all(self, webpubsub_endpoint): - client = self.create_client(endpoint=webpubsub_endpoint) - client.send_to_all('Hub', {'hello': 'test_webpubsub_send_to_all'}) + client = self.create_client(endpoint=webpubsub_endpoint, hub='hub') + client.send_to_all({'hello': 'test_webpubsub_send_to_all'}) @WebpubsubPowerShellPreparer() def test_webpubsub_send_to_all_api_management_proxy(self, webpubsub_endpoint, webpubsub_reverse_proxy_endpoint=None): - client = self.create_client(endpoint=webpubsub_endpoint, reverse_proxy_endpoint=webpubsub_reverse_proxy_endpoint) - client.send_to_all('Hub', {'hello': 'test_webpubsub_send_to_all_api_management_proxy'}) + client = self.create_client(endpoint=webpubsub_endpoint, hub='hub', reverse_proxy_endpoint=webpubsub_reverse_proxy_endpoint) + client.send_to_all({'hello': 'test_webpubsub_send_to_all_api_management_proxy'}) @WebpubsubPowerShellPreparer() def test_webpubsub_send_request(self, webpubsub_endpoint): - client = self.create_client(endpoint=webpubsub_endpoint) + client = self.create_client(endpoint=webpubsub_endpoint, hub='hub') request = build_send_to_all_request('Hub', content='test_webpubsub_send_request', content_type='text/plain') response = client.send_request(request) assert response.status_code == 202 @@ -32,14 +32,14 @@ def test_webpubsub_send_request(self, webpubsub_endpoint): # If reverse_proxy_endpoint is not available, `ServiceRequestError` will be raised @WebpubsubPowerShellPreparer() def test_webpubsub_send_to_all_api_management_proxy_counter_test(self, webpubsub_endpoint): - client = self.create_client(endpoint=webpubsub_endpoint, reverse_proxy_endpoint='https://example.azure-api.net') + client = self.create_client(endpoint=webpubsub_endpoint, hub='hub', reverse_proxy_endpoint='https://example.azure-api.net') with pytest.raises(ServiceRequestError): - client.send_to_all('Hub', {'hello': 'test_webpubsub_send_to_all_api_management_proxy_counter_test'}) + client.send_to_all({'hello': 'test_webpubsub_send_to_all_api_management_proxy_counter_test'}) @WebpubsubPowerShellPreparer() def test_get_client_access_token(self, webpubsub_endpoint): - client = self.create_client(endpoint=webpubsub_endpoint) - access_token = client.get_client_access_token(hub='hub') + client = self.create_client(endpoint=webpubsub_endpoint, hub='hub') + access_token = client.get_client_access_token() assert len(access_token) == 3 assert access_token['baseUrl'][:3] == "wss" assert access_token['token'] diff --git a/sdk/webpubsub/azure-messaging-webpubsubservice/tests/test_smoke_async.py b/sdk/webpubsub/azure-messaging-webpubsubservice/tests/test_smoke_async.py index 54003fbb010d..55a7270f6c25 100644 --- a/sdk/webpubsub/azure-messaging-webpubsubservice/tests/test_smoke_async.py +++ b/sdk/webpubsub/azure-messaging-webpubsubservice/tests/test_smoke_async.py @@ -5,25 +5,25 @@ # license information. # ------------------------------------------------------------------------- from testcase import WebpubsubPowerShellPreparer -from testcase_async import WebpubsubTestAsync +from testcase_async import WebpubsubAsyncTest -class WebpubsubSmokeTestAsync(WebpubsubTestAsync): +class WebpubsubSmokeAsyncTest(WebpubsubAsyncTest): @WebpubsubPowerShellPreparer() async def test_webpubsub_send_to_all(self, webpubsub_endpoint): - client = self.create_client(endpoint=webpubsub_endpoint) - await client.send_to_all('Hub', {'hello': 'test_webpubsub_send_to_all'}) + client = self.create_client(endpoint=webpubsub_endpoint, hub='hub') + await client.send_to_all({'hello': 'test_webpubsub_send_to_all'}) @WebpubsubPowerShellPreparer() async def test_webpubsub_send_to_all_apim_proxy(self, webpubsub_endpoint, webpubsub_reverse_proxy_endpoint=None): - client = self.create_client(endpoint=webpubsub_endpoint, reverse_proxy_endpoint=webpubsub_reverse_proxy_endpoint) - await client.send_to_all('Hub', {'hello': 'test_webpubsub_send_to_all_apim_proxy'}) + client = self.create_client(endpoint=webpubsub_endpoint, hub='hub', reverse_proxy_endpoint=webpubsub_reverse_proxy_endpoint) + await client.send_to_all({'hello': 'test_webpubsub_send_to_all_apim_proxy'}) @WebpubsubPowerShellPreparer() async def test_get_client_access_token(self, webpubsub_endpoint): - client = self.create_client(endpoint=webpubsub_endpoint) - access_token = await client.get_client_access_token(hub='hub') + client = self.create_client(endpoint=webpubsub_endpoint, hub='hub') + access_token = await client.get_client_access_token() assert len(access_token) == 3 assert access_token['baseUrl'][:3] == "wss" assert access_token['token'] diff --git a/sdk/webpubsub/azure-messaging-webpubsubservice/tests/testcase.py b/sdk/webpubsub/azure-messaging-webpubsubservice/tests/testcase.py index 9f2875e70fc4..be4c70d640a4 100644 --- a/sdk/webpubsub/azure-messaging-webpubsubservice/tests/testcase.py +++ b/sdk/webpubsub/azure-messaging-webpubsubservice/tests/testcase.py @@ -13,12 +13,13 @@ class WebpubsubTest(AzureTestCase): def __init__(self, method_name, **kwargs): super(WebpubsubTest, self).__init__(method_name, **kwargs) - def create_client(self, endpoint, reverse_proxy_endpoint=None): + def create_client(self, endpoint, hub, reverse_proxy_endpoint=None): credential = self.get_credential(WebPubSubServiceClient) return self.create_client_from_credential( WebPubSubServiceClient, credential=credential, endpoint=endpoint, + hub=hub, reverse_proxy_endpoint=reverse_proxy_endpoint ) diff --git a/sdk/webpubsub/azure-messaging-webpubsubservice/tests/testcase_async.py b/sdk/webpubsub/azure-messaging-webpubsubservice/tests/testcase_async.py index 46f9f1662b8e..9930e81b7628 100644 --- a/sdk/webpubsub/azure-messaging-webpubsubservice/tests/testcase_async.py +++ b/sdk/webpubsub/azure-messaging-webpubsubservice/tests/testcase_async.py @@ -8,15 +8,16 @@ from azure.messaging.webpubsubservice.aio import WebPubSubServiceClient -class WebpubsubTestAsync(AzureTestCase): +class WebpubsubAsyncTest(AzureTestCase): def __init__(self, method_name, **kwargs): - super(WebpubsubTestAsync, self).__init__(method_name, **kwargs) + super(WebpubsubAsyncTest, self).__init__(method_name, **kwargs) - def create_client(self, endpoint, reverse_proxy_endpoint=None): + def create_client(self, endpoint, hub, reverse_proxy_endpoint=None): credential = self.get_credential(WebPubSubServiceClient, is_async=True) return self.create_client_from_credential( WebPubSubServiceClient, credential=credential, endpoint=endpoint, + hub=hub, reverse_proxy_endpoint=reverse_proxy_endpoint ) From e5d442109e8bd7a40257fef59e126a3a8c8c1103 Mon Sep 17 00:00:00 2001 From: msyyc <70930885+msyyc@users.noreply.github.com> Date: Wed, 10 Nov 2021 11:56:34 +0800 Subject: [PATCH 3/4] changelog --- sdk/webpubsub/azure-messaging-webpubsubservice/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/sdk/webpubsub/azure-messaging-webpubsubservice/CHANGELOG.md b/sdk/webpubsub/azure-messaging-webpubsubservice/CHANGELOG.md index 53011aa638d5..8e8b7120eeb4 100644 --- a/sdk/webpubsub/azure-messaging-webpubsubservice/CHANGELOG.md +++ b/sdk/webpubsub/azure-messaging-webpubsubservice/CHANGELOG.md @@ -10,6 +10,7 @@ - remove the `operations` namespace from `azure.messaging.webpubsubservice` - rename operation `check_permission` to `has_permission` - operations `connection_exists`, `group_exists`, `user_exists`, and `has_permission` now return boolean values instead of raising +- move parameter 'hub' from operation to client ## 1.0.0b2 (2021-10-14) From 638ef7e5565f883876cdb477c9a3a8f430beb950 Mon Sep 17 00:00:00 2001 From: msyyc <70930885+msyyc@users.noreply.github.com> Date: Wed, 10 Nov 2021 15:39:48 +0800 Subject: [PATCH 4/4] update readme --- .../README.md | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/sdk/webpubsub/azure-messaging-webpubsubservice/README.md b/sdk/webpubsub/azure-messaging-webpubsubservice/README.md index 525883a687c2..a8f01f9017a0 100644 --- a/sdk/webpubsub/azure-messaging-webpubsubservice/README.md +++ b/sdk/webpubsub/azure-messaging-webpubsubservice/README.md @@ -36,7 +36,7 @@ You can authenticate the `WebPubSubServiceClient` using [connection string][conn ```python >>> from azure.messaging.webpubsubservice import WebPubSubServiceClient ->>> service = WebPubSubServiceClient.from_connection_string(connection_string='') +>>> service = WebPubSubServiceClient.from_connection_string(connection_string='', hub='hub') ``` Or using the service endpoint and the access key: @@ -45,7 +45,7 @@ Or using the service endpoint and the access key: >>> from azure.messaging.webpubsubservice import WebPubSubServiceClient >>> from azure.core.credentials import AzureKeyCredential ->>> service = WebPubSubServiceClient(endpoint='', credential=AzureKeyCredential("")) +>>> service = WebPubSubServiceClient(endpoint='', hub='hub', credential=AzureKeyCredential("")) ``` Or using [Azure Active Directory][aad_doc]: @@ -56,7 +56,7 @@ Or using [Azure Active Directory][aad_doc]: ```python >>> from azure.messaging.webpubsubservice import WebPubSubServiceClient >>> from azure.identity import DefaultAzureCredential - >>> service = WebPubSubServiceClient(endpoint='', credential=DefaultAzureCredential()) + >>> service = WebPubSubServiceClient(endpoint='', hub='hub', credential=DefaultAzureCredential()) ``` ## Key concepts @@ -88,8 +88,8 @@ When the client is connected, it can send messages to the upstream application, ```python >>> from azure.messaging.webpubsubservice import WebPubSubServiceClient ->>> service = WebPubSubServiceClient.from_connection_string('') ->>> service.send_to_all('hub1', message = { +>>> service = WebPubSubServiceClient.from_connection_string('', hub='hub1') +>>> service.send_to_all(message = { 'from': 'user1', 'data': 'Hello world' }) @@ -101,8 +101,8 @@ The WebSocket client will receive JSON serialized text: `{"from": "user1", "data ```python >>> from azure.messaging.webpubsubservice import WebPubSubServiceClient ->>> service = WebPubSubServiceClient.from_connection_string('') ->>> service.send_to_all('hub1', message = 'Hello world', content_type='text/plain') +>>> service = WebPubSubServiceClient.from_connection_string('', hub='hub1') +>>> service.send_to_all(message = 'Hello world', content_type='text/plain') ``` The WebSocket client will receive text: `Hello world`. @@ -112,8 +112,8 @@ The WebSocket client will receive text: `Hello world`. ```python >>> import io >>> from azure.messaging.webpubsubservice import WebPubSubServiceClient ->>> service = WebPubSubServiceClient.from_connection_string('') ->>> service.send_to_all('hub1', message=io.StringIO('Hello World'), content_type='application/octet-stream') +>>> service = WebPubSubServiceClient.from_connection_string('', hub='hub') +>>> service.send_to_all(message=io.StringIO('Hello World'), content_type='application/octet-stream') ``` The WebSocket client will receive binary text: `b'Hello world'`. @@ -142,7 +142,7 @@ endpoint = "" credential = DefaultAzureCredential() # This WebPubSubServiceClient will log detailed information about its HTTP sessions, at DEBUG level -service = WebPubSubServiceClient(endpoint=endpoint, credential=credential, logging_enable=True) +service = WebPubSubServiceClient(endpoint=endpoint, hub='hub', credential=credential, logging_enable=True) ``` Similarly, `logging_enable` can enable detailed logging for a single call,