From: John Mulligan Date: Mon, 2 Mar 2026 21:09:16 +0000 (-0500) Subject: mgr/smb: reimplement part of the _search_resources function X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=d5f37cd591ae03100e1db4e9e79d7a50d0e1e4ab;p=ceph.git mgr/smb: reimplement part of the _search_resources function Reimplement part of the _search_resources function to avoid using yet another static mapping between the SMBResource type and it's partner entry type which is one more place you forget to update when you add a new type. Now, the type mapping is based on the matcher class and the typ mapping function provided by the internal.py module. Fixes: 5712016c2133870da3f704d8457358ad06efc87f Signed-off-by: John Mulligan --- diff --git a/src/pybind/mgr/smb/handler.py b/src/pybind/mgr/smb/handler.py index 35c371652bd..9feea2df828 100644 --- a/src/pybind/mgr/smb/handler.py +++ b/src/pybind/mgr/smb/handler.py @@ -8,6 +8,7 @@ from typing import ( Optional, Set, Tuple, + Type, Union, cast, ) @@ -33,11 +34,13 @@ from .enums import ( ) from .internal import ( ClusterEntry, + CommonResourceEntry, ExternalCephClusterEntry, JoinAuthEntry, ShareEntry, TLSCredentialEntry, UsersAndGroupsEntry, + map_resource_entry, ) from .proto import ( AccessAuthorizer, @@ -238,6 +241,9 @@ class _Matcher: f'{txt!r} does not match a valid resource type' ) + def resources(self) -> List[Type[SMBResource]]: + return list(self._match_resources) + class ClusterConfigHandler: """The central class for ingesting and handling smb configuration change @@ -382,6 +388,7 @@ class ClusterConfigHandler: def _search_resources(self, matcher: _Matcher) -> List[SMBResource]: log.debug("performing search with matcher: %s", matcher) out: List[SMBResource] = [] + # clusters and shares (with parent-child relationship) if resources.Cluster in matcher or resources.Share in matcher: log.debug("searching for clusters and/or shares") cluster_shares = self.share_ids_by_cluster() @@ -395,21 +402,20 @@ class ClusterConfigHandler: cluster_id, share_id ).get_share() ) - _resources = ( - (resources.JoinAuth, JoinAuthEntry), - (resources.UsersAndGroups, UsersAndGroupsEntry), - (resources.TLSCredential, TLSCredentialEntry), - ) - for rtype, ecls in _resources: - if rtype in matcher: - log.debug("searching for %s", cast(Any, rtype).resource_type) - out.extend( - ecls.from_store( - self.internal_store, rid - ).get_resource_type(rtype) - for rid in ecls.ids(self.internal_store) - if (rtype, rid) in matcher - ) + # other common top-level resources + for rtype in matcher.resources(): + if rtype in (resources.Cluster, resources.Share): + continue # already handled above + if rtype not in matcher: + continue + log.debug("searching for %s", cast(Any, rtype).resource_type) + ecls = map_resource_entry(rtype) + assert issubclass(ecls, CommonResourceEntry) + for rid in ecls.ids(self.internal_store): + if (rtype, rid) in matcher: + entry = ecls.from_store(self.internal_store, rid) + res = entry.get_resource_type(rtype) + out.append(cast(SMBResource, res)) log.debug("search found %d resources", len(out)) return out