Skip to content

Commit 2789802

Browse files
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 <[email protected]>
1 parent 8254069 commit 2789802

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/pybind/mgr/smb/mon_store.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def uri(self) -> str:
168168
# The rados:mon-config-key pseudo scheme is made up for the
169169
# purposes of communicating a key using the URI syntax with
170170
# other components, particularly the sambacc library.
171-
return f'rados:mon-config-key:{self._store_key}'
171+
return f'{self._store.SCHEME}:{self._store_key}'
172172

173173
@property
174174
def full_key(self) -> EntryKey:
@@ -191,6 +191,7 @@ class MonKeyConfigStore:
191191
"""
192192

193193
PREFIX = 'smb/config/'
194+
SCHEME = 'rados:mon-config-key'
194195

195196
def __init__(self, mc: MonCommandIssuer):
196197
self._mc = mc
@@ -282,3 +283,17 @@ def _rm(self, key: EntryKey) -> str:
282283
if ret != 0:
283284
raise KeyError(f'config-key rm {key!r} failed [{ret}]: {err}')
284285
return json_data
286+
287+
def lookup_uri(self, uri: str) -> MonKeyStoreEntry:
288+
_scheme = f'{self.SCHEME}:'
289+
if not uri.startswith(_scheme):
290+
raise ValueError(f'invalid uri: {uri}')
291+
slen = len(_scheme)
292+
path = uri[slen:]
293+
if not path.startswith(self.PREFIX):
294+
raise ValueError(f'invalid path: {path!r} from {uri}')
295+
plen = len(self.PREFIX)
296+
subpath = path[plen:]
297+
key = tuple(subpath.split('/', 1))
298+
assert len(key) == 2
299+
return self[key]

0 commit comments

Comments
 (0)