From: John Mulligan Date: Wed, 12 Mar 2025 21:33:04 +0000 (-0400) Subject: mgr/smb: add support for password conversion/filtering to results types X-Git-Tag: testing/wip-vshankar-testing-20250407.170244-debug~31^2~7 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=f7b281b8c9ea817e6a6b99a20916b158b75ea275;p=ceph-ci.git mgr/smb: add support for password conversion/filtering to results types 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 --- diff --git a/src/pybind/mgr/smb/results.py b/src/pybind/mgr/smb/results.py index b62d6e66377..b8fcadf722c 100644 --- a/src/pybind/mgr/smb/results.py +++ b/src/pybind/mgr/smb/results.py @@ -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 + ] + )