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

[ServiceBus] validate iso8601 duration format in mgmt module #18044

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
1 change: 1 addition & 0 deletions sdk/servicebus/azure-servicebus/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 7.1.2 (Unreleased)



## 7.1.1 (2021-04-07)

This version and all future versions will require Python 2.7 or Python 3.6+, Python 3.5 is no longer supported.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,17 +296,20 @@ async def create_queue(self, queue_name: str, **kwargs) -> QueueProperties:
:type authorization_rules: list[~azure.servicebus.management.AuthorizationRule]
:keyword auto_delete_on_idle: ISO 8601 timeSpan idle interval after which the queue is
automatically deleted. The minimum duration is 5 minutes.
:type auto_delete_on_idle: ~datetime.timedelta
Input value of either type ~datetime.timedelta or string in ISO 8601 duration format like "PT300S" is accepted.
:type auto_delete_on_idle: Union[~datetime.timedelta, str]
:keyword dead_lettering_on_message_expiration: A value that indicates whether this queue has dead
letter support when a message expires.
:type dead_lettering_on_message_expiration: bool
:keyword default_message_time_to_live: ISO 8601 default message timespan to live value. This is
the duration after which the message expires, starting from when the message is sent to Service
Bus. This is the default value used when TimeToLive is not set on a message itself.
:type default_message_time_to_live: ~datetime.timedelta
Input value of either type ~datetime.timedelta or string in ISO 8601 duration format like "PT300S" is accepted.
:type default_message_time_to_live: Union[~datetime.timedelta, str]
:keyword duplicate_detection_history_time_window: ISO 8601 timeSpan structure that defines the
duration of the duplicate detection history. The default value is 10 minutes.
:type duplicate_detection_history_time_window: ~datetime.timedelta
Input value of either type ~datetime.timedelta or string in ISO 8601 duration format like "PT300S" is accepted.
:type duplicate_detection_history_time_window: Union[~datetime.timedelta, str]
:keyword enable_batched_operations: Value that indicates whether server-side batched operations
are enabled.
:type enable_batched_operations: bool
Expand All @@ -319,7 +322,8 @@ async def create_queue(self, queue_name: str, **kwargs) -> QueueProperties:
:keyword lock_duration: ISO 8601 timespan duration of a peek-lock; that is, the amount of time
that the message is locked for other receivers. The maximum value for LockDuration is 5
minutes; the default value is 1 minute.
:type lock_duration: ~datetime.timedelta
Input value of either type ~datetime.timedelta or string in ISO 8601 duration format like "PT300S" is accepted.
:type lock_duration: Union[~datetime.timedelta, str]
:keyword max_delivery_count: The maximum delivery count. A message is automatically deadlettered
after this number of deliveries. Default value is 10.
:type max_delivery_count: int
Expand Down Expand Up @@ -561,7 +565,8 @@ async def create_topic(self, topic_name: str, **kwargs) -> TopicProperties:
:keyword default_message_time_to_live: ISO 8601 default message timespan to live value. This is
the duration after which the message expires, starting from when the message is sent to Service
Bus. This is the default value used when TimeToLive is not set on a message itself.
:type default_message_time_to_live: ~datetime.timedelta
Input value of either type ~datetime.timedelta or string in ISO 8601 duration format like "PT300S" is accepted.
:type default_message_time_to_live: Union[~datetime.timedelta, str]
:keyword max_size_in_megabytes: The maximum size of the topic in megabytes, which is the size of
memory allocated for the topic.
:type max_size_in_megabytes: long
Expand All @@ -570,7 +575,8 @@ async def create_topic(self, topic_name: str, **kwargs) -> TopicProperties:
:type requires_duplicate_detection: bool
:keyword duplicate_detection_history_time_window: ISO 8601 timeSpan structure that defines the
duration of the duplicate detection history. The default value is 10 minutes.
:type duplicate_detection_history_time_window: ~datetime.timedelta
Input value of either type ~datetime.timedelta or string in ISO 8601 duration format like "PT300S" is accepted.
:type duplicate_detection_history_time_window: Union[~datetime.timedelta, str]
:keyword enable_batched_operations: Value that indicates whether server-side batched operations
are enabled.
:type enable_batched_operations: bool
Expand All @@ -585,7 +591,8 @@ async def create_topic(self, topic_name: str, **kwargs) -> TopicProperties:
:type support_ordering: bool
:keyword auto_delete_on_idle: ISO 8601 timeSpan idle interval after which the topic is
automatically deleted. The minimum duration is 5 minutes.
:type auto_delete_on_idle: ~datetime.timedelta
Input value of either type ~datetime.timedelta or string in ISO 8601 duration format like "PT300S" is accepted.
:type auto_delete_on_idle: Union[~datetime.timedelta, str]
:keyword enable_partitioning: A value that indicates whether the topic is to be partitioned
across multiple message brokers.
:type enable_partitioning: bool
Expand Down Expand Up @@ -663,10 +670,10 @@ async def update_topic(
topic = create_properties_from_dict_if_needed(topic, TopicProperties)
to_update = topic._to_internal_entity()

to_update.default_message_time_to_live = avoid_timedelta_overflow(
to_update.default_message_time_to_live = avoid_timedelta_overflow( # type: ignore
to_update.default_message_time_to_live
)
to_update.auto_delete_on_idle = avoid_timedelta_overflow(
to_update.auto_delete_on_idle = avoid_timedelta_overflow( # type: ignore
to_update.auto_delete_on_idle
)

Expand Down Expand Up @@ -805,14 +812,16 @@ async def create_subscription(
:keyword lock_duration: ISO 8601 timespan duration of a peek-lock; that is, the amount of time
that the message is locked for other receivers. The maximum value for LockDuration is 5
minutes; the default value is 1 minute.
:type lock_duration: ~datetime.timedelta
Input value of either type ~datetime.timedelta or string in ISO 8601 duration format like "PT300S" is accepted.
:type lock_duration: Union[~datetime.timedelta, str]
:keyword requires_session: A value that indicates whether the queue supports the concept of
sessions.
:type requires_session: bool
:keyword default_message_time_to_live: ISO 8601 default message timespan to live value. This is
the duration after which the message expires, starting from when the message is sent to Service
Bus. This is the default value used when TimeToLive is not set on a message itself.
:type default_message_time_to_live: ~datetime.timedelta
Input value of either type ~datetime.timedelta or string in ISO 8601 duration format like "PT300S" is accepted.
:type default_message_time_to_live: Union[~datetime.timedelta, str]
:keyword dead_lettering_on_message_expiration: A value that indicates whether this subscription
has dead letter support when a message expires.
:type dead_lettering_on_message_expiration: bool
Expand All @@ -836,7 +845,8 @@ async def create_subscription(
:type forward_dead_lettered_messages_to: str
:keyword auto_delete_on_idle: ISO 8601 timeSpan idle interval after which the subscription is
automatically deleted. The minimum duration is 5 minutes.
:type auto_delete_on_idle: ~datetime.timedelta
Input value of either type ~datetime.timedelta or string in ISO 8601 duration format like "PT300S" is accepted.
:type auto_delete_on_idle: Union[~datetime.timedelta, str]
:rtype: ~azure.servicebus.management.SubscriptionProperties
"""
_validate_entity_name_type(topic_name, display_name="topic_name")
Expand Down Expand Up @@ -932,10 +942,10 @@ async def update_subscription(
)
to_update = subscription._to_internal_entity()

to_update.default_message_time_to_live = avoid_timedelta_overflow(
to_update.default_message_time_to_live = avoid_timedelta_overflow( # type: ignore
to_update.default_message_time_to_live
)
to_update.auto_delete_on_idle = avoid_timedelta_overflow(
to_update.auto_delete_on_idle = avoid_timedelta_overflow( # type: ignore
to_update.auto_delete_on_idle
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,17 +288,20 @@ def create_queue(self, queue_name, **kwargs):
:type authorization_rules: list[~azure.servicebus.management.AuthorizationRule]
:keyword auto_delete_on_idle: ISO 8601 timeSpan idle interval after which the queue is
automatically deleted. The minimum duration is 5 minutes.
:type auto_delete_on_idle: ~datetime.timedelta
Input value of either type ~datetime.timedelta or string in ISO 8601 duration format like "PT300S" is accepted.
:type auto_delete_on_idle: Union[~datetime.timedelta, str]
:keyword dead_lettering_on_message_expiration: A value that indicates whether this queue has dead
letter support when a message expires.
:type dead_lettering_on_message_expiration: bool
:keyword default_message_time_to_live: ISO 8601 default message timespan to live value. This is
the duration after which the message expires, starting from when the message is sent to Service
Bus. This is the default value used when TimeToLive is not set on a message itself.
:type default_message_time_to_live: ~datetime.timedelta
Input value of either type ~datetime.timedelta or string in ISO 8601 duration format like "PT300S" is accepted.
:type default_message_time_to_live: Union[~datetime.timedelta, str]
:keyword duplicate_detection_history_time_window: ISO 8601 timeSpan structure that defines the
duration of the duplicate detection history. The default value is 10 minutes.
:type duplicate_detection_history_time_window: ~datetime.timedelta
Input value of either type ~datetime.timedelta or string in ISO 8601 duration format like "PT300S" is accepted.
:type duplicate_detection_history_time_window: Union[~datetime.timedelta, str]
:keyword enable_batched_operations: Value that indicates whether server-side batched operations
are enabled.
:type enable_batched_operations: bool
Expand All @@ -311,7 +314,8 @@ def create_queue(self, queue_name, **kwargs):
:keyword lock_duration: ISO 8601 timespan duration of a peek-lock; that is, the amount of time
that the message is locked for other receivers. The maximum value for LockDuration is 5
minutes; the default value is 1 minute.
:type lock_duration: ~datetime.timedelta
Input value of either type ~datetime.timedelta or string in ISO 8601 duration format like "PT300S" is accepted.
:type lock_duration: Union[~datetime.timedelta, str]
:keyword max_delivery_count: The maximum delivery count. A message is automatically deadlettered
after this number of deliveries. Default value is 10.
:type max_delivery_count: int
Expand Down Expand Up @@ -553,7 +557,8 @@ def create_topic(self, topic_name, **kwargs):
:keyword default_message_time_to_live: ISO 8601 default message timespan to live value. This is
the duration after which the message expires, starting from when the message is sent to Service
Bus. This is the default value used when TimeToLive is not set on a message itself.
:type default_message_time_to_live: ~datetime.timedelta
Input value of either type ~datetime.timedelta or string in ISO 8601 duration format like "PT300S" is accepted.
:type default_message_time_to_live: Union[~datetime.timedelta, str]
:keyword max_size_in_megabytes: The maximum size of the topic in megabytes, which is the size of
memory allocated for the topic.
:type max_size_in_megabytes: long
Expand All @@ -562,7 +567,8 @@ def create_topic(self, topic_name, **kwargs):
:type requires_duplicate_detection: bool
:keyword duplicate_detection_history_time_window: ISO 8601 timeSpan structure that defines the
duration of the duplicate detection history. The default value is 10 minutes.
:type duplicate_detection_history_time_window: ~datetime.timedelta
Input value of either type ~datetime.timedelta or string in ISO 8601 duration format like "PT300S" is accepted.
:type duplicate_detection_history_time_window: Union[~datetime.timedelta, str]
:keyword enable_batched_operations: Value that indicates whether server-side batched operations
are enabled.
:type enable_batched_operations: bool
Expand All @@ -577,7 +583,8 @@ def create_topic(self, topic_name, **kwargs):
:type support_ordering: bool
:keyword auto_delete_on_idle: ISO 8601 timeSpan idle interval after which the topic is
automatically deleted. The minimum duration is 5 minutes.
:type auto_delete_on_idle: ~datetime.timedelta
Input value of either type ~datetime.timedelta or string in ISO 8601 duration format like "PT300S" is accepted.
:type auto_delete_on_idle: Union[~datetime.timedelta, str]
:keyword enable_partitioning: A value that indicates whether the topic is to be partitioned
across multiple message brokers.
:type enable_partitioning: bool
Expand Down Expand Up @@ -662,10 +669,10 @@ def update_topic(self, topic, **kwargs):
or topic.duplicate_detection_history_time_window
)

to_update.default_message_time_to_live = avoid_timedelta_overflow(
to_update.default_message_time_to_live = avoid_timedelta_overflow( # type: ignore
to_update.default_message_time_to_live
)
to_update.auto_delete_on_idle = avoid_timedelta_overflow(
to_update.auto_delete_on_idle = avoid_timedelta_overflow( # type: ignore
to_update.auto_delete_on_idle
)

Expand Down Expand Up @@ -804,14 +811,16 @@ def create_subscription(self, topic_name, subscription_name, **kwargs):
:keyword lock_duration: ISO 8601 timespan duration of a peek-lock; that is, the amount of time
that the message is locked for other receivers. The maximum value for LockDuration is 5
minutes; the default value is 1 minute.
:type lock_duration: ~datetime.timedelta
Input value of either type ~datetime.timedelta or string in ISO 8601 duration format like "PT300S" is accepted.
:type lock_duration: Union[~datetime.timedelta, str]
:keyword requires_session: A value that indicates whether the queue supports the concept of
sessions.
:type requires_session: bool
:keyword default_message_time_to_live: ISO 8601 default message timespan to live value. This is
the duration after which the message expires, starting from when the message is sent to Service
Bus. This is the default value used when TimeToLive is not set on a message itself.
:type default_message_time_to_live: ~datetime.timedelta
Input value of either type ~datetime.timedelta or string in ISO 8601 duration format like "PT300S" is accepted.
:type default_message_time_to_live: Union[~datetime.timedelta, str]
:keyword dead_lettering_on_message_expiration: A value that indicates whether this subscription
has dead letter support when a message expires.
:type dead_lettering_on_message_expiration: bool
Expand All @@ -835,7 +844,8 @@ def create_subscription(self, topic_name, subscription_name, **kwargs):
:type forward_dead_lettered_messages_to: str
:keyword auto_delete_on_idle: ISO 8601 timeSpan idle interval after which the subscription is
automatically deleted. The minimum duration is 5 minutes.
:type auto_delete_on_idle: ~datetime.timedelta
Input value of either type ~datetime.timedelta or string in ISO 8601 duration format like "PT300S" is accepted.
:type auto_delete_on_idle: Union[~datetime.timedelta, str]
:rtype: ~azure.servicebus.management.SubscriptionProperties
"""
_validate_entity_name_type(topic_name, display_name="topic_name")
Expand Down Expand Up @@ -924,10 +934,10 @@ def update_subscription(self, topic_name, subscription, **kwargs):
)
to_update = subscription._to_internal_entity()

to_update.default_message_time_to_live = avoid_timedelta_overflow(
to_update.default_message_time_to_live = avoid_timedelta_overflow( # type: ignore
to_update.default_message_time_to_live
)
to_update.auto_delete_on_idle = avoid_timedelta_overflow(
to_update.auto_delete_on_idle = avoid_timedelta_overflow( # type: ignore
to_update.auto_delete_on_idle
)
create_entity_body = CreateSubscriptionBody(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
from typing import Dict, Iterable, Any, Optional, Tuple, Type
from typing import Dict, Iterable, Any, Optional, Tuple, Type, Union
from collections import OrderedDict
from datetime import timedelta
from msrest.serialization import Model
Expand Down Expand Up @@ -239,16 +239,21 @@


def avoid_timedelta_overflow(td):
# type: (Optional[timedelta]) -> Optional[timedelta]
# type: (Optional[Union[timedelta, str]]) -> Optional[Union[timedelta, str]]
"""Service Bus REST API uses "P10675199DT2H48M5.4775807S" as default value for some properties, which are of type
datetime.timedelta. When they are deserialized, Python round the milliseconds from 4775807 to 477581.
When we get an entity (for instance, QueueDescription) and update this entity, this default value is
deserialized to "P10675199DT2H48M5.477581S". Service Bus doesn't accept this value probably because it's too large.
The workaround is to deduct the milliseconds by 0.000001.
"""
result = td
if td is not None and td.days == 10675199 and td.microseconds >= 477581:
result = timedelta(seconds=td.total_seconds() - 0.000001)
try:
result = td
if td is not None and td.days == 10675199 and td.microseconds >= 477581: # type: ignore
result = timedelta(seconds=td.total_seconds() - 0.000001) # type: ignore
except AttributeError:
# td is expected to be an ISO 8601 time span string
# in this case we don't do client validation and let the service handle the string
pass
return result


Expand Down
Loading