Skip to content

Commit 75d8d23

Browse files
authored
Merge branch 'sb_control_client' into kibrantn/servicebus/track2-control-client-queue-create-tests
2 parents 8a657e7 + 5674fa5 commit 75d8d23

File tree

3 files changed

+88
-27
lines changed

3 files changed

+88
-27
lines changed

sdk/servicebus/azure-servicebus/azure/servicebus/management/_management_client.py

+64-17
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,14 @@ def _handle_response_error():
3434
try:
3535
yield
3636
except HttpResponseError as response_error:
37-
new_response_error = HttpResponseError(
38-
message=response_error.model.detail,
39-
response=response_error.response,
40-
model=response_error.model
41-
)
37+
try:
38+
new_response_error = HttpResponseError(
39+
message=response_error.model.detail,
40+
response=response_error.response,
41+
model=response_error.model
42+
)
43+
except AttributeError:
44+
new_response_error = response_error
4245
raise new_response_error
4346

4447

@@ -54,13 +57,20 @@ def _convert_xml_to_object(queue_name, et, class_):
5457

5558

5659
class ServiceBusManagementClient:
60+
"""Use this client to create, update, list, and delete resources of a ServiceBus namespace
61+
62+
:param str fully_qualified_namespace:
63+
:param credential:
64+
:type credential: Union[TokenCredential, ServiceBusSharedKeyCredential]
65+
:keyword Pipeline pipeline: If omitted, the standard pipeline is used.
66+
:keyword HttpTransport transport: If omitted, the standard pipeline is used.
67+
:keyword List[HTTPPolicy] policies: If omitted, the standard pipeline is used.
68+
69+
For keyword arguments, refer to TODO: add a link here
70+
"""
5771

5872
def __init__(self, fully_qualified_namespace, credential, **kwargs):
5973
# type: (str, Union[TokenCredential, ServiceBusSharedKeyCredential], Dict[str, Any]) -> None
60-
"""
61-
:param fully_qualified_namespace:
62-
:param kwargs:
63-
"""
6474
self.fully_qualified_namespace = fully_qualified_namespace
6575
self._credential = credential
6676
self._endpoint = "https://" + fully_qualified_namespace
@@ -93,12 +103,14 @@ def _build_pipeline(self, **kwargs): # pylint: disable=no-self-use
93103
return Pipeline(transport, policies)
94104

