Skip to content

Commit c266336

Browse files
dragomirprenovate[bot]sinclert-canonicalmarceloneppela-velasco
authored
[MISC] Sync main to 16/edge (#958)
* Update charmcraft.yaml build tools (#903) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Update canonical/data-platform-workflows action to v31.0.1 (#902) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * [DPE-6344] LDAP IV: Define pebble service (#897) * Update ghcr.io/canonical/charmed-postgresql:14.17-22.04_edge Docker digest to 5f8d51a (#908) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * [DPE-6344] LDAP V: Define mapping option (#900) * Update charmcraft.yaml build tools (#912) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * [DPE-6910] Remove duplicate parameters specification (#896) * Remove duplicate parameters specification Signed-off-by: Marcelo Henrique Neppel <[email protected]> * Enable config test Signed-off-by: Marcelo Henrique Neppel <[email protected]> * Fix linting Signed-off-by: Marcelo Henrique Neppel <[email protected]> --------- Signed-off-by: Marcelo Henrique Neppel <[email protected]> * [MISC] Conditional checksum calculation (#901) * Conditional checksum calculation * Converge s3 resource creation * Tactically deployed sleep * Early fail * Update charmcraft.yaml build tools (#916) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Create SECURITY.md (#914) * Update pull_request_template.md (#918) * [MISC] Add missing connection vars (#920) * Update README file's security section (#921) * Add empty lines after headings * Update security section * Update link to make it clear that's not GitHub issues * [DPE-6218] Static code analysis (#915) * Create actionlint.yaml * Create tiobe_scan.yaml * Add push event to trigger the workflow once * Install libpq-dev * Remove push event * Test adding unit venv to PATH * Test sourcing unit venv * Fix sourcing * Test installing dependencies * Activate virtual environment * Add poetry dependency * Fix TICS auth token variable * Move results to the right folder * Delete .github/actionlint.yaml * Install ops * Install dependencies through poetry * Install extra dependencies * Install dependencies from all groups * Remove unnecessary step * Remove permission * Remove push trigger * Add double quotes to environment variables Signed-off-by: Marcelo Henrique Neppel <[email protected]> * Add push trigger * Remove push trigger Signed-off-by: Marcelo Henrique Neppel <[email protected]> --------- Signed-off-by: Marcelo Henrique Neppel <[email protected]> * Update dependency uv to v0.6.14 (#924) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Disable pgaudit (#931) * Lock file maintenance Python dependencies (main) (#904) * Lock file maintenance Python dependencies * Add a separate pyproj for libs --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Dragomir Penev <[email protected]> * [DPE-6344] Remove CA transferred check (#932) * [MISC] Don't set tls flag if relation isn't initialised (#933) * Don't set tls flag if relation isn't initialised * Unit test * Update dependency uv to v0.6.16 (#936) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Lock file maintenance Python dependencies (#937) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Update ghcr.io/canonical/charmed-postgresql:14.17-22.04_edge Docker digest to 1d771d2 (#935) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * [DPE-6664] Make username mandatory in set-password (#934) * Make username mandatory * Default in get_password * Lock file maintenance Python dependencies (#944) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Mandatory scope (#947) * Lock file maintenance Python dependencies (#949) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Update charmcraft.yaml build tools (#948) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * [DPE-6344] Persist transferred certificates upon start (#953) * [MISC] Extend relation-user listing syntax (#957) --------- Signed-off-by: Marcelo Henrique Neppel <[email protected]> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Sinclert Pérez <[email protected]> Co-authored-by: Marcelo Henrique Neppel <[email protected]> Co-authored-by: Andreia <[email protected]> Co-authored-by: Vladimir Izmalkov <[email protected]>
1 parent 274abc1 commit c266336

File tree

4 files changed

+26
-8
lines changed

4 files changed

+26
-8
lines changed

lib/charms/postgresql_k8s/v0/postgresql.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,9 @@ def list_users_from_relation(self) -> Set[str]:
672672
try:
673673
with self._connect_to_database() as connection, connection.cursor() as cursor:
674674
cursor.execute(
675-
"SELECT usename FROM pg_catalog.pg_user WHERE usename LIKE 'relation_id_%';"
675+
"SELECT usename "
676+
"FROM pg_catalog.pg_user "
677+
"WHERE usename LIKE 'relation_id_%' OR usename LIKE 'relation-%';"
676678
)
677679
usernames = cursor.fetchall()
678680
return {username[0] for username in usernames}

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
@@ -1036,7 +1036,9 @@ def _on_postgresql_pebble_ready(self, event: WorkloadEvent) -> None:
10361036
return
10371037

10381038
try:
1039-
self.push_tls_files_to_workload(container)
1039+
self.push_tls_files_to_workload()
1040+
for ca_secret_name in self.tls.get_ca_secret_names():
1041+
self.push_ca_file_into_workload(ca_secret_name)
10401042
except (PathError, ProtocolError) as e:
10411043
logger.error(
10421044
"Deferring on_postgresql_pebble_ready: Cannot push TLS certificates: %r", e
@@ -1902,10 +1904,9 @@ def _push_file_to_workload(self, container: Container, file_path: str, file_data
19021904
group=WORKLOAD_OS_GROUP,
19031905
)
19041906

1905-
def push_tls_files_to_workload(self, container: Container = None) -> bool:
1907+
def push_tls_files_to_workload(self) -> bool:
19061908
"""Uploads TLS files to the workload container."""
1907-
if container is None:
1908-
container = self.unit.get_container("postgresql")
1909+
container = self.unit.get_container("postgresql")
19091910

19101911
key, ca, cert = self.tls.get_tls_files()
19111912

tests/unit/test_postgresql.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,11 @@ def test_grant_relation_access_group_memberships(harness):
208208
harness.charm.postgresql.grant_relation_access_group_memberships()
209209

210210
execute.assert_has_calls([
211-
call("SELECT usename FROM pg_catalog.pg_user WHERE usename LIKE 'relation_id_%';"),
211+
call(
212+
"SELECT usename "
213+
"FROM pg_catalog.pg_user "
214+
"WHERE usename LIKE 'relation_id_%' OR usename LIKE 'relation-%';"
215+
),
212216
])
213217

214218

0 commit comments

Comments
 (0)