]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/smb: add a uri lookup func to the MonKeyConfigStore
authorJohn Mulligan <jmulligan@redhat.com>
Tue, 1 Jul 2025 23:08:24 +0000 (19:08 -0400)
committerAdam King <adking@redhat.com>
Thu, 21 Aug 2025 18:13:55 +0000 (14:13 -0400)
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 <jmulligan@redhat.com>
(cherry picked from commit 2789802fc147fb79c8ae28fecfa974db2f165721)

src/pybind/mgr/smb/mon_store.py

index 58700f1c4e11cb1bf8fa236e0383b6d9537cf9f8..e1fa4a8beb55c3d8fee94e54cd60af6e37cdfc2d 100644 (file)
@@ -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]