12
12
13
13
logger = getLogger (__name__ )
14
14
15
+ _ALIAS_MAPPING_KEY = '__STORAGE_ALIASES_MAPPING'
16
+
15
17
16
18
async def resolve_alias_to_id (
17
19
alias : str ,
@@ -30,22 +32,20 @@ async def resolve_alias_to_id(
30
32
"""
31
33
default_kvs_client = await _get_default_kvs_client (configuration )
32
34
33
- # Create the key for this alias
35
+ # Create the dictionary key for this alias.
34
36
alias_key = f'alias-{ storage_type } -{ alias } '
35
37
36
- # Try to get the stored ID for this alias
37
38
try :
38
- record = await default_kvs_client .get_record (alias_key )
39
- if record and record .get ('value' ):
40
- # The record structure is: {'value': {'value': 'storage_id'}}
41
- value_data = record ['value' ]
42
- if isinstance (value_data , dict ) and 'value' in value_data :
43
- storage_id = value_data ['value' ]
44
- if isinstance (storage_id , str ):
45
- return storage_id
46
- except Exception as e :
47
- # If there's any error accessing the record, treat it as not found
48
- logger .warning (f'Error accessing alias mapping for { alias } : { e } ' )
39
+ record = await default_kvs_client .get_record (_ALIAS_MAPPING_KEY )
40
+
41
+ # Extract the actual data from the KVS record
42
+ if isinstance (record , dict ) and alias_key in record :
43
+ storage_id = record [alias_key ]
44
+ return str (storage_id )
45
+
46
+ except Exception as exc :
47
+ # If there's any error accessing the record, treat it as not found.
48
+ logger .warning (f'Error accessing alias mapping for { alias } : { exc } ' )
49
49
50
50
return None
51
51
@@ -66,11 +66,22 @@ async def store_alias_mapping(
66
66
"""
67
67
default_kvs_client = await _get_default_kvs_client (configuration )
68
68
69
- # Create the key for this alias (must match the format in resolve_alias_to_id)
69
+ # Create the dictionary key for this alias.
70
70
alias_key = f'alias-{ storage_type } -{ alias } '
71
71
72
- # Store the mapping
73
- await default_kvs_client .set_record (alias_key , {'value' : storage_id })
72
+ try :
73
+ record = await default_kvs_client .get_record (_ALIAS_MAPPING_KEY )
74
+
75
+ # Update or create the record with the new alias mapping
76
+ if isinstance (record , dict ):
77
+ record [alias_key ] = storage_id
78
+ else :
79
+ record = {alias_key : storage_id }
80
+
81
+ # Store the mapping back in the KVS.
82
+ await default_kvs_client .set_record (_ALIAS_MAPPING_KEY , record )
83
+ except Exception as exc :
84
+ logger .warning (f'Error accessing alias mapping for { alias } : { exc } ' )
74
85
75
86
76
87
async def _get_default_kvs_client (configuration : Configuration ) -> KeyValueStoreClientAsync :
0 commit comments