95105
@classmethod
96-
def from_connection_string(cls, connection_string):
97-
# type: (str) -> ServiceBusManagementClient
98-
"""
106+
def from_connection_string(cls, connection_string, **kwargs):
107+
# type: (str, Any) -> ServiceBusManagementClient
108+
"""Create a client from connection string
99109
100110
:param str connection_string:
101-
:return:
111+
:keyword Pipeline pipeline: If omitted, the standard pipeline is used.
112+
:keyword HttpTransport transport: If omitted, the standard pipeline is used.
113+
:keyword List[HTTPPolicy] policies: If omitted, the standard pipeline is used.
102114
"""
103115
endpoint, shared_access_key_name, shared_access_key, _ = parse_conn_str(connection_string)
104116
if "//" in endpoint:
@@ -141,16 +153,30 @@ def _list_queues(self, skip, max_count, class_):
141153

142154
def get_queue(self, queue_name):
143155
# type: (str) -> QueueDescription
156+
"""Get a QueueDescription
157+
158+
:param str queue_name: The name of the queue
159+
"""
144160
return self._get_queue_object(queue_name, QueueDescription)
145161

146162
def get_queue_runtime_info(self, queue_name):
147163
# type: (str) -> QueueRuntimeInfo
164+
"""Get the runtime information of a queue
165+
166+
:param str queue_name: The name of the queue
167+
"""
148168
return self._get_queue_object(queue_name, QueueRuntimeInfo)
149169

150170
def create_queue(self, queue):
151171
# type: (Union[str, QueueDescription]) -> QueueDescription
152-
"""Create a queue"""
153-
172+
"""Create a queue
173+
174+
:param queue: The queue name or a `QueueDescription` instance. When it's a str, it will be the name
175+
of the created queue. Other properties of the created queue will have default values decided by the
176+
ServiceBus. Use a `QueueDesceiption` if you want to set queue properties other than the queue name.
177+
:type queue: Union[str, QueueDescription].
178+
:returns: `QueueDescription` returned from ServiceBus.
179+
"""
154180
queue_name = None
155181
try:
156182
queue_name = queue.queue_name # type: ignore
@@ -182,7 +208,13 @@ def create_queue(self, queue):
182208

183209
def update_queue(self, queue_description):
184210
# type: (QueueDescription) -> QueueDescription
185-
"""Update a queue"""
211+
"""
212+
213+
:param queue_description: The properties of this `QueueDescription` will be applied to the queue in
214+
ServiceBus. Only a portion of properties can be updated.
215+
Refer to https://docs.microsoft.com/en-us/rest/api/servicebus/update-queue.
216+
:type queue_description: QueueDescription
217+
"""
186218
if not queue_description.queue_name:
187219
raise ValueError("queue_description must have a non-empty queue_name")
188220

@@ -208,7 +240,10 @@ def update_queue(self, queue_description):
208240

209241
def delete_queue(self, queue_name):
210242
# type: (str) -> None
211-
"""Create a queue"""
243+
"""Delete a queue
244+
245+
:param str queue_name: The name of the queue
246+
"""
212247

213248
if not queue_name:
214249
raise ValueError("queue_name must not be None or empty")
@@ -217,8 +252,20 @@ def delete_queue(self, queue_name):
217252

218253
def list_queues(self, skip=0, max_count=100):
219254
# type: (int, int) -> List[QueueDescription]
255+
"""List the queues of a ServiceBus namespace
256+
257+
:param int skip: skip this number of queues
258+
:param int max_count: return at most this number of queues if there are more than this number in
259+
the ServiceBus namespace
260+
"""
220261
return self._list_queues(skip, max_count, QueueDescription)
221262

222263
def list_queues_runtime_info(self, skip=0, max_count=100):
223264
# type: (int, int) -> List[QueueRuntimeInfo]
265+
"""List the queues runtime info of a ServiceBus namespace
266+
267+
:param int skip: skip this number of queues
268+
:param int max_count: return at most this number of queues if there are more than this number in
269+
the ServiceBus namespace
270+
"""
224271
return self._list_queues(skip, max_count, QueueRuntimeInfo)

sdk/servicebus/azure-servicebus/azure/servicebus/management/_shared_key_policy.py

+13
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,18 @@
55

66
import time
77
import six
8+
from azure.core.pipeline import PipelineRequest
89
from azure.core.pipeline.policies import SansIOHTTPPolicy
910
from .._base_handler import ServiceBusSharedKeyCredential
1011

1112

1213
class ServiceBusSharedKeyCredentialPolicy(SansIOHTTPPolicy):
14+
"""A policy that put token generated by ServiceBusSharedKeyCredential into HTTP request header
15+
16+
:param str endpoint:
17+
:param ServiceBusSharedKeyCredential credential:
18+
:param str name:
19+
"""
1320
def __init__(self, endpoint, credential, name):
1421
# type: (str, ServiceBusSharedKeyCredential, str) -> None
1522
super(ServiceBusSharedKeyCredentialPolicy, self).__init__()
@@ -29,5 +36,11 @@ def _update_token(self):
2936
self._token = access_token.decode("utf-8")
3037

3138
def on_request(self, request):
39+
# type: (PipelineRequest) -> None
40+
"""Adds an Authorization header to request and sends request to next policy.
41+
42+
:param request: The pipeline request object
43+
:type request: ~azure.core.pipeline.PipelineRequest
44+
"""
3245
self._update_token()
3346
request.http_request.headers[self._name] = self._token

sdk/servicebus/azure-servicebus/azure/servicebus/management/aio/_management_client_async.py

+11-10
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ async def _get_queue_object(self, queue_name, clazz):
9595
return _convert_xml_to_object(queue_name, et, clazz)
9696

9797
async def _list_queues(self, skip, max_count, clazz):
98-
# type: (int, int, Type[Model]) -> Union[List[QueueDescription], List[QueueRuntimeInfo])
98+
# type: (int, int, Type[Model]) -> Union[List[QueueDescription], List[QueueRuntimeInfo]]
9999
with _handle_response_error():
100100
et = cast(
101101
ElementTree,
@@ -126,18 +126,19 @@ async def get_queue_runtime_info(self, queue_name):
126126
async def create_queue(self, queue):
127127
# type: (Union[str, QueueDescription]) -> QueueDescription
128128
"""Create a queue"""
129-
if not queue or not queue.queue_name: # type: ignore
130-
raise ValueError("queue must be a non-empty str or a QueueDescription with non-empty queue_name")
131-
if isinstance(queue, str):
129+
try: # queue is a QueueDescription
130+
queue_name = queue.queue_name
131+
to_create = copy(queue)
132+
to_create.queue_name = None
133+
except AttributeError: # str expected. But if not str, it might work and might not work.
132134
queue_name = queue
133-
queue_description = QueueDescription()
134-
else:
135-
queue_name = queue.queue_name # type: ignore
136-
queue_description = copy(queue)
137-
queue_description.queue_name = None
135+
to_create = QueueDescription()
136+
if queue_name is None:
137+
raise ValueError("queue should be a non-empty str or a QueueDescription with non-empty queue_name")
138+
138139
create_entity_body = CreateQueueBody(
139140
content=CreateQueueBodyContent(
140-
queue_description=queue_description,
141+
queue_description=to_create,
141142
)
142143
)
143144
request_body = create_entity_body.serialize(is_xml=True)

0 commit comments

Comments
 (0)