Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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,7 +10,6 @@
from datetime import timedelta

from azure.core.async_paging import AsyncItemPaged
from azure.servicebus.aio.management._utils import extract_data_template, get_next_template
from azure.core.exceptions import ResourceNotFoundError
from azure.core.pipeline import AsyncPipeline
from azure.core.pipeline.policies import HttpLoggingPolicy, DistributedTracingPolicy, ContentDecodePolicy, \
Expand Down Expand Up @@ -39,6 +38,8 @@
from ...management._xml_workaround_policy import ServiceBusXMLWorkaroundPolicy
from ...management._handle_response_error import _handle_response_error
from ...management._model_workaround import avoid_timedelta_overflow
from ._utils import extract_data_template, extract_rule_data_template, get_next_template
from ...management._utils import deserialize_rule_key_values, serialize_rule_key_values


if TYPE_CHECKING:
Expand Down Expand Up @@ -692,6 +693,7 @@ async def get_rule(
"Rule('Topic: {}, Subscription: {}, Rule {}') does not exist".format(
subscription_name, topic_name, rule_name))
rule_description = RuleDescription._from_internal_entity(rule_name, entry.content.rule_description)
deserialize_rule_key_values(entry_ele, rule_description) # to remove after #3535 is released.
return rule_description

async def create_rule(
Expand Down Expand Up @@ -724,14 +726,16 @@ async def create_rule(
)
)
request_body = create_entity_body.serialize(is_xml=True)
serialize_rule_key_values(request_body, rule)
with _handle_response_error():
entry_ele = await self._impl.rule.put(
topic_name,
subscription_name, # type: ignore
rule_name,
request_body, api_version=constants.API_VERSION, **kwargs)
entry = RuleDescriptionEntry.deserialize(entry_ele)
result = entry.content.rule_description
result = RuleDescription._from_internal_entity(rule_name, entry.content.rule_description)
deserialize_rule_key_values(entry_ele, result) # to remove after #3535 is released.
return result

async def update_rule(
Expand Down Expand Up @@ -767,6 +771,7 @@ async def update_rule(
)
)
request_body = create_entity_body.serialize(is_xml=True)
serialize_rule_key_values(request_body, rule)
Comment thread
KieranBrantnerMagee marked this conversation as resolved.
with _handle_response_error():
await self._impl.rule.put(
topic_name,
Expand Down Expand Up @@ -824,12 +829,17 @@ def list_rules(
except AttributeError:
subscription_name = subscription

def entry_to_rule(entry):
def entry_to_rule(ele, entry):
Comment thread
KieranBrantnerMagee marked this conversation as resolved.
"""
`ele` will be removed after #3535 is released.
"""
rule = entry.content.rule_description
return RuleDescription._from_internal_entity(entry.title, rule)
rule_description = RuleDescription._from_internal_entity(entry.title, rule)
deserialize_rule_key_values(ele, rule_description) # to remove after #3535 is released.
return rule_description

extract_data = functools.partial(
extract_data_template, RuleDescriptionFeed, entry_to_rule
extract_rule_data_template, RuleDescriptionFeed, entry_to_rule
)
get_next = functools.partial(
get_next_template, functools.partial(self._impl.list_rules, topic_name, subscription_name), **kwargs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,29 @@ async def extract_data_template(feed_class, convert, feed_element):
return next_link, iter(list_of_qd) # when next_page is None, AsyncPagedItem will stop fetch next page data.


async def extract_rule_data_template(feed_class, convert, feed_element):
"""Special version of function extrat_data_template for Rule.

Pass both the XML entry element and the rule instance to function `convert`. Rule needs to extract
KeyValue from XML Element and set to Rule model instance manually. The autorest/msrest serialization/deserialization
doesn't work for this special part.
After autorest is enhanced, this method can be removed.
Refer to autorest issue https://github.com/Azure/autorest/issues/3535
"""
deserialized = feed_class.deserialize(feed_element)
next_link = None
if deserialized.link and len(deserialized.link) == 2:
next_link = deserialized.link[1].href
if deserialized.entry:
list_of_entities = [
convert(*x) if convert else x for x in zip(feed_element.findall(
constants.ATOM_ENTRY_TAG), deserialized.entry)
]
else:
list_of_entities = []
return next_link, iter(list_of_entities)


async def get_next_template(list_func, *args, start_index=0, max_page_size=100, **kwargs):
"""Call list_func to get the XML data and deserialize it to XML ElementTree.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,37 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

# Generated API parameters
API_VERSION_PARAM_NAME = "api-version"
API_VERSION = "2017-04"
ENTRY_TAG = "{http://www.w3.org/2005/Atom}entry"
CONTENT_TAG = "{http://www.w3.org/2005/Atom}content"
QUEUE_DESCRIPTION_TAG = "{http://schemas.microsoft.com/netservices/2010/10/servicebus/connect}QueueDescription"
COUNT_DETAILS_TAG = "{http://schemas.microsoft.com/netservices/2010/10/servicebus/connect}CountDetails"
TITLE_TAG = "{http://www.w3.org/2005/Atom}title"

ENTITY_TYPE_QUEUES = "queues"
ENTITY_TYPE_TOPICS = "topics"

LIST_OP_SKIP = "$skip"
LIST_OP_TOP = "$top"

# XML namespace and tags
XML_SCHEMA_NAMESPACE = "http://www.w3.org/2001/XMLSchema"
XML_SCHEMA_INSTANCE_NAMESPACE = "http://www.w3.org/2001/XMLSchema-instance"
ATOM_ENTRY_TAG = "{http://www.w3.org/2005/Atom}entry"
ATOM_CONTENT_TAG = "{http://www.w3.org/2005/Atom}content"

# ServiceBus XML namespace
SB_XML_NAMESPACE = "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect"

# Rule XML tags
RULE_KEY_VALUE = "KeyValueOfstringanyType"
RULE_KEY = "Key"
RULE_VALUE = "Value"
RULE_VALUE_TYPE = "type"
RULE_VALUE_TYPE_XML_PREFIX = "d6p1"
RULE_SQL_COMPATIBILITY_LEVEL = "20"
RULE_DESCRIPTION_TAG = "{http://schemas.microsoft.com/netservices/2010/10/servicebus/connect}RuleDescription"
RULE_FILTER_TAG = "{http://schemas.microsoft.com/netservices/2010/10/servicebus/connect}Filter"
RULE_FILTER_COR_PROPERTIES_TAG = "{http://schemas.microsoft.com/netservices/2010/10/servicebus/connect}Properties"
RULE_PARAMETERS_TAG = "{http://schemas.microsoft.com/netservices/2010/10/servicebus/connect}Parameters"
RULE_ACTION_TAG = "{http://schemas.microsoft.com/netservices/2010/10/servicebus/connect}Action"
RULE_KEY_VALUE_TAG = "{{{}}}{}".format(SB_XML_NAMESPACE, RULE_KEY_VALUE)
RULE_KEY_TAG = "{{{}}}{}".format(SB_XML_NAMESPACE, RULE_KEY)
RULE_VALUE_TAG = "{{{}}}{}".format(SB_XML_NAMESPACE, RULE_VALUE)
RULE_VALUE_TYPE_TAG = "{{{}}}{}".format(XML_SCHEMA_INSTANCE_NAMESPACE, RULE_VALUE_TYPE)
INT32_MAX_VALUE = 2147483647 # int32 max value used to tell if a Python int is an int32 or long in other languages
Loading