Skip to content

Commit

Permalink
Don't overwrite keys
Browse files Browse the repository at this point in the history
  • Loading branch information
dragomirp committed Jan 7, 2025
1 parent cc4a25b commit ebc10a3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
4 changes: 2 additions & 2 deletions lib/charms/postgresql_k8s/v0/postgresql.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,8 @@ def enable_disable_extensions(
connection.close()

def _generate_database_privileges_statements(
self, relations_accessing_this_database: int, schemas: list[str], user: str
) -> list[Composed]:
self, relations_accessing_this_database: int, schemas: List[str], user: str
) -> List[Composed]:
"""Generates a list of databases privileges statements."""
statements = []
if relations_accessing_this_database == 1:
Expand Down
19 changes: 12 additions & 7 deletions lib/charms/postgresql_k8s/v0/postgresql_tls.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,22 @@ def _on_certificate_available(self, event: CertificateAvailableEvent) -> None:
logger.error("An unknown certificate available.")
return

self.charm.set_secret(
SCOPE, "chain", "\n".join(event.chain) if event.chain is not None else None
)
self.charm.set_secret(SCOPE, "cert", event.certificate)
self.charm.set_secret(SCOPE, "ca", event.ca)

if not event.certificate:
logger.debug("Cannot push TLS certificates at this moment")
logger.debug("No certificate available.")
event.defer()
return

chain = self.charm.get_secret(SCOPE, "chain")
new_chain = "\n".join(event.chain) if event.chain is not None else None
if chain != new_chain:
self.charm.set_secret(SCOPE, "chain", new_chain)
cert = self.charm.get_secret(SCOPE, "cert")
if cert != event.certificate:
self.charm.set_secret(SCOPE, "cert", event.certificate)
ca = self.charm.get_secret(SCOPE, "ca")
if ca != event.ca:
self.charm.set_secret(SCOPE, "ca", event.ca)

try:
if not self.charm.push_tls_files_to_workload():
logger.debug("Cannot push TLS certificates at this moment")
Expand Down

0 comments on commit ebc10a3

Please sign in to comment.