diff --git a/ops-sunbeam/fetch-libs.sh b/ops-sunbeam/fetch-libs.sh index c9909fbd..d38a620a 100755 --- a/ops-sunbeam/fetch-libs.sh +++ b/ops-sunbeam/fetch-libs.sh @@ -6,7 +6,7 @@ echo "WARNING: Charm interface libs are excluded from ASO python package." charmcraft fetch-lib charms.nginx_ingress_integrator.v0.ingress charmcraft fetch-lib charms.data_platform_libs.v0.database_requires -charmcraft fetch-lib charms.keystone_k8s.v0.identity_service +charmcraft fetch-lib charms.keystone_k8s.v1.identity_service charmcraft fetch-lib charms.keystone_k8s.v0.cloud_credentials charmcraft fetch-lib charms.rabbitmq_k8s.v0.rabbitmq charmcraft fetch-lib charms.ovn_central_k8s.v0.ovsdb diff --git a/ops-sunbeam/ops_sunbeam/relation_handlers.py b/ops-sunbeam/ops_sunbeam/relation_handlers.py index be50dcda..994fc04f 100644 --- a/ops-sunbeam/ops_sunbeam/relation_handlers.py +++ b/ops-sunbeam/ops_sunbeam/relation_handlers.py @@ -459,7 +459,7 @@ class IdentityServiceRequiresHandler(RelationHandler): def setup_event_handler(self) -> ops.charm.Object: """Configure event handlers for an Identity service relation.""" logger.debug("Setting up Identity Service event handler") - import charms.keystone_k8s.v0.identity_service as sun_id + import charms.keystone_k8s.v1.identity_service as sun_id id_svc = sun_id.IdentityServiceRequires( self.charm, self.relation_name, self.service_endpoints, self.region diff --git a/ops-sunbeam/ops_sunbeam/test_utils.py b/ops-sunbeam/ops_sunbeam/test_utils.py index ad9f6eb0..10d8cb37 100644 --- a/ops-sunbeam/ops_sunbeam/test_utils.py +++ b/ops-sunbeam/ops_sunbeam/test_utils.py @@ -358,6 +358,9 @@ def add_identity_service_relation_response( harness: Harness, rel_id: str ) -> None: """Add id service data to identity-service relation.""" + credentials_content = {"username": "svcuser1", "password": "svcpass1"} + credentials_id = harness.add_model_secret("keystone", credentials_content) + harness.grant_secret(credentials_id, "my-service") harness.update_relation_data( rel_id, "keystone", @@ -375,12 +378,13 @@ def add_identity_service_relation_response( "service-domain": "servicedom", "service-domain_id": "svcdomid1", "service-host": "keystone.service", - "service-password": "svcpass1", + # "service-password": "svcpass1", "service-port": "5000", "service-protocol": "http", "service-project": "svcproj1", "service-project-id": "svcprojid1", - "service-user-name": "svcuser1", + # "service-user-name": "svcuser1", + "service-credentials": credentials_id, }, ) diff --git a/ops-sunbeam/unit_tests/lib/charms/keystone_k8s/v0/identity_service.py b/ops-sunbeam/unit_tests/lib/charms/keystone_k8s/v1/identity_service.py similarity index 92% rename from ops-sunbeam/unit_tests/lib/charms/keystone_k8s/v0/identity_service.py rename to ops-sunbeam/unit_tests/lib/charms/keystone_k8s/v1/identity_service.py index 8f80a191..35556622 100644 --- a/ops-sunbeam/unit_tests/lib/charms/keystone_k8s/v0/identity_service.py +++ b/ops-sunbeam/unit_tests/lib/charms/keystone_k8s/v1/identity_service.py @@ -26,7 +26,7 @@ Two events are also available to respond to: A basic example showing the usage of this relation follows: ``` -from charms.sunbeam_keystone_operator.v0.identity_service import IdentityServiceRequires +from charms.keystone_k8s.v1.identity_service import IdentityServiceRequires class IdentityServiceClientCharm(CharmBase): def __init__(self, *args): @@ -85,7 +85,10 @@ from ops.framework import ( EventSource, Object, ) -from ops.model import Relation +from ops.model import ( + Relation, + SecretNotFoundError, +) logger = logging.getLogger(__name__) @@ -93,11 +96,11 @@ logger = logging.getLogger(__name__) LIBID = "0fa7fe7236c14c6e9624acf232b9a3b0" # Increment this major API version when introducing breaking changes -LIBAPI = 0 +LIBAPI = 1 # Increment this PATCH version before using `charmcraft publish-lib` or reset # to 0 if you are raising the major API version -LIBPATCH = 1 +LIBPATCH = 0 logger = logging.getLogger(__name__) @@ -175,7 +178,7 @@ class IdentityServiceRequires(Object): try: self.service_password self.on.ready.emit() - except AttributeError: + except (AttributeError, KeyError): pass def _on_identity_service_relation_broken(self, event): @@ -273,10 +276,24 @@ class IdentityServiceRequires(Object): """Return the service_host.""" return self.get_remote_app_data('service-host') + @property + def service_credentials(self) -> str: + """Return the service_credentials secret.""" + return self.get_remote_app_data('service-credentials') + @property def service_password(self) -> str: """Return the service_password.""" - return self.get_remote_app_data('service-password') + credentials_id = self.get_remote_app_data('service-credentials') + if not credentials_id: + return None + + try: + credentials = self.charm.model.get_secret(id=credentials_id) + return credentials.get_content().get("password") + except SecretNotFoundError: + logger.warning(f"Secret {credentials_id} not found") + return None @property def service_port(self) -> str: @@ -301,7 +318,16 @@ class IdentityServiceRequires(Object): @property def service_user_name(self) -> str: """Return the service_user_name.""" - return self.get_remote_app_data('service-user-name') + credentials_id = self.get_remote_app_data('service-credentials') + if not credentials_id: + return None + + try: + credentials = self.charm.model.get_secret(id=credentials_id) + return credentials.get_content().get("username") + except SecretNotFoundError: + logger.warning(f"Secret {credentials_id} not found") + return None @property def service_user_id(self) -> str: @@ -450,12 +476,12 @@ class IdentityServiceProvides(Object): admin_project: str, admin_user: str, service_domain: str, - service_password: str, service_project: str, service_user: str, internal_auth_url: str, admin_auth_url: str, - public_auth_url: str): + public_auth_url: str, + service_credentials: str): logging.debug("Setting identity_service connection information.") _identity_service_rel = None for relation in self.framework.model.relations[relation_name]: @@ -485,9 +511,8 @@ class IdentityServiceProvides(Object): app_data["service-domain-id"] = service_domain.id app_data["service-project-name"] = service_project.name app_data["service-project-id"] = service_project.id - app_data["service-user-name"] = service_user.name app_data["service-user-id"] = service_user.id - app_data["service-password"] = service_password app_data["internal-auth-url"] = internal_auth_url app_data["admin-auth-url"] = admin_auth_url app_data["public-auth-url"] = public_auth_url + app_data["service-credentials"] = service_credentials