Merge "Use library cloud_credentials v1.0" into main
This commit is contained in:
commit
b19fcbc9fd
@ -7,7 +7,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.v1.identity_service
|
||||
charmcraft fetch-lib charms.keystone_k8s.v0.cloud_credentials
|
||||
charmcraft fetch-lib charms.keystone_k8s.v1.cloud_credentials
|
||||
charmcraft fetch-lib charms.rabbitmq_k8s.v0.rabbitmq
|
||||
charmcraft fetch-lib charms.ovn_central_k8s.v0.ovsdb
|
||||
charmcraft fetch-lib charms.observability_libs.v0.kubernetes_service_patch
|
||||
|
@ -977,7 +977,7 @@ class CloudCredentialsRequiresHandler(RelationHandler):
|
||||
|
||||
def setup_event_handler(self) -> ops.charm.Object:
|
||||
"""Configure event handlers for cloud-credentials relation."""
|
||||
import charms.keystone_k8s.v0.cloud_credentials as cloud_credentials
|
||||
import charms.keystone_k8s.v1.cloud_credentials as cloud_credentials
|
||||
|
||||
logger.debug("Setting up the cloud-credentials event handler")
|
||||
credentials_service = cloud_credentials.CloudCredentialsRequires(
|
||||
|
@ -402,6 +402,9 @@ def add_cloud_credentials_relation_response(
|
||||
harness: Harness, rel_id: str
|
||||
) -> None:
|
||||
"""Add id service data to identity-service relation."""
|
||||
credentials_content = {"username": "username", "password": "user-password"}
|
||||
credentials_id = harness.add_model_secret("keystone", credentials_content)
|
||||
harness.grant_secret(credentials_id, harness.charm.app.name)
|
||||
harness.update_relation_data(
|
||||
rel_id,
|
||||
"keystone",
|
||||
@ -413,8 +416,7 @@ def add_cloud_credentials_relation_response(
|
||||
"internal-host": "keystone.internal",
|
||||
"internal-port": "5000",
|
||||
"internal-protocol": "http",
|
||||
"username": "username",
|
||||
"password": "user-password",
|
||||
"credentials": credentials_id,
|
||||
"project-name": "user-project",
|
||||
"project-id": "uproj-id",
|
||||
"user-domain-name": "udomain-name",
|
||||
|
@ -84,17 +84,20 @@ from ops.framework import (
|
||||
EventSource,
|
||||
Object,
|
||||
)
|
||||
from ops.model import Relation
|
||||
from ops.model import (
|
||||
Relation,
|
||||
SecretNotFoundError,
|
||||
)
|
||||
|
||||
# The unique Charmhub library identifier, never change it
|
||||
LIBID = "a5d96cc2686c47eea554ce2210c2d24e"
|
||||
|
||||
# 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__)
|
||||
|
||||
@ -165,7 +168,7 @@ class CloudCredentialsRequires(Object):
|
||||
logging.debug("CloudCredentials on_changed")
|
||||
try:
|
||||
self.on.ready.emit()
|
||||
except AttributeError:
|
||||
except (AttributeError, KeyError):
|
||||
logger.exception('Error when emitting event')
|
||||
|
||||
def _on_cloud_credentials_relation_broken(self, event):
|
||||
@ -218,15 +221,35 @@ class CloudCredentialsRequires(Object):
|
||||
"""Return the internal_protocol."""
|
||||
return self.get_remote_app_data('internal-protocol')
|
||||
|
||||
@property
|
||||
def credentials(self) -> str:
|
||||
return self.get_remote_app_data('credentials')
|
||||
|
||||
@property
|
||||
def username(self) -> str:
|
||||
"""Return the username."""
|
||||
return self.get_remote_app_data('username')
|
||||
credentials_id = self.get_remote_app_data('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 password(self) -> str:
|
||||
"""Return the password."""
|
||||
return self.get_remote_app_data('password')
|
||||
credentials_id = self.get_remote_app_data('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 project_name(self) -> str:
|
||||
@ -382,8 +405,7 @@ class CloudCredentialsProvides(Object):
|
||||
internal_host: str,
|
||||
internal_port: str,
|
||||
internal_protocol: str,
|
||||
username: str,
|
||||
password: str,
|
||||
credentials: str,
|
||||
project_name: str,
|
||||
project_id: str,
|
||||
user_domain_name: str,
|
||||
@ -407,8 +429,7 @@ class CloudCredentialsProvides(Object):
|
||||
app_data["internal-host"] = internal_host
|
||||
app_data["internal-port"] = str(internal_port)
|
||||
app_data["internal-protocol"] = internal_protocol
|
||||
app_data["username"] = username
|
||||
app_data["password"] = password
|
||||
app_data["credentials"] = credentials
|
||||
app_data["project-name"] = project_name
|
||||
app_data["project-id"] = project_id
|
||||
app_data["user-domain-name"] = user_domain_name
|
Loading…
x
Reference in New Issue
Block a user