From 8af7aad79f8a2fde443a3953112a1b7335807a70 Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Mon, 17 Mar 2025 16:10:15 -0400 Subject: [PATCH] mgr/smb: extend password filtering to cluster commands The imperative commands like `ceph smb cluster create` may involve setting and reporting outputs that have passwords. Use the previously established password filter mechanism there (and use the new _apply_res function everywhere for completeness). Signed-off-by: John Mulligan --- src/pybind/mgr/smb/module.py | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/pybind/mgr/smb/module.py b/src/pybind/mgr/smb/module.py index b140ed172e7..b368268c188 100644 --- a/src/pybind/mgr/smb/module.py +++ b/src/pybind/mgr/smb/module.py @@ -145,6 +145,7 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule): def _apply_res( self, resource_input: List[resources.SMBResource], + create_only: bool = False, password_filter: InputPasswordFilter = InputPasswordFilter.NONE, password_filter_out: Optional[PasswordFilter] = None, ) -> results.ResultGroup: @@ -155,7 +156,9 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule): in_op = (in_pf, PasswordFilter.NONE) log.debug('Password filtering for resource apply: %r', in_op) resource_input = [r.convert(in_op) for r in resource_input] - all_results = self._handler.apply(resource_input) + all_results = self._handler.apply( + resource_input, create_only=create_only + ) if out_pf is not PasswordFilter.NONE: # we need to apply the conversion filter to the output # resources in the results - otherwise we would show raw @@ -208,6 +211,8 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule): placement: Optional[str] = None, clustering: Optional[SMBClustering] = None, public_addrs: Optional[List[str]] = None, + password_filter: InputPasswordFilter = InputPasswordFilter.NONE, + password_filter_out: Optional[PasswordFilter] = None, ) -> results.Result: """Create an smb cluster""" domain_settings = None @@ -318,13 +323,24 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule): public_addrs=c_public_addrs, ) to_apply.append(cluster) - return self._handler.apply(to_apply, create_only=True).squash(cluster) + return self._apply_res( + to_apply, + create_only=True, + password_filter=password_filter, + password_filter_out=password_filter_out, + ).squash(cluster) @cli.SMBCommand('cluster rm', perm='rw') - def cluster_rm(self, cluster_id: str) -> results.Result: + def cluster_rm( + self, + cluster_id: str, + password_filter: PasswordFilter = PasswordFilter.NONE, + ) -> results.Result: """Remove an smb cluster""" cluster = resources.RemovedCluster(cluster_id=cluster_id) - return self._handler.apply([cluster]).one() + return self._apply_res( + [cluster], password_filter_out=password_filter + ).one() @cli.SMBCommand('share ls', perm='r') def share_ls(self, cluster_id: str) -> List[str]: @@ -360,7 +376,7 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule): subvolume=subvolume, ), ) - return self._handler.apply([share], create_only=True).one() + return self._apply_res([share], create_only=True).one() @cli.SMBCommand('share rm', perm='rw') def share_rm(self, cluster_id: str, share_id: str) -> results.Result: @@ -368,7 +384,7 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule): share = resources.RemovedShare( cluster_id=cluster_id, share_id=share_id ) - return self._handler.apply([share]).one() + return self._apply_res([share]).one() @cli.SMBCommand("show", perm="r") def show( -- 2.39.5