Skip to content

Commit

Permalink
fixup! apply suggestions
Browse files Browse the repository at this point in the history
Remote log leftovers, extend http and connection string building, and extend testing
  • Loading branch information
jeqo committed Dec 21, 2023
1 parent c0ce800 commit 03cc506
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
19 changes: 9 additions & 10 deletions rohmu/object_storage/azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,29 +122,28 @@ def conn_string(
port: Optional[int],
is_secure: bool,
) -> str:
protocol = "https" if is_secure else "http"
conn_str = (
f"DefaultEndpointsProtocol={protocol};"
f"AccountName={account_name};"
f"AccountKey={account_key};"
)
if not host and not port:
try:
endpoint_suffix = ENDPOINT_SUFFIXES[azure_cloud]
except KeyError:
raise InvalidConfigurationError(f"Unknown azure cloud {repr(azure_cloud)}")

conn_str = (
"DefaultEndpointsProtocol=https;"
f"AccountName={account_name};"
f"AccountKey={account_key};"
f"EndpointSuffix={endpoint_suffix}"
f"{conn_str}"
f"EndpointSuffix={endpoint_suffix};"
)
else:
print(host)
print(port)
if not host or not port:
raise InvalidConfigurationError("Custom host and port must be specified together")

protocol = "https" if is_secure else "http"
conn_str = (
f"DefaultEndpointsProtocol={protocol};"
f"AccountName={account_name};"
f"AccountKey={account_key};"
f"{conn_str}"
f"BlobEndpoint={protocol}://{host}:{port}/{account_name};"
)
return conn_str
Expand Down
26 changes: 19 additions & 7 deletions test/object_storage/test_azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from rohmu.errors import InvalidByteRangeError
from tempfile import NamedTemporaryFile
from types import ModuleType
from typing import Any, Tuple
from typing import Any, Tuple, Optional
from unittest.mock import MagicMock, patch

import pytest
Expand Down Expand Up @@ -105,7 +105,22 @@ def test_get_contents_to_fileobj_raises_error_on_invalid_byte_range(azure_module
)


def test_conn_string_custom_host_port() -> None:
@pytest.mark.parametrize(
"host,port,is_secured,expected",
[
(None, None, True,
"DefaultEndpointsProtocol=https;AccountName=test_name;AccountKey=test_key;EndpointSuffix=core.windows.net;"),
(None, None, False,
"DefaultEndpointsProtocol=http;AccountName=test_name;AccountKey=test_key;EndpointSuffix=core.windows.net;"),
("localhost", 10000, True,
"DefaultEndpointsProtocol=https;AccountName=test_name;AccountKey=test_key;"
"BlobEndpoint=https://localhost:10000/test_name;"),
("localhost", 10000, False,
"DefaultEndpointsProtocol=http;AccountName=test_name;AccountKey=test_key;"
"BlobEndpoint=http://localhost:10000/test_name;"),
]
)
def test_conn_string(host: Optional[str], port: Optional[int], is_secured: bool, expected: str) -> None:
get_blob_client_mock = MagicMock()
blob_client = MagicMock(get_blob_client=get_blob_client_mock)
service_client = MagicMock(from_connection_string=MagicMock(return_value=blob_client))
Expand All @@ -118,9 +133,6 @@ def test_conn_string_custom_host_port() -> None:
from rohmu.object_storage.azure import AzureTransfer

conn_string = AzureTransfer.conn_string(
account_name="test_name", account_key="test_key", azure_cloud=None, host="localhost", port=10000, is_secure=False
account_name="test_name", account_key="test_key", azure_cloud=None, host=host, port=port, is_secure=is_secured
)
assert (
"DefaultEndpointsProtocol=http;AccountName=test_name;AccountKey=test_key;"
"BlobEndpoint=http://localhost:10000/test_name;"
) == conn_string
assert expected == conn_string

0 comments on commit 03cc506

Please sign in to comment.