From: John Mulligan Date: Tue, 1 Jul 2025 23:08:24 +0000 (-0400) Subject: mgr/smb: add a uri lookup func to the MonKeyConfigStore X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=2789802fc147fb79c8ae28fecfa974db2f165721;p=ceph.git mgr/smb: add a uri lookup func to the MonKeyConfigStore Add a new lookup_uri function to the MonKeyConfigStore - this allows the store to return an entry given a URI. The URIs in the stores are typically used to communicate to components outside the mgr module. But there are occasions that we have a uri and want to look it up instead of using a key. Signed-off-by: John Mulligan --- diff --git a/src/pybind/mgr/smb/mon_store.py b/src/pybind/mgr/smb/mon_store.py index 58700f1c4e11..e1fa4a8beb55 100644 --- a/src/pybind/mgr/smb/mon_store.py +++ b/src/pybind/mgr/smb/mon_store.py @@ -168,7 +168,7 @@ class MonKeyStoreEntry: # The rados:mon-config-key pseudo scheme is made up for the # purposes of communicating a key using the URI syntax with # other components, particularly the sambacc library. - return f'rados:mon-config-key:{self._store_key}' + return f'{self._store.SCHEME}:{self._store_key}' @property def full_key(self) -> EntryKey: @@ -191,6 +191,7 @@ class MonKeyConfigStore: """ PREFIX = 'smb/config/' + SCHEME = 'rados:mon-config-key' def __init__(self, mc: MonCommandIssuer): self._mc = mc @@ -282,3 +283,17 @@ class MonKeyConfigStore: if ret != 0: raise KeyError(f'config-key rm {key!r} failed [{ret}]: {err}') return json_data + + def lookup_uri(self, uri: str) -> MonKeyStoreEntry: + _scheme = f'{self.SCHEME}:' + if not uri.startswith(_scheme): + raise ValueError(f'invalid uri: {uri}') + slen = len(_scheme) + path = uri[slen:] + if not path.startswith(self.PREFIX): + raise ValueError(f'invalid path: {path!r} from {uri}') + plen = len(self.PREFIX) + subpath = path[plen:] + key = tuple(subpath.split('/', 1)) + assert len(key) == 2 + return self[key]