From 41399f501e6b66b306159aca38d7c343cf60a29c Mon Sep 17 00:00:00 2001 From: Hemanth Nakkina Date: Fri, 13 Dec 2024 16:33:44 +0530 Subject: [PATCH] [keystone-k8s] fix list-ca-certs action result list-ca-certs action considers part of name as dictionary key if name contains '.'. This is due to ops flattening the event result [1]. Replace '.' with '-' Closes-Bug: #2091691 [1] https://github.com/canonical/operator/blob/e573f8f39c6b11470dcae3ac94ad798e4655ee91/ops/charm.py#L170 Change-Id: I7f4d22bc978c606496c25187f4892dc47f6472ad --- charms/keystone-k8s/charmcraft.yaml | 3 ++- charms/keystone-k8s/src/charm.py | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/charms/keystone-k8s/charmcraft.yaml b/charms/keystone-k8s/charmcraft.yaml index 7e88df23..012bf66b 100644 --- a/charms/keystone-k8s/charmcraft.yaml +++ b/charms/keystone-k8s/charmcraft.yaml @@ -105,7 +105,8 @@ actions: additionalProperties: false list-ca-certs: description: | - List CA certs uploaded for transfer + List CA certs uploaded for transfer. + Certificate names with `.` will be replace with `-`. containers: keystone: diff --git a/charms/keystone-k8s/src/charm.py b/charms/keystone-k8s/src/charm.py index 66553725..ef0c589c 100755 --- a/charms/keystone-k8s/src/charm.py +++ b/charms/keystone-k8s/src/charm.py @@ -631,6 +631,16 @@ export OS_AUTH_VERSION=3 self.peers.get_app_data(CERTIFICATE_TRANSFER_LABEL) or "{}" ) certificates = json.loads(certificates_str) + + # Replace '.' in certificate names with '-' + # This is due to the way ops flatten the results dictionary + # https://github.com/canonical/operator/blob/e573f8f39c6b11470dcae3ac94ad798e4655ee91/ops/charm.py#L170 + names_with_dot = [k for k, v in certificates.items() if "." in k] + for name in names_with_dot: + name_ = name.replace(".", "-") + certificates[name_] = certificates[name] + certificates.pop(name) + event.set_results(certificates) def _on_peer_data_changed(self, event: RelationChangedEvent):