Skip to content

Commit 689d616

Browse files
dragomirprenovate[bot]sinclert-canonicalmarceloneppela-velasco
authored
[MISC] Sync main into 16/edge (#943)
* 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> --------- 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 73d3660 commit 689d616

File tree

8 files changed

+36
-53
lines changed

8 files changed

+36
-53
lines changed

src/charm.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1753,7 +1753,7 @@ def _generate_ldap_service(self) -> dict:
17531753

17541754
ldap_base_dn = ldap_params["ldapbasedn"]
17551755
ldap_bind_username = ldap_params["ldapbinddn"]
1756-
ldap_bing_password = ldap_params["ldapbindpasswd"]
1756+
ldap_bind_password = ldap_params["ldapbindpasswd"]
17571757
ldap_group_mappings = self.postgresql.build_postgresql_group_map(self.config.ldap_map)
17581758

17591759
return {
@@ -1766,7 +1766,7 @@ def _generate_ldap_service(self) -> dict:
17661766
"LDAP_PORT": ldap_port,
17671767
"LDAP_BASE_DN": ldap_base_dn,
17681768
"LDAP_BIND_USERNAME": ldap_bind_username,
1769-
"LDAP_BIND_PASSWORD": ldap_bing_password,
1769+
"LDAP_BIND_PASSWORD": ldap_bind_password,
17701770
"LDAP_GROUP_IDENTITY": json.dumps(ACCESS_GROUP_IDENTITY),
17711771
"LDAP_GROUP_MAPPINGS": json.dumps(ldap_group_mappings),
17721772
"POSTGRES_HOST": "127.0.0.1",
@@ -1984,7 +1984,7 @@ def _restart_ldap_sync_service(self) -> None:
19841984

19851985
if not self.is_primary and sync_service[0].is_running():
19861986
logger.debug("Stopping LDAP sync service. It must only run in the primary")
1987-
container.stop(self.pg_ldap_sync_service)
1987+
container.stop(self.ldap_sync_service)
19881988

19891989
if self.is_primary and not self.is_ldap_enabled:
19901990
logger.debug("Stopping LDAP sync service")

src/ldap.py

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,9 @@
1111
LdapRequirer,
1212
LdapUnavailableEvent,
1313
)
14-
from charms.postgresql_k8s.v0.postgresql_tls import (
15-
TLS_TRANSFER_RELATION,
16-
)
1714
from ops import Relation
1815
from ops.framework import Object
19-
from ops.model import ActiveStatus, BlockedStatus
16+
from ops.model import ActiveStatus
2017

2118
logger = logging.getLogger(__name__)
2219

@@ -35,29 +32,13 @@ def __init__(self, charm, relation_name: str):
3532
self.framework.observe(self.ldap.on.ldap_ready, self._on_ldap_ready)
3633
self.framework.observe(self.ldap.on.ldap_unavailable, self._on_ldap_unavailable)
3734

38-
@property
39-
def ca_transferred(self) -> bool:
40-
"""Return whether the CA certificate has been transferred."""
41-
ca_transferred_relations = self.model.relations[TLS_TRANSFER_RELATION]
42-
43-
for relation in ca_transferred_relations:
44-
if relation.app.name == self._relation.app.name:
45-
return True
46-
47-
return False
48-
4935
@property
5036
def _relation(self) -> Relation:
5137
"""Return the relation object."""
5238
return self.model.get_relation(self.relation_name)
5339

54-
def _on_ldap_ready(self, event: LdapReadyEvent) -> None:
40+
def _on_ldap_ready(self, _: LdapReadyEvent) -> None:
5541
"""Handler for the LDAP ready event."""
56-
if not self.ca_transferred:
57-
self.charm.unit.status = BlockedStatus("LDAP insecure. Send LDAP server certificate")
58-
event.defer()
59-
return
60-
6142
logger.debug("Enabling LDAP connection")
6243
if self.charm.unit.is_leader():
6344
self.charm.app_peer_data.update({"ldap_enabled": "True"})

src/relations/postgresql_provider.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,9 @@ def update_tls_flag(self, tls: str) -> None:
265265
ca = ""
266266

267267
for relation in relations:
268-
self.database_provides.set_tls(relation.id, tls)
269-
self.database_provides.set_tls_ca(relation.id, ca)
268+
if self.database_provides.fetch_relation_field(relation.id, "database"):
269+
self.database_provides.set_tls(relation.id, tls)
270+
self.database_provides.set_tls_ca(relation.id, ca)
270271

271272
def _check_multiple_endpoints(self) -> bool:
272273
"""Checks if there are relations with other endpoints."""

tests/integration/ha_tests/test_upgrade.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ async def test_deploy_latest(ops_test: OpsTest) -> None:
5959
await ops_test.model.wait_for_idle(
6060
apps=[DATABASE_APP_NAME, APPLICATION_NAME],
6161
status="active",
62-
raise_on_error=False,
6362
timeout=1000,
6463
)
6564
assert len(ops_test.model.applications[DATABASE_APP_NAME].units) == 3

tests/integration/ha_tests/test_upgrade_from_stable.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ async def test_deploy_stable(ops_test: OpsTest) -> None:
5454
logger.info("Wait for applications to become active")
5555
async with ops_test.fast_forward():
5656
await ops_test.model.wait_for_idle(
57-
apps=[DATABASE_APP_NAME, APPLICATION_NAME], status="active", raise_on_error=False
57+
apps=[DATABASE_APP_NAME, APPLICATION_NAME], status="active"
5858
)
5959
assert len(ops_test.model.applications[DATABASE_APP_NAME].units) == 3
6060

tests/integration/helpers.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ async def build_and_deploy(
115115
apps=[database_app_name],
116116
status=status,
117117
raise_on_blocked=True,
118-
raise_on_error=False,
119118
timeout=1000,
120119
wait_for_exact_units=num_units,
121120
)

tests/unit/test_ldap.py

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
from unittest.mock import (
55
MagicMock,
6-
PropertyMock,
76
patch,
87
)
98

@@ -29,14 +28,10 @@ def harness():
2928
harness.cleanup()
3029

3130

32-
def test_on_ldap_ready_with_certificate(harness):
31+
def test_on_ldap_ready(harness):
3332
mock_event = MagicMock()
3433

35-
with (
36-
patch("charm.PostgresqlOperatorCharm.update_config") as _update_config,
37-
patch("charm.PostgreSQLLDAP.ca_transferred", new_callable=PropertyMock) as _ca_transferred,
38-
):
39-
_ca_transferred.return_value = True
34+
with patch("charm.PostgresqlOperatorCharm.update_config") as _update_config:
4035
harness.charm.ldap._on_ldap_ready(mock_event)
4136
_update_config.assert_called_once()
4237

@@ -45,22 +40,6 @@ def test_on_ldap_ready_with_certificate(harness):
4540
assert "ldap_enabled" in app_databag
4641

4742

48-
def test_on_ldap_ready_without_certificate(harness):
49-
mock_event = MagicMock()
50-
51-
with (
52-
patch("charm.PostgresqlOperatorCharm.update_config") as _update_config,
53-
patch("charm.PostgreSQLLDAP.ca_transferred", new_callable=PropertyMock) as _ca_transferred,
54-
):
55-
_ca_transferred.return_value = False
56-
harness.charm.ldap._on_ldap_ready(mock_event)
57-
_update_config.assert_not_called()
58-
59-
peer_rel_id = harness.model.get_relation(PEER).id
60-
app_databag = harness.get_relation_data(peer_rel_id, harness.charm.app)
61-
assert "ldap_enabled" not in app_databag
62-
63-
6443
def test_on_ldap_unavailable(harness):
6544
mock_event = MagicMock()
6645

tests/unit/test_postgresql_provider.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright 2022 Canonical Ltd.
22
# See LICENSE file for licensing details.
33

4-
from unittest.mock import Mock, PropertyMock, patch
4+
from unittest.mock import Mock, PropertyMock, patch, sentinel
55

66
import pytest
77
from charms.postgresql_k8s.v0.postgresql import (
@@ -216,3 +216,27 @@ def test_on_relation_broken(harness):
216216
)
217217
harness.charm.postgresql_client_relation._on_relation_broken(event)
218218
postgresql_mock.delete_user.assert_not_called()
219+
220+
221+
def test_update_tls_flag(harness):
222+
with (
223+
patch("charm.PostgreSQLTLS.get_tls_files", return_value=(None, sentinel.ca, None)),
224+
patch(
225+
"relations.postgresql_provider.new_password", return_value="test-password"
226+
) as _new_password,
227+
patch(
228+
"relations.postgresql_provider.DatabaseProvides.fetch_relation_field",
229+
side_effect=[None, "db"],
230+
),
231+
patch(
232+
"relations.postgresql_provider.DatabaseProvides.set_tls",
233+
) as _set_tls,
234+
patch(
235+
"relations.postgresql_provider.DatabaseProvides.set_tls_ca",
236+
) as _set_tls_ca,
237+
):
238+
with harness.hooks_disabled():
239+
second_rel = harness.add_relation(RELATION_NAME, "second_app")
240+
harness.charm.postgresql_client_relation.update_tls_flag("True")
241+
_set_tls.assert_called_once_with(second_rel, "True")
242+
_set_tls_ca.assert_called_once_with(second_rel, sentinel.ca)

0 commit comments

Comments
 (0)