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

[DPE-5039] - Simple charm ops #19

Merged
merged 11 commits into from
Aug 12, 2024
34 changes: 26 additions & 8 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ def _pull_licenses(container: Container) -> None:
license_file = container.pull(
path=Config.get_license_path(license_name)
)
f = open("LICENSE", "x")
f = open(license_name, "x")
MiaAltieri marked this conversation as resolved.
Show resolved Hide resolved
f.write(str(license_file.read()))
f.close()
except FileExistsError:
Expand Down Expand Up @@ -400,15 +400,23 @@ def _unit_ip(self) -> str:

@property
def is_external_client(self) -> Optional[str]:
Mehdi-Bendriss marked this conversation as resolved.
Show resolved Hide resolved
"""Returns the database requested by the hosting application of the subordinate charm."""
"""Returns the connectivity mode which mongos should use.

This is determined by checking the modes requested by the client(s).

TODO: Future PR. This should be modified to work for many clients.
"""
if EXTERNAL_CONNECTIVITY_TAG not in self.app_peer_data:
return False

return json.loads(self.app_peer_data.get(EXTERNAL_CONNECTIVITY_TAG))

@property
def database(self) -> Optional[str]:
"""Returns the database requested by the hosting application of the subordinate charm."""
"""Returns a mapping of databases requested by integrated clients.

TODO: Future PR. This should be modified to work for many clients.
MiaAltieri marked this conversation as resolved.
Show resolved Hide resolved
"""
if not self._peers:
logger.info("Peer relation not joined yet.")
# TODO future PR implement relation interface between host application mongos and use
Expand All @@ -419,7 +427,10 @@ def database(self) -> Optional[str]:

@property
def extra_user_roles(self) -> Set[str]:
"""Returns the user roles requested by the hosting application of the subordinate charm."""
"""Returns a mapping of user roles requested by integrated clients.

TODO: Future PR. This should be modified to work for many clients.
"""
if not self._peers:
logger.info("Peer relation not joined yet.")
return None
Expand All @@ -430,6 +441,7 @@ def extra_user_roles(self) -> Set[str]:
def mongos_config(self) -> MongosConfiguration:
"""Generates a MongoDBConfiguration object for mongos in the deployment of MongoDB."""
hosts = [self.get_mongos_host()]
# TODO: Future PR. Ensure that this works for external connections with NodePort
port = Config.MONGOS_PORT if self.is_external_client else None
Gu1nness marked this conversation as resolved.
Show resolved Hide resolved
external_ca, _ = self.tls.get_tls_files(internal=False)
internal_ca, _ = self.tls.get_tls_files(internal=True)
Expand All @@ -456,13 +468,19 @@ def _peers(self) -> Relation | None:

@property
def unit_peer_data(self) -> Dict:
"""Unit peer relation data object."""
return self._peers.data[self.unit]
"""Peer relation data object."""
if not self.peers:
return {}

return self.peers.data[self.unit]
MiaAltieri marked this conversation as resolved.
Show resolved Hide resolved

@property
def app_peer_data(self) -> Dict:
"""App peer relation data object."""
return self._peers.data[self.app]
"""Peer relation data object."""
if not self.peers:
return {}

return self.peers.data[self.app]
MiaAltieri marked this conversation as resolved.
Show resolved Hide resolved

@property
def upgrade_in_progress(self) -> bool:
Expand Down
Loading