From: Adam King Date: Wed, 18 Sep 2024 15:25:20 +0000 (-0400) Subject: mgr/cephadm: add --no-exception-when-missing flag to cert-store cert/key get X-Git-Tag: v19.2.1~67^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=652fff986dc346203572675e953cd5979d7f6682;p=ceph.git 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 (cherry picked from commit c187b0d6e22e7b6b42e11572be358b31759d9f6b) --- diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index bebd6361a27..d480bd6959a 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -3145,10 +3145,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 @@ -3157,10 +3160,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 e7f94f7c74b..ab42e7fe3b4 100644 --- a/src/pybind/mgr/orchestrator/_interface.py +++ b/src/pybind/mgr/orchestrator/_interface.py @@ -567,7 +567,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() @@ -575,7 +576,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 6558ae2eb38..d4f3aadcf3e 100644 --- a/src/pybind/mgr/orchestrator/module.py +++ b/src/pybind/mgr/orchestrator/module.py @@ -1173,9 +1173,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) @@ -1185,9 +1191,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)