Skip to content

Commit

Permalink
fixup! refactor string concat
Browse files Browse the repository at this point in the history
  • Loading branch information
jeqo committed Dec 30, 2023
1 parent a7ae503 commit 8d91072
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 24 deletions.
12 changes: 8 additions & 4 deletions rohmu/object_storage/azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,20 +123,24 @@ def conn_string(
is_secure: bool,
) -> str:
protocol = "https" if is_secure else "http"
conn_str = f"DefaultEndpointsProtocol={protocol};" f"AccountName={account_name};" f"AccountKey={account_key};"
conn = [
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 = f"{conn_str}" f"EndpointSuffix={endpoint_suffix};"
conn.append(f"EndpointSuffix={endpoint_suffix}")
else:
if not host or not port:
raise InvalidConfigurationError("Custom host and port must be specified together")

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

def copy_file(
self, *, source_key: str, destination_key: str, metadata: Optional[Metadata] = None, **kwargs: Any
Expand Down
40 changes: 20 additions & 20 deletions test/object_storage/test_azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,51 +112,51 @@ def test_get_contents_to_fileobj_raises_error_on_invalid_byte_range(azure_module
None,
None,
True,
"".join(
";".join(
[
"DefaultEndpointsProtocol=https;",
"AccountName=test_name;",
"AccountKey=test_key;",
"EndpointSuffix=core.windows.net;",
"DefaultEndpointsProtocol=https",
"AccountName=test_name",
"AccountKey=test_key",
"EndpointSuffix=core.windows.net",
]
),
),
(
None,
None,
False,
"".join(
";".join(
[
"DefaultEndpointsProtocol=http;",
"AccountName=test_name;",
"AccountKey=test_key;",
"EndpointSuffix=core.windows.net;",
"DefaultEndpointsProtocol=http",
"AccountName=test_name",
"AccountKey=test_key",
"EndpointSuffix=core.windows.net",
]
),
),
(
"localhost",
10000,
True,
"".join(
";".join(
[
"DefaultEndpointsProtocol=https;",
"AccountName=test_name;",
"AccountKey=test_key;",
"BlobEndpoint=https://localhost:10000/test_name;",
"DefaultEndpointsProtocol=https",
"AccountName=test_name",
"AccountKey=test_key",
"BlobEndpoint=https://localhost:10000/test_name",
]
),
),
(
"localhost",
10000,
False,
"".join(
";".join(
[
"DefaultEndpointsProtocol=http;",
"AccountName=test_name;",
"AccountKey=test_key;",
"BlobEndpoint=http://localhost:10000/test_name;",
"DefaultEndpointsProtocol=http",
"AccountName=test_name",
"AccountKey=test_key",
"BlobEndpoint=http://localhost:10000/test_name",
]
),
),
Expand Down

0 comments on commit 8d91072

Please sign in to comment.