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,18 @@ 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 :
39
+ record = await default_kvs_client .get_record (_ALIAS_MAPPING_KEY )
40
+
41
+ if isinstance (record , dict ) and alias_key in record :
42
+ return str (record [alias_key ])
43
+
44
+ except Exception as exc :
47
45
# If there's any error accessing the record, treat it as not found
48
- logger .warning (f'Error accessing alias mapping for { alias } : { e } ' )
46
+ logger .warning (f'Error accessing alias mapping for { alias } : { exc } ' )
49
47
50
48
return None
51
49
@@ -66,11 +64,22 @@ async def store_alias_mapping(
66
64
"""
67
65
default_kvs_client = await _get_default_kvs_client (configuration )
68
66
69
- # Create the key for this alias (must match the format in resolve_alias_to_id)
67
+ # Create the dictionary key for this alias.
70
68
alias_key = f'alias-{ storage_type } -{ alias } '
71
69
72
- # Store the mapping
73
- await default_kvs_client .set_record (alias_key , {'value' : storage_id })
70
+ try :
71
+ record = await default_kvs_client .get_record (_ALIAS_MAPPING_KEY )
72
+
73
+ # Update or create the record with the new alias mapping
74
+ if isinstance (record , dict ) and alias_key in record :
75
+ record [alias_key ] = storage_id
76
+ else :
77
+ record = {alias_key : storage_id }
78
+
79
+ # Store the mapping back in the KVS.
80
+ await default_kvs_client .set_record (_ALIAS_MAPPING_KEY , record )
81
+ except Exception as exc :
82
+ logger .warning (f'Error accessing alias mapping for { alias } : { exc } ' )
74
83
75
84
76
85
async def _get_default_kvs_client (configuration : Configuration ) -> KeyValueStoreClientAsync :
0 commit comments