@@ -38,7 +38,10 @@ def __init__(self, storage_type: _StorageT, alias: str, token: str, api_url: str
3838 self .token = token
3939
4040 @classmethod
41- def get_additional_cache_key (cls , api_url : str , token : str ) -> str :
41+ def get_additional_cache_key (cls , api_url : str , token : str , * , encrypted : bool = False ) -> str :
42+ if not encrypted :
43+ return cls .ADDITIONAL_CACHE_KEY_SEPARATOR .join ([api_url , token ])
44+
4245 encryption_key = Configuration .get_global_configuration ().token
4346 if encryption_key is not None :
4447 encrypted_token = cls ._create_fernet (encryption_key ).encrypt (token .encode ()).decode ()
@@ -47,7 +50,7 @@ def get_additional_cache_key(cls, api_url: str, token: str) -> str:
4750
4851 @property
4952 def additional_cache_key (self ) -> str :
50- return self .get_additional_cache_key (self .api_url , self .token )
53+ return self .get_additional_cache_key (self .api_url , self .token , encrypted = False )
5154
5255 @classmethod
5356 def from_exported_string (cls , alias_as_string : str ) -> _Alias :
@@ -67,8 +70,14 @@ def from_exported_string(cls, alias_as_string: str) -> _Alias:
6770
6871 return cls (storage_type = storage_map [storage_class_name ], alias = alias , api_url = api_url , token = token )
6972
70- def __str__ (self ) -> str :
71- return self .ALIAS_SEPARATOR .join ([self .storage_type .__name__ , self .alias , self .additional_cache_key ])
73+ def get_storage_key (self ) -> str :
74+ return self .ALIAS_SEPARATOR .join (
75+ [
76+ self .storage_type .__name__ ,
77+ self .alias ,
78+ self .get_additional_cache_key (api_url = self .api_url , token = self .token , encrypted = True ),
79+ ]
80+ )
7281
7382 @staticmethod
7483 def _create_fernet (token : str ) -> Fernet :
@@ -91,10 +100,11 @@ async def store_mapping_to_apify_kvs(self, storage_id: str) -> None:
91100 record = record ['value' ]
92101
93102 # Update or create the record with the new alias mapping
103+
94104 if isinstance (record , dict ):
95- record [str ( self )] = storage_id
105+ record [self . get_storage_key ( )] = storage_id
96106 else :
97- record = {str ( self ): storage_id }
107+ record = {self . get_storage_key ( ): storage_id }
98108
99109 # Store the mapping back in the KVS.
100110 await default_kvs_client .set_record (_ALIAS_MAPPING_KEY , record )
0 commit comments