From c187b0d6e22e7b6b42e11572be358b31759d9f6b Mon Sep 17 00:00:00 2001 From: Adam King Date: Wed, 18 Sep 2024 11:25:20 -0400 Subject: [PATCH] mgr/cephadm: add --no-exception-when-missing flag to cert-store cert/key get This is mostly intended for automation that wants to check for these certificates and handle the results themselves. Without this flag an exception will be logged which isn't great for automation tools that may check for this repeatedly Signed-off-by: Adam King --- src/pybind/mgr/cephadm/module.py | 10 ++++++++-- src/pybind/mgr/orchestrator/_interface.py | 6 ++++-- src/pybind/mgr/orchestrator/module.py | 20 ++++++++++++++++---- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index 0bca599961e33..356f346347173 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -3264,10 +3264,13 @@ Then run the following: self, entity: str, service_name: Optional[str] = None, - hostname: Optional[str] = None + hostname: Optional[str] = None, + no_exception_when_missing: bool = False ) -> str: cert = self.cert_key_store.get_cert(entity, service_name or '', hostname or '') if not cert: + if no_exception_when_missing: + return '' raise OrchSecretNotFound(entity=entity, service_name=service_name, hostname=hostname) return cert @@ -3276,10 +3279,13 @@ Then run the following: self, entity: str, service_name: Optional[str] = None, - hostname: Optional[str] = None + hostname: Optional[str] = None, + no_exception_when_missing: bool = False ) -> str: key = self.cert_key_store.get_key(entity, service_name or '', hostname or '') if not key: + if no_exception_when_missing: + return '' raise OrchSecretNotFound(entity=entity, service_name=service_name, hostname=hostname) return key diff --git a/src/pybind/mgr/orchestrator/_interface.py b/src/pybind/mgr/orchestrator/_interface.py index c33f38cfdd470..9dc0aa7525a8a 100644 --- a/src/pybind/mgr/orchestrator/_interface.py +++ b/src/pybind/mgr/orchestrator/_interface.py @@ -561,7 +561,8 @@ class Orchestrator(object): self, entity: str, service_name: Optional[str] = None, - hostname: Optional[str] = None + hostname: Optional[str] = None, + no_exception_when_missing: bool = False ) -> OrchResult[str]: raise NotImplementedError() @@ -569,7 +570,8 @@ class Orchestrator(object): self, entity: str, service_name: Optional[str] = None, - hostname: Optional[str] = None + hostname: Optional[str] = None, + no_exception_when_missing: bool = False ) -> OrchResult[str]: raise NotImplementedError() diff --git a/src/pybind/mgr/orchestrator/module.py b/src/pybind/mgr/orchestrator/module.py index 3513992c7012e..12bbb227f00d6 100644 --- a/src/pybind/mgr/orchestrator/module.py +++ b/src/pybind/mgr/orchestrator/module.py @@ -1166,9 +1166,15 @@ class OrchestratorCli(OrchestratorClientMixin, MgrModule, entity: str, _end_positional_: int = 0, service_name: Optional[str] = None, - hostname: Optional[str] = None + hostname: Optional[str] = None, + no_exception_when_missing: bool = False ) -> HandleCommandResult: - completion = self.cert_store_get_cert(entity, service_name, hostname) + completion = self.cert_store_get_cert( + entity, + service_name, + hostname, + no_exception_when_missing + ) cert = raise_if_exception(completion) return HandleCommandResult(stdout=cert) @@ -1178,9 +1184,15 @@ class OrchestratorCli(OrchestratorClientMixin, MgrModule, entity: str, _end_positional_: int = 0, service_name: Optional[str] = None, - hostname: Optional[str] = None + hostname: Optional[str] = None, + no_exception_when_missing: bool = False ) -> HandleCommandResult: - completion = self.cert_store_get_key(entity, service_name, hostname) + completion = self.cert_store_get_key( + entity, + service_name, + hostname, + no_exception_when_missing + ) key = raise_if_exception(completion) return HandleCommandResult(stdout=key) -- 2.39.5