Skip to content

Commit 083b303

Browse files
[DPE-6344] Persist transferred certificates upon start (#953)
1 parent 280d444 commit 083b303

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

lib/charms/postgresql_k8s/v0/postgresql_tls.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import logging
2424
import re
2525
import socket
26-
from typing import List, Optional
26+
from typing import Iterator, List, Optional
2727

2828
from charms.certificate_transfer_interface.v0.certificate_transfer import (
2929
CertificateAvailableEvent as CertificateAddedEvent,
@@ -55,7 +55,7 @@
5555

5656
# Increment this PATCH version before using `charmcraft publish-lib` or reset
5757
# to 0 if you are raising the major API version.
58-
LIBPATCH = 14
58+
LIBPATCH = 15
5959

6060
logger = logging.getLogger(__name__)
6161
SCOPE = "unit"
@@ -269,6 +269,17 @@ def is_ip_address(address: str) -> bool:
269269
"sans_dns": sans_dns,
270270
}
271271

272+
def get_ca_secret_names(self) -> Iterator[str]:
273+
"""Get a secret-name for each relation fulfilling the CA transfer interface.
274+
275+
Returns:
276+
Secret name for a CA transfer fulfilled interface.
277+
"""
278+
relations = self.charm.model.relations.get(TLS_TRANSFER_RELATION, [])
279+
280+
for relation in relations:
281+
yield f"ca-{relation.app.name}"
282+
272283
def get_tls_files(self) -> (Optional[str], Optional[str], Optional[str]):
273284
"""Prepare TLS files in special PostgreSQL way.
274285

src/charm.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,9 @@ def _on_postgresql_pebble_ready(self, event: WorkloadEvent) -> None:
998998
return
999999

10001000
try:
1001-
self.push_tls_files_to_workload(container)
1001+
self.push_tls_files_to_workload()
1002+
for ca_secret_name in self.tls.get_ca_secret_names():
1003+
self.push_ca_file_into_workload(ca_secret_name)
10021004
except (PathError, ProtocolError) as e:
10031005
logger.error(
10041006
"Deferring on_postgresql_pebble_ready: Cannot push TLS certificates: %r", e
@@ -1893,10 +1895,9 @@ def _push_file_to_workload(self, container: Container, file_path: str, file_data
18931895
group=WORKLOAD_OS_GROUP,
18941896
)
18951897

1896-
def push_tls_files_to_workload(self, container: Container = None) -> bool:
1898+
def push_tls_files_to_workload(self) -> bool:
18971899
"""Uploads TLS files to the workload container."""
1898-
if container is None:
1899-
container = self.unit.get_container("postgresql")
1900+
container = self.unit.get_container("postgresql")
19001901

19011902
key, ca, cert = self.tls.get_tls_files()
19021903

0 commit comments

Comments
 (0)