]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/cephadm: add --no-exception-when-missing flag to cert-store cert/key get 59860/head
authorAdam King <adking@redhat.com>
Wed, 18 Sep 2024 15:25:20 +0000 (11:25 -0400)
committerAdam King <adking@redhat.com>
Wed, 18 Sep 2024 15:25:20 +0000 (11:25 -0400)
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 <adking@redhat.com>
src/pybind/mgr/cephadm/module.py
src/pybind/mgr/orchestrator/_interface.py
src/pybind/mgr/orchestrator/module.py

index 0bca599961e33fe01256cbe1668d0920ba559113..356f346347173d9318175d65ca0245950e83021a 100644 (file)
@@ -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
 
index c33f38cfdd470f255e33d37f500a6db53971240d..9dc0aa7525a8a08ec684923d53711a1a37aebc01 100644 (file)
@@ -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()
 
index 3513992c7012e5f52fdc7598cafcfa69a9965377..12bbb227f00d6a99a8b069a055ea48aee7eadca4 100644 (file)
@@ -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)