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

Replace UTC_Now() workaround with MSRest.UTC #13498

Merged
merged 4 commits into from
Sep 11, 2020
Merged
Changes from 1 commit
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
43 changes: 25 additions & 18 deletions sdk/servicebus/azure-servicebus/azure/servicebus/_common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,24 @@
import functools
import platform
from typing import Optional, Dict
from msrest.serialization import UTC as utc


try:
from urlparse import urlparse
except ImportError:
from urllib.parse import urlparse

from uamqp import authentication, types

from ..exceptions import ServiceBusError
from .._version import VERSION
from .constants import (
JWT_TOKEN_SCOPE,
TOKEN_TYPE_JWT,
TOKEN_TYPE_SASTOKEN,
DEAD_LETTER_QUEUE_SUFFIX,
TRANSFER_DEAD_LETTER_QUEUE_SUFFIX,
USER_AGENT_PREFIX
USER_AGENT_PREFIX,
)

_log = logging.getLogger(__name__)
Expand Down Expand Up @@ -60,23 +62,23 @@ def utc_from_timestamp(timestamp):


def utc_now():
return datetime.datetime.now(tz=TZ_UTC)
return datetime.datetime.now(utc())
lmazuel marked this conversation as resolved.
Show resolved Hide resolved


def parse_conn_str(conn_str):
endpoint = None
shared_access_key_name = None
shared_access_key = None
entity_path = None
for element in conn_str.split(';'):
key, _, value = element.partition('=')
if key.lower() == 'endpoint':
endpoint = value.rstrip('/')
elif key.lower() == 'sharedaccesskeyname':
for element in conn_str.split(";"):
key, _, value = element.partition("=")
if key.lower() == "endpoint":
endpoint = value.rstrip("/")
elif key.lower() == "sharedaccesskeyname":
shared_access_key_name = value
elif key.lower() == 'sharedaccesskey':
elif key.lower() == "sharedaccesskey":
shared_access_key = value
elif key.lower() == 'entitypath':
elif key.lower() == "entitypath":
entity_path = value
if not all([endpoint, shared_access_key_name, shared_access_key]):
raise ValueError("Invalid connection string")
Expand All @@ -99,7 +101,8 @@ def create_properties(user_agent=None):
Format the properties with which to instantiate the connection.
This acts like a user agent over HTTP.

:param str user_agent: If specified, this will be added in front of the built-in user agent string.
:param str user_agent: If specified,
this will be added in front of the built-in user agent string.

:rtype: dict
"""
Expand Down Expand Up @@ -165,23 +168,27 @@ def create_authentication(client):


def generate_dead_letter_entity_name(
queue_name=None,
topic_name=None,
subscription_name=None,
transfer_deadletter=False
queue_name=None, topic_name=None, subscription_name=None, transfer_deadletter=False
):
entity_name = queue_name if queue_name else (topic_name + "/Subscriptions/" + subscription_name)
entity_name = (
queue_name
if queue_name
else (topic_name + "/Subscriptions/" + subscription_name)
)
entity_name = "{}{}".format(
entity_name,
TRANSFER_DEAD_LETTER_QUEUE_SUFFIX if transfer_deadletter else DEAD_LETTER_QUEUE_SUFFIX
TRANSFER_DEAD_LETTER_QUEUE_SUFFIX
if transfer_deadletter
else DEAD_LETTER_QUEUE_SUFFIX,
)

return entity_name


def copy_messages_to_sendable_if_needed(messages):
"""
This method is to convert single/multiple received messages to sendable messages to enable message resending.
This method is to convert single/multiple received messages
to sendable messages to enable message resending.
"""
# pylint: disable=protected-access
try:
Expand Down