Skip to content

Commit

Permalink
fixup! move checks to config validator
Browse files Browse the repository at this point in the history
  • Loading branch information
jeqo committed Jan 2, 2024
1 parent 2e7e68f commit 9ff51d4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
3 changes: 0 additions & 3 deletions rohmu/object_storage/azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,6 @@ def conn_string(

conn.append(f"EndpointSuffix={endpoint_suffix}")
else:
if not host or not port:
raise InvalidConfigurationError("Custom host and port must be specified together")

conn.append(f"BlobEndpoint={protocol}://{host}:{port}/{account_name}")
return ";".join(conn)

Expand Down
8 changes: 8 additions & 0 deletions rohmu/object_storage/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ class AzureObjectStorageConfig(StorageModel):
proxy_info: Optional[ProxyInfo] = None
storage_type: Literal[StorageDriver.azure] = StorageDriver.azure

@root_validator
@classmethod
def host_and_port_must_be_set_together(cls, values: Dict[str, Any]) -> Dict[str, Any]:
if "host" in values and "port" in values:
if not values["host"] or not values["port"]:
raise ValueError("host and port must be set together")
return values


class GoogleObjectStorageConfig(StorageModel):
project_id: str
Expand Down
8 changes: 8 additions & 0 deletions test/object_storage/test_azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from datetime import datetime
from io import BytesIO
from rohmu.errors import InvalidByteRangeError
from rohmu.object_storage.config import AzureObjectStorageConfig
from tempfile import NamedTemporaryFile
from types import ModuleType
from typing import Any, Optional, Tuple
Expand Down Expand Up @@ -105,6 +106,13 @@ def test_get_contents_to_fileobj_raises_error_on_invalid_byte_range(azure_module
)


def test_azure_config_host_port_set_together() -> None:
with pytest.raises(ValueError):
AzureObjectStorageConfig(account_name="test", host="localhost")
with pytest.raises(ValueError):
AzureObjectStorageConfig(account_name="test", port=10000)


@pytest.mark.parametrize(
"host,port,is_secured,expected",
[
Expand Down

0 comments on commit 9ff51d4

Please sign in to comment.