Skip to content

Commit

Permalink
make host optional
Browse files Browse the repository at this point in the history
  • Loading branch information
arturo-seijas committed Apr 9, 2024
1 parent 3a25cfa commit 2bc8def
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src-docs/state.py.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ The Indico operator charm state.

---

<a href="../src/state.py#L164"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/state.py#L167"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>classmethod</kbd> `from_charm`

Expand Down
9 changes: 6 additions & 3 deletions src/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class S3Config(BaseModel): # pylint: disable=too-few-public-methods
"""

bucket: str
host: str
host: Optional[str]
access_key: str
secret_key: str

Expand All @@ -88,10 +88,13 @@ def get_connection_string(self) -> str:
Returns: the connection string for this instance.
"""
return (
f"s3:bucket={self.bucket},host={self.host},access_key={self.access_key},"
connection_string = (
f"s3:bucket={self.bucket},access_key={self.access_key},"
f"secret_key={self.secret_key},proxy=true"
)
if self.host:
connection_string = f"{connection_string},host={self.host}"
return connection_string


class SamlEndpoint(BaseModel): # pylint: disable=too-few-public-methods
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,8 @@ def test_config_changed(self, mock_exec): # pylint: disable=R0915
self.assertEqual("fs:/srv/indico/archive", storage_dict["default"])
self.assertEqual(
(
f"s3:bucket={s3_config.bucket},host={s3_config.host},"
f"access_key={s3_config.access_key},secret_key={s3_config.secret_key},proxy=true"
f"s3:bucket={s3_config.bucket},access_key={s3_config.access_key},"
f"secret_key={s3_config.secret_key},proxy=true,host={s3_config.host}"
),
storage_dict["s3"],
)
Expand Down
25 changes: 23 additions & 2 deletions tests/unit/test_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,27 @@ def test_s3_config_get_connection_string():
connection_string = s3_config.get_connection_string()

assert connection_string == (
f"s3:bucket=sample-bucket,host=s3.example.com,access_key={access_key},"
f"secret_key={secret_key},proxy=true"
f"s3:bucket=sample-bucket,access_key={access_key},"
f"secret_key={secret_key},proxy=true,host=s3.example.com"
)


def test_s3_config_get_connection_string_without_host():
"""
arrange: create an S3Config object.
act: call the get_connection_string method.
assert: the returned value matches the object attributes.
"""
access_key = token_hex(16)
secret_key = token_hex(16)
s3_config = state.S3Config(
bucket="sample-bucket",
access_key=access_key,
secret_key=secret_key,
)

connection_string = s3_config.get_connection_string()

assert connection_string == (
f"s3:bucket=sample-bucket,access_key={access_key},secret_key={secret_key},proxy=true"
)

0 comments on commit 2bc8def

Please sign in to comment.