]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr/smb: add support for password conversion/filtering to results types
authorJohn Mulligan <jmulligan@redhat.com>
Wed, 12 Mar 2025 21:33:04 +0000 (17:33 -0400)
committerJohn Mulligan <jmulligan@redhat.com>
Tue, 1 Apr 2025 12:02:39 +0000 (08:02 -0400)
Because these results types embed resources and these are used to
display output of commands we want to ensure that they support password
conversion/filtering too.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
src/pybind/mgr/smb/results.py

index b62d6e66377684261e3b409e10da98c46643ac78..b8fcadf722c3dd93271d605bff60e90bf91a094f 100644 (file)
@@ -2,8 +2,8 @@ from typing import Iterable, Iterator, List, Optional
 
 import errno
 
-from .proto import Simplified
-from .resources import SMBResource
+from .proto import Self, Simplified
+from .resources import ConversionOp, SMBResource
 from .utils import one
 
 _DOMAIN = 'domain'
@@ -44,6 +44,14 @@ class Result:
             return ""
         return "resource failed to apply (see response data for details)"
 
+    def replace_resource(self, resource: SMBResource) -> Self:
+        return self.__class__(
+            src=resource,
+            success=self.success,
+            msg=self.msg,
+            status=self.status,
+        )
+
 
 class ErrorResult(Result, Exception):
     """A Result subclass for wrapping an error condition."""
@@ -135,3 +143,14 @@ class ResultGroup:
         ct = sum(0 if r.success else 1 for r in self._contents)
         s = '' if ct <= 1 else 's'
         return f"{ct} resource{s} failed to apply (see response data for details)"
+
+    def convert_results(self, operation: ConversionOp) -> Self:
+        """Apply a conversion operation to all the resources in the result group
+        returning a new result group with all the results updated.
+        """
+        return self.__class__(
+            initial_results=[
+                result.replace_resource(result.src.convert(operation))
+                for result in self._contents
+            ]
+        )