Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[webpubsub] regen with hub as a client parameter #21688

Merged
merged 5 commits into from
Nov 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 10 additions & 10 deletions sdk/webpubsub/azure-messaging-webpubsubservice/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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='<connection_string>')
>>> service = WebPubSubServiceClient.from_connection_string(connection_string='<connection_string>', hub='hub')
```

Or using the service endpoint and the access key:
Expand All @@ -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='<endpoint>', credential=AzureKeyCredential("<access_key>"))
>>> service = WebPubSubServiceClient(endpoint='<endpoint>', hub='hub', credential=AzureKeyCredential("<access_key>"))
```

Or using [Azure Active Directory][aad_doc]:
Expand All @@ -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='<endpoint>', credential=DefaultAzureCredential())
>>> service = WebPubSubServiceClient(endpoint='<endpoint>', hub='hub', credential=DefaultAzureCredential())
```

## Key concepts
Expand Down Expand Up @@ -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('<connection_string>')
>>> service.send_to_all('hub1', message = {
>>> service = WebPubSubServiceClient.from_connection_string('<connection_string>', hub='hub1')
>>> service.send_to_all(message = {
'from': 'user1',
'data': 'Hello world'
})
Expand All @@ -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('<connection_string>')
>>> service.send_to_all('hub1', message = 'Hello world', content_type='text/plain')
>>> service = WebPubSubServiceClient.from_connection_string('<connection_string>', hub='hub1')
>>> service.send_to_all(message = 'Hello world', content_type='text/plain')
```

The WebSocket client will receive text: `Hello world`.
Expand All @@ -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('<connection_string>')
>>> service.send_to_all('hub1', message=io.StringIO('Hello World'), content_type='application/octet-stream')
>>> service = WebPubSubServiceClient.from_connection_string('<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'`.

Expand Down Expand Up @@ -142,7 +142,7 @@ endpoint = "<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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -36,6 +38,7 @@ class WebPubSubServiceClientConfiguration(Configuration):

def __init__(
self,
hub, # type: str
endpoint, # type: str
credential, # type: "TokenCredential"
**kwargs # type: Any
Expand All @@ -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
Expand Down
Loading