]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/cephadm: add --no-exception-when-missing flag to cert-store cert/key get 59935/head
authorAdam King <adking@redhat.com>
Wed, 18 Sep 2024 15:25:20 +0000 (11:25 -0400)
committerAdam King <adking@redhat.com>
Mon, 23 Sep 2024 15:52:40 +0000 (11:52 -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>
(cherry picked from commit c187b0d6e22e7b6b42e11572be358b31759d9f6b)

src/pybind/mgr/cephadm/module.py
src/pybind/mgr/orchestrator/_interface.py
src/pybind/mgr/orchestrator/module.py

index bebd6361a27cf96aa00723832651829fd46bfea2..d480bd6959a0d093491975300ebfdc340b29b497 100644 (file)
@@ -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
 
index e7f94f7c74b34b82389eba81464253f654b13543..ab42e7fe3b44d4d50a3428abb621efe1edb95fda 100644 (file)
@@ -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()
 
index 6558ae2eb38f41ed0bd3713fad96f26ba2082672..d4f3aadcf3e8830705d20e5cc2db1c8de496dbc2 100644 (file)
@@ -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)