@@ -38,7 +38,10 @@ def __init__(self, storage_type: _StorageT, alias: str, token: str, api_url: str
38
38
self .token = token
39
39
40
40
@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
+
42
45
encryption_key = Configuration .get_global_configuration ().token
43
46
if encryption_key is not None :
44
47
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:
47
50
48
51
@property
49
52
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 )
51
54
52
55
@classmethod
53
56
def from_exported_string (cls , alias_as_string : str ) -> _Alias :
@@ -67,8 +70,14 @@ def from_exported_string(cls, alias_as_string: str) -> _Alias:
67
70
68
71
return cls (storage_type = storage_map [storage_class_name ], alias = alias , api_url = api_url , token = token )
69
72
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
+ )
72
81
73
82
@staticmethod
74
83
def _create_fernet (token : str ) -> Fernet :
@@ -91,10 +100,11 @@ async def store_mapping_to_apify_kvs(self, storage_id: str) -> None:
91
100
record = record ['value' ]
92
101
93
102
# Update or create the record with the new alias mapping
103
+
94
104
if isinstance (record , dict ):
95
- record [str ( self )] = storage_id
105
+ record [self . get_storage_key ( )] = storage_id
96
106
else :
97
- record = {str ( self ): storage_id }
107
+ record = {self . get_storage_key ( ): storage_id }
98
108
99
109
# Store the mapping back in the KVS.
100
110
await default_kvs_client .set_record (_ALIAS_MAPPING_KEY , record )
0 commit comments