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

Allow azurestoragequeues transport to be used with Azurite emulator in docker-compose #1611

Merged
merged 3 commits into from
Oct 16, 2022
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
9 changes: 8 additions & 1 deletion kombu/transport/azurestoragequeues.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class Transport(virtual.Transport):
can_parse_url = True

@staticmethod
def parse_uri(uri: str) -> tuple[str, str]:
def parse_uri(uri: str) -> tuple[str | dict, str]:
# URL like:
# azurestoragequeues://STORAGE_ACCOUNT_ACCESS_KEY@STORAGE_ACCOUNT_URL
# azurestoragequeues://SAS_TOKEN@STORAGE_ACCOUNT_URL
Expand All @@ -192,6 +192,13 @@ def parse_uri(uri: str) -> tuple[str, str]:
# > 'some/key', 'url'
credential, url = uri.rsplit('@', 1)

# parse credential as a dict if Azurite is being used
if "devstoreaccount1" in url and ".core.windows.net" not in url:
credential = {
"account_name": "devstoreaccount1",
"account_key": credential,
}

# Validate parameters
assert all([credential, url])
except Exception:
Expand Down
21 changes: 21 additions & 0 deletions t/unit/transport/test_azurestoragequeues.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

URL_NOCREDS = 'azurestoragequeues://'
URL_CREDS = 'azurestoragequeues://sas/key%@https://STORAGE_ACCOUNT_NAME.queue.core.windows.net/' # noqa
AZURITE_CREDS = 'azurestoragequeues://Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==@http://localhost:10001/devstoreaccount1' # noqa
AZURITE_CREDS_DOCKER_COMPOSE = 'azurestoragequeues://Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==@http://azurite:10001/devstoreaccount1' # noqa


def test_queue_service_nocredentials():
Expand All @@ -31,3 +33,22 @@ def test_queue_service():
# Check the SAS token "sas/key%" has been parsed from the url correctly
assert channel._credential == 'sas/key%'
assert channel._url == 'https://STORAGE_ACCOUNT_NAME.queue.core.windows.net/' # noqa


@pytest.mark.parametrize(
"creds, hostname",
[
(AZURITE_CREDS, 'localhost'),
(AZURITE_CREDS_DOCKER_COMPOSE, 'azurite'),
]
)
def test_queue_service_works_for_azurite(creds, hostname):
conn = Connection(creds, transport=azurestoragequeues.Transport)
with patch('kombu.transport.azurestoragequeues.QueueServiceClient'):
channel = conn.channel()

assert channel._credential == {
'account_name': 'devstoreaccount1',
'account_key': 'Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==' # noqa
}
assert channel._url == f'http://{hostname}:10001/devstoreaccount1' # noqa