# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------
import functools
from typing import Any, Callable, Dict, Generic, IO, List, Optional, TypeVar, Union
import warnings
from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error
from azure.core.pipeline import PipelineResponse
from azure.core.pipeline.transport import AsyncHttpResponse
from azure.core.rest import HttpRequest
from azure.core.tracing.decorator_async import distributed_trace_async
from ...operations._operations import build_add_connection_to_group_request, build_add_user_to_group_request, build_check_permission_request, build_close_all_connections_request, build_close_connection_request, build_close_group_connections_request, build_close_user_connections_request, build_connection_exists_request, build_generate_client_token_request, build_grant_permission_request, build_group_exists_request, build_remove_connection_from_group_request, build_remove_user_from_all_groups_request, build_remove_user_from_group_request, build_revoke_permission_request, build_send_to_all_request, build_send_to_connection_request, build_send_to_group_request, build_send_to_user_request, build_user_exists_request
T = TypeVar('T')
ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]]
[docs]class WebPubSubServiceClientOperationsMixin:
[docs] @distributed_trace_async
async def generate_client_token(
self,
hub: str,
*,
user_id: Optional[str] = None,
role: Optional[List[str]] = None,
minutes_to_expire: Optional[int] = 60,
**kwargs: Any
) -> Any:
"""Generate token for the client to connect Azure Web PubSub service.
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 role: Roles that the connection with the generated token will have.
:paramtype role: list[str]
:keyword minutes_to_expire: The expire time of the generated token.
:paramtype minutes_to_expire: int
:return: JSON object
:rtype: Any
:raises: ~azure.core.exceptions.HttpResponseError
Example:
.. code-block:: python
# response body for status code(s): 200
response.json() == {
"token": "str" # Optional. The token value for the WebSocket client to connect to the service.
}
"""
cls = kwargs.pop('cls', None) # type: ClsType[Any]
error_map = {
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
}
error_map.update(kwargs.pop('error_map', {}))
request = build_generate_client_token_request(
hub=hub,
user_id=user_id,
role=role,
minutes_to_expire=minutes_to_expire,
template_url=self.generate_client_token.metadata['url'],
)
path_format_arguments = {
"Endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True),
}
request.url = self._client.format_url(request.url, **path_format_arguments)
pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
response = pipeline_response.http_response
if response.status_code not in [200]:
map_error(status_code=response.status_code, response=response, error_map=error_map)
raise HttpResponseError(response=response)
if response.content:
deserialized = response.json()
else:
deserialized = None
if cls:
return cls(pipeline_response, deserialized, {})
return deserialized
generate_client_token.metadata = {'url': '/api/hubs/{hub}/:generateToken'} # type: ignore
[docs] @distributed_trace_async
async def close_all_connections(
self,
hub: str,
*,
excluded: Optional[List[str]] = None,
reason: Optional[str] = None,
**kwargs: Any
) -> None:
"""Close the connections in the hub.
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.
:paramtype reason: str
:return: None
:rtype: None
:raises: ~azure.core.exceptions.HttpResponseError
"""
cls = kwargs.pop('cls', None) # type: ClsType[None]
error_map = {
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
}
error_map.update(kwargs.pop('error_map', {}))
request = build_close_all_connections_request(
hub=hub,
excluded=excluded,
reason=reason,
template_url=self.close_all_connections.metadata['url'],
)
path_format_arguments = {
"Endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True),
}
request.url = self._client.format_url(request.url, **path_format_arguments)
pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
response = pipeline_response.http_response
if response.status_code not in [204]:
map_error(status_code=response.status_code, response=response, error_map=error_map)
raise HttpResponseError(response=response)
if cls:
return cls(pipeline_response, None, {})
close_all_connections.metadata = {'url': '/api/hubs/{hub}/:closeConnections'} # type: ignore
[docs] @distributed_trace_async
async def send_to_all(
self,
hub: str,
message: Union[IO, str],
*,
excluded: Optional[List[str]] = None,
**kwargs: Any
) -> None:
"""Broadcast content inside request body to all the connected client connections.
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
:keyword excluded: Excluded connection Ids.
:paramtype excluded: list[str]
:keyword str content_type: Media type of the body sent to the API. Default value is
"application/json". Allowed values are: "application/json", "application/octet-stream",
"text/plain."
:return: None
:rtype: None
:raises: ~azure.core.exceptions.HttpResponseError
"""
cls = kwargs.pop('cls', None) # type: ClsType[None]
error_map = {
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
}
error_map.update(kwargs.pop('error_map', {}))
content_type = kwargs.pop('content_type', "text/plain") # type: Optional[str]
json = None
content = None
if content_type.split(";")[0] in ['application/json', 'application/octet-stream']:
content = message
elif content_type.split(";")[0] in ['text/plain']:
json = message
else:
raise ValueError(
"The content_type '{}' is not one of the allowed values: "
"['application/json', 'application/octet-stream', 'text/plain']".format(content_type)
)
request = build_send_to_all_request(
hub=hub,
content_type=content_type,
excluded=excluded,
json=json,
content=content,
template_url=self.send_to_all.metadata['url'],
)
path_format_arguments = {
"Endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True),
}
request.url = self._client.format_url(request.url, **path_format_arguments)
pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
response = pipeline_response.http_response
if response.status_code not in [202]:
map_error(status_code=response.status_code, response=response, error_map=error_map)
raise HttpResponseError(response=response)
if cls:
return cls(pipeline_response, None, {})
send_to_all.metadata = {'url': '/api/hubs/{hub}/:send'} # type: ignore
[docs] @distributed_trace_async
async def connection_exists(
self,
hub: str,
connection_id: str,
**kwargs: Any
) -> None:
"""Check if the connection with the given connectionId 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
:return: None
:rtype: None
:raises: ~azure.core.exceptions.HttpResponseError
"""
cls = kwargs.pop('cls', None) # type: ClsType[None]
error_map = {
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
}
error_map.update(kwargs.pop('error_map', {}))
request = build_connection_exists_request(
hub=hub,
connection_id=connection_id,
template_url=self.connection_exists.metadata['url'],
)
path_format_arguments = {
"Endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True),
}
request.url = self._client.format_url(request.url, **path_format_arguments)
pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
response = pipeline_response.http_response
if response.status_code not in [200, 404]:
map_error(status_code=response.status_code, response=response, error_map=error_map)
raise HttpResponseError(response=response)
if cls:
return cls(pipeline_response, None, {})
connection_exists.metadata = {'url': '/api/hubs/{hub}/connections/{connectionId}'} # type: ignore
[docs] @distributed_trace_async
async def close_connection(
self,
hub: str,
connection_id: str,
*,
reason: Optional[str] = None,
**kwargs: Any
) -> None:
"""Close the client 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.
:paramtype reason: str
:return: None
:rtype: None
:raises: ~azure.core.exceptions.HttpResponseError
"""
cls = kwargs.pop('cls', None) # type: ClsType[None]
error_map = {
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
}
error_map.update(kwargs.pop('error_map', {}))
request = build_close_connection_request(
hub=hub,
connection_id=connection_id,
reason=reason,
template_url=self.close_connection.metadata['url'],
)
path_format_arguments = {
"Endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True),
}
request.url = self._client.format_url(request.url, **path_format_arguments)
pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
response = pipeline_response.http_response
if response.status_code not in [204]:
map_error(status_code=response.status_code, response=response, error_map=error_map)
raise HttpResponseError(response=response)
if cls:
return cls(pipeline_response, None, {})
close_connection.metadata = {'url': '/api/hubs/{hub}/connections/{connectionId}'} # type: ignore
[docs] @distributed_trace_async
async def send_to_connection(
self,
hub: str,
connection_id: str,
message: Union[IO, str],
**kwargs: Any
) -> None:
"""Send content inside request body to the specific 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.
:type message: IO or str
:keyword str content_type: Media type of the body sent to the API. Default value is
"application/json". Allowed values are: "application/json", "application/octet-stream",
"text/plain."
:return: None
:rtype: None
:raises: ~azure.core.exceptions.HttpResponseError
"""
cls = kwargs.pop('cls', None) # type: ClsType[None]
error_map = {
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
}
error_map.update(kwargs.pop('error_map', {}))
content_type = kwargs.pop('content_type', "text/plain") # type: Optional[str]
json = None
content = None
if content_type.split(";")[0] in ['application/json', 'application/octet-stream']:
content = message
elif content_type.split(";")[0] in ['text/plain']:
json = message
else:
raise ValueError(
"The content_type '{}' is not one of the allowed values: "
"['application/json', 'application/octet-stream', 'text/plain']".format(content_type)
)
request = build_send_to_connection_request(
hub=hub,
connection_id=connection_id,
content_type=content_type,
json=json,
content=content,
template_url=self.send_to_connection.metadata['url'],
)
path_format_arguments = {
"Endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True),
}
request.url = self._client.format_url(request.url, **path_format_arguments)
pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
response = pipeline_response.http_response
if response.status_code not in [202]:
map_error(status_code=response.status_code, response=response, error_map=error_map)
raise HttpResponseError(response=response)
if cls:
return cls(pipeline_response, None, {})
send_to_connection.metadata = {'url': '/api/hubs/{hub}/connections/{connectionId}/:send'} # type: ignore
[docs] @distributed_trace_async
async def group_exists(
self,
hub: str,
group: str,
**kwargs: Any
) -> None:
"""Check if there are any client connections inside the given group.
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
:return: None
:rtype: None
:raises: ~azure.core.exceptions.HttpResponseError
"""
cls = kwargs.pop('cls', None) # type: ClsType[None]
error_map = {
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
}
error_map.update(kwargs.pop('error_map', {}))
request = build_group_exists_request(
hub=hub,
group=group,
template_url=self.group_exists.metadata['url'],
)
path_format_arguments = {
"Endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True),
}
request.url = self._client.format_url(request.url, **path_format_arguments)
pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
response = pipeline_response.http_response
if response.status_code not in [200, 404]:
map_error(status_code=response.status_code, response=response, error_map=error_map)
raise HttpResponseError(response=response)
if cls:
return cls(pipeline_response, None, {})
group_exists.metadata = {'url': '/api/hubs/{hub}/groups/{group}'} # type: ignore
[docs] @distributed_trace_async
async def close_group_connections(
self,
hub: str,
group: str,
*,
excluded: Optional[List[str]] = None,
reason: Optional[str] = None,
**kwargs: Any
) -> None:
"""Close connections in the specific group.
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.
:paramtype excluded: list[str]
:keyword reason: The reason closing the client connection.
:paramtype reason: str
:return: None
:rtype: None
:raises: ~azure.core.exceptions.HttpResponseError
"""
cls = kwargs.pop('cls', None) # type: ClsType[None]
error_map = {
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
}
error_map.update(kwargs.pop('error_map', {}))
request = build_close_group_connections_request(
hub=hub,
group=group,
excluded=excluded,
reason=reason,
template_url=self.close_group_connections.metadata['url'],
)
path_format_arguments = {
"Endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True),
}
request.url = self._client.format_url(request.url, **path_format_arguments)
pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
response = pipeline_response.http_response
if response.status_code not in [204]:
map_error(status_code=response.status_code, response=response, error_map=error_map)
raise HttpResponseError(response=response)
if cls:
return cls(pipeline_response, None, {})
close_group_connections.metadata = {'url': '/api/hubs/{hub}/groups/{group}/:closeConnections'} # type: ignore
[docs] @distributed_trace_async
async def send_to_group(
self,
hub: str,
group: str,
message: Union[IO, str],
*,
excluded: Optional[List[str]] = None,
**kwargs: Any
) -> None:
"""Send content inside request body to a group of connections.
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.
:type message: IO or str
:keyword excluded: Excluded connection Ids.
:paramtype excluded: list[str]
:keyword str content_type: Media type of the body sent to the API. Default value is
"application/json". Allowed values are: "application/json", "application/octet-stream",
"text/plain."
:return: None
:rtype: None
:raises: ~azure.core.exceptions.HttpResponseError
"""
cls = kwargs.pop('cls', None) # type: ClsType[None]
error_map = {
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
}
error_map.update(kwargs.pop('error_map', {}))
content_type = kwargs.pop('content_type', "text/plain") # type: Optional[str]
json = None
content = None
if content_type.split(";")[0] in ['application/json', 'application/octet-stream']:
content = message
elif content_type.split(";")[0] in ['text/plain']:
json = message
else:
raise ValueError(
"The content_type '{}' is not one of the allowed values: "
"['application/json', 'application/octet-stream', 'text/plain']".format(content_type)
)
request = build_send_to_group_request(
hub=hub,
group=group,
content_type=content_type,
excluded=excluded,
json=json,
content=content,
template_url=self.send_to_group.metadata['url'],
)
path_format_arguments = {
"Endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True),
}
request.url = self._client.format_url(request.url, **path_format_arguments)
pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
response = pipeline_response.http_response
if response.status_code not in [202]:
map_error(status_code=response.status_code, response=response, error_map=error_map)
raise HttpResponseError(response=response)
if cls:
return cls(pipeline_response, None, {})
send_to_group.metadata = {'url': '/api/hubs/{hub}/groups/{group}/:send'} # type: ignore
[docs] @distributed_trace_async
async def add_connection_to_group(
self,
hub: str,
group: str,
connection_id: str,
**kwargs: Any
) -> None:
"""Add a connection to the target 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.
:type connection_id: str
:return: None
:rtype: None
:raises: ~azure.core.exceptions.HttpResponseError
"""
cls = kwargs.pop('cls', None) # type: ClsType[None]
error_map = {
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
}
error_map.update(kwargs.pop('error_map', {}))
request = build_add_connection_to_group_request(
hub=hub,
group=group,
connection_id=connection_id,
template_url=self.add_connection_to_group.metadata['url'],
)
path_format_arguments = {
"Endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True),
}
request.url = self._client.format_url(request.url, **path_format_arguments)
pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
response = pipeline_response.http_response
if response.status_code not in [200, 404]:
map_error(status_code=response.status_code, response=response, error_map=error_map)
raise HttpResponseError(response=response)
if cls:
return cls(pipeline_response, None, {})
add_connection_to_group.metadata = {'url': '/api/hubs/{hub}/groups/{group}/connections/{connectionId}'} # type: ignore
[docs] @distributed_trace_async
async def remove_connection_from_group(
self,
hub: str,
group: str,
connection_id: str,
**kwargs: Any
) -> None:
"""Remove a connection from the target 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.
:type connection_id: str
:return: None
:rtype: None
:raises: ~azure.core.exceptions.HttpResponseError
"""
cls = kwargs.pop('cls', None) # type: ClsType[None]
error_map = {
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
}
error_map.update(kwargs.pop('error_map', {}))
request = build_remove_connection_from_group_request(
hub=hub,
group=group,
connection_id=connection_id,
template_url=self.remove_connection_from_group.metadata['url'],
)
path_format_arguments = {
"Endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True),
}
request.url = self._client.format_url(request.url, **path_format_arguments)
pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
response = pipeline_response.http_response
if response.status_code not in [204]:
map_error(status_code=response.status_code, response=response, error_map=error_map)
raise HttpResponseError(response=response)
if cls:
return cls(pipeline_response, None, {})
remove_connection_from_group.metadata = {'url': '/api/hubs/{hub}/groups/{group}/connections/{connectionId}'} # type: ignore
[docs] @distributed_trace_async
async def user_exists(
self,
hub: str,
user_id: str,
**kwargs: Any
) -> None:
"""Check if there are any client connections connected for the given user.
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
:return: None
:rtype: None
:raises: ~azure.core.exceptions.HttpResponseError
"""
cls = kwargs.pop('cls', None) # type: ClsType[None]
error_map = {
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
}
error_map.update(kwargs.pop('error_map', {}))
request = build_user_exists_request(
hub=hub,
user_id=user_id,
template_url=self.user_exists.metadata['url'],
)
path_format_arguments = {
"Endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True),
}
request.url = self._client.format_url(request.url, **path_format_arguments)
pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
response = pipeline_response.http_response
if response.status_code not in [200, 404]:
map_error(status_code=response.status_code, response=response, error_map=error_map)
raise HttpResponseError(response=response)
if cls:
return cls(pipeline_response, None, {})
user_exists.metadata = {'url': '/api/hubs/{hub}/users/{userId}'} # type: ignore
[docs] @distributed_trace_async
async def close_user_connections(
self,
hub: str,
user_id: str,
*,
excluded: Optional[List[str]] = None,
reason: Optional[str] = None,
**kwargs: Any
) -> None:
"""Close connections for the specific user.
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.
:paramtype excluded: list[str]
:keyword reason: The reason closing the client connection.
:paramtype reason: str
:return: None
:rtype: None
:raises: ~azure.core.exceptions.HttpResponseError
"""
cls = kwargs.pop('cls', None) # type: ClsType[None]
error_map = {
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
}
error_map.update(kwargs.pop('error_map', {}))
request = build_close_user_connections_request(
hub=hub,
user_id=user_id,
excluded=excluded,
reason=reason,
template_url=self.close_user_connections.metadata['url'],
)
path_format_arguments = {
"Endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True),
}
request.url = self._client.format_url(request.url, **path_format_arguments)
pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
response = pipeline_response.http_response
if response.status_code not in [204]:
map_error(status_code=response.status_code, response=response, error_map=error_map)
raise HttpResponseError(response=response)
if cls:
return cls(pipeline_response, None, {})
close_user_connections.metadata = {'url': '/api/hubs/{hub}/users/{userId}/:closeConnections'} # type: ignore
[docs] @distributed_trace_async
async def send_to_user(
self,
hub: str,
user_id: str,
message: Union[IO, str],
**kwargs: Any
) -> None:
"""Send content inside request body to the specific 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.
:type message: IO or str
:keyword str content_type: Media type of the body sent to the API. Default value is
"application/json". Allowed values are: "application/json", "application/octet-stream",
"text/plain."
:return: None
:rtype: None
:raises: ~azure.core.exceptions.HttpResponseError
"""
cls = kwargs.pop('cls', None) # type: ClsType[None]
error_map = {
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
}
error_map.update(kwargs.pop('error_map', {}))
content_type = kwargs.pop('content_type', "text/plain") # type: Optional[str]
json = None
content = None
if content_type.split(";")[0] in ['application/json', 'application/octet-stream']:
content = message
elif content_type.split(";")[0] in ['text/plain']:
json = message
else:
raise ValueError(
"The content_type '{}' is not one of the allowed values: "
"['application/json', 'application/octet-stream', 'text/plain']".format(content_type)
)
request = build_send_to_user_request(
hub=hub,
user_id=user_id,
content_type=content_type,
json=json,
content=content,
template_url=self.send_to_user.metadata['url'],
)
path_format_arguments = {
"Endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True),
}
request.url = self._client.format_url(request.url, **path_format_arguments)
pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
response = pipeline_response.http_response
if response.status_code not in [202]:
map_error(status_code=response.status_code, response=response, error_map=error_map)
raise HttpResponseError(response=response)
if cls:
return cls(pipeline_response, None, {})
send_to_user.metadata = {'url': '/api/hubs/{hub}/users/{userId}/:send'} # type: ignore
[docs] @distributed_trace_async
async def add_user_to_group(
self,
hub: str,
group: str,
user_id: str,
**kwargs: Any
) -> None:
"""Add a user to the target 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.
:type user_id: str
:return: None
:rtype: None
:raises: ~azure.core.exceptions.HttpResponseError
"""
cls = kwargs.pop('cls', None) # type: ClsType[None]
error_map = {
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
}
error_map.update(kwargs.pop('error_map', {}))
request = build_add_user_to_group_request(
hub=hub,
group=group,
user_id=user_id,
template_url=self.add_user_to_group.metadata['url'],
)
path_format_arguments = {
"Endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True),
}
request.url = self._client.format_url(request.url, **path_format_arguments)
pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
response = pipeline_response.http_response
if response.status_code not in [200, 404]:
map_error(status_code=response.status_code, response=response, error_map=error_map)
raise HttpResponseError(response=response)
if cls:
return cls(pipeline_response, None, {})
add_user_to_group.metadata = {'url': '/api/hubs/{hub}/users/{userId}/groups/{group}'} # type: ignore
[docs] @distributed_trace_async
async def remove_user_from_group(
self,
hub: str,
group: str,
user_id: str,
**kwargs: Any
) -> None:
"""Remove a user from the target 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.
:type user_id: str
:return: None
:rtype: None
:raises: ~azure.core.exceptions.HttpResponseError
"""
cls = kwargs.pop('cls', None) # type: ClsType[None]
error_map = {
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
}
error_map.update(kwargs.pop('error_map', {}))
request = build_remove_user_from_group_request(
hub=hub,
group=group,
user_id=user_id,
template_url=self.remove_user_from_group.metadata['url'],
)
path_format_arguments = {
"Endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True),
}
request.url = self._client.format_url(request.url, **path_format_arguments)
pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
response = pipeline_response.http_response
if response.status_code not in [204]:
map_error(status_code=response.status_code, response=response, error_map=error_map)
raise HttpResponseError(response=response)
if cls:
return cls(pipeline_response, None, {})
remove_user_from_group.metadata = {'url': '/api/hubs/{hub}/users/{userId}/groups/{group}'} # type: ignore
[docs] @distributed_trace_async
async def remove_user_from_all_groups(
self,
hub: str,
user_id: str,
**kwargs: Any
) -> None:
"""Remove a 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
:return: None
:rtype: None
:raises: ~azure.core.exceptions.HttpResponseError
"""
cls = kwargs.pop('cls', None) # type: ClsType[None]
error_map = {
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
}
error_map.update(kwargs.pop('error_map', {}))
request = build_remove_user_from_all_groups_request(
hub=hub,
user_id=user_id,
template_url=self.remove_user_from_all_groups.metadata['url'],
)
path_format_arguments = {
"Endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True),
}
request.url = self._client.format_url(request.url, **path_format_arguments)
pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
response = pipeline_response.http_response
if response.status_code not in [204]:
map_error(status_code=response.status_code, response=response, error_map=error_map)
raise HttpResponseError(response=response)
if cls:
return cls(pipeline_response, None, {})
remove_user_from_all_groups.metadata = {'url': '/api/hubs/{hub}/users/{userId}/groups'} # type: ignore
[docs] @distributed_trace_async
async def grant_permission(
self,
hub: str,
permission: str,
connection_id: str,
*,
target_name: Optional[str] = None,
**kwargs: Any
) -> None:
"""Grant permission to the connection.
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
:param connection_id: Target connection Id.
:type connection_id: str
:keyword target_name: The meaning of the target depends on the specific permission. For
joinLeaveGroup and sendToGroup, targetName is a required parameter standing for the group name.
:paramtype target_name: str
:return: None
:rtype: None
:raises: ~azure.core.exceptions.HttpResponseError
"""
cls = kwargs.pop('cls', None) # type: ClsType[None]
error_map = {
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
}
error_map.update(kwargs.pop('error_map', {}))
request = build_grant_permission_request(
hub=hub,
permission=permission,
connection_id=connection_id,
target_name=target_name,
template_url=self.grant_permission.metadata['url'],
)
path_format_arguments = {
"Endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True),
}
request.url = self._client.format_url(request.url, **path_format_arguments)
pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
response = pipeline_response.http_response
if response.status_code not in [200]:
map_error(status_code=response.status_code, response=response, error_map=error_map)
raise HttpResponseError(response=response)
if cls:
return cls(pipeline_response, None, {})
grant_permission.metadata = {'url': '/api/hubs/{hub}/permissions/{permission}/connections/{connectionId}'} # type: ignore
[docs] @distributed_trace_async
async def revoke_permission(
self,
hub: str,
permission: str,
connection_id: str,
*,
target_name: Optional[str] = None,
**kwargs: Any
) -> None:
"""Revoke permission for the connection.
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
:param connection_id: Target connection Id.
:type connection_id: str
:keyword target_name: The meaning of the target depends on the specific permission. For
joinLeaveGroup and sendToGroup, targetName is a required parameter standing for the group name.
:paramtype target_name: str
:return: None
:rtype: None
:raises: ~azure.core.exceptions.HttpResponseError
"""
cls = kwargs.pop('cls', None) # type: ClsType[None]
error_map = {
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
}
error_map.update(kwargs.pop('error_map', {}))
request = build_revoke_permission_request(
hub=hub,
permission=permission,
connection_id=connection_id,
target_name=target_name,
template_url=self.revoke_permission.metadata['url'],
)
path_format_arguments = {
"Endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True),
}
request.url = self._client.format_url(request.url, **path_format_arguments)
pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
response = pipeline_response.http_response
if response.status_code not in [204]:
map_error(status_code=response.status_code, response=response, error_map=error_map)
raise HttpResponseError(response=response)
if cls:
return cls(pipeline_response, None, {})
revoke_permission.metadata = {'url': '/api/hubs/{hub}/permissions/{permission}/connections/{connectionId}'} # type: ignore
[docs] @distributed_trace_async
async def check_permission(
self,
hub: str,
permission: str,
connection_id: str,
*,
target_name: Optional[str] = None,
**kwargs: Any
) -> None:
"""Check if a connection has permission to the specified action.
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
:param connection_id: Target connection Id.
:type connection_id: str
:keyword target_name: The meaning of the target depends on the specific permission. For
joinLeaveGroup and sendToGroup, targetName is a required parameter standing for the group name.
:paramtype target_name: str
:return: None
:rtype: None
:raises: ~azure.core.exceptions.HttpResponseError
"""
cls = kwargs.pop('cls', None) # type: ClsType[None]
error_map = {
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
}
error_map.update(kwargs.pop('error_map', {}))
request = build_check_permission_request(
hub=hub,
permission=permission,
connection_id=connection_id,
target_name=target_name,
template_url=self.check_permission.metadata['url'],
)
path_format_arguments = {
"Endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True),
}
request.url = self._client.format_url(request.url, **path_format_arguments)
pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
response = pipeline_response.http_response
if response.status_code not in [200, 404]:
map_error(status_code=response.status_code, response=response, error_map=error_map)
raise HttpResponseError(response=response)
if cls:
return cls(pipeline_response, None, {})
check_permission.metadata = {'url': '/api/hubs/{hub}/permissions/{permission}/connections/{connectionId}'} # type: ignore