Skip to content

Commit a2f840e

Browse files
committed
chore: resolve linter issues (#498)
1 parent 8938374 commit a2f840e

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

src/apify/_consts.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@
88
BASE64_REGEXP = '[-A-Za-z0-9+/]*={0,3}'
99
ENCRYPTED_STRING_VALUE_PREFIX = 'ENCRYPTED_VALUE'
1010
ENCRYPTED_JSON_VALUE_PREFIX = 'ENCRYPTED_JSON'
11-
ENCRYPTED_INPUT_VALUE_REGEXP = re.compile(f'^({ENCRYPTED_STRING_VALUE_PREFIX}|{ENCRYPTED_JSON_VALUE_PREFIX}):(?:({BASE64_REGEXP}):)?({BASE64_REGEXP}):({BASE64_REGEXP})$')
11+
ENCRYPTED_INPUT_VALUE_REGEXP = re.compile(
12+
f'^({ENCRYPTED_STRING_VALUE_PREFIX}|{ENCRYPTED_JSON_VALUE_PREFIX}):(?:({BASE64_REGEXP}):)?({BASE64_REGEXP}):({BASE64_REGEXP})$'
13+
)

src/apify/_crypto.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from apify_shared.utils import ignore_docs
1616
from crawlee._utils.crypto import crypto_random_object_id
1717

18-
from apify._consts import ENCRYPTED_INPUT_VALUE_REGEXP, ENCRYPTED_STRING_VALUE_PREFIX, ENCRYPTED_JSON_VALUE_PREFIX
18+
from apify._consts import ENCRYPTED_INPUT_VALUE_REGEXP, ENCRYPTED_JSON_VALUE_PREFIX, ENCRYPTED_STRING_VALUE_PREFIX
1919

2020
ENCRYPTION_KEY_LENGTH = 32
2121
ENCRYPTION_IV_LENGTH = 16

tests/unit/actor/test_actor_key_value_store.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from ..test_crypto import PRIVATE_KEY_PASSWORD, PRIVATE_KEY_PEM_BASE64, PUBLIC_KEY
1111
from apify import Actor
12-
from apify._consts import ENCRYPTED_STRING_VALUE_PREFIX, ENCRYPTED_JSON_VALUE_PREFIX
12+
from apify._consts import ENCRYPTED_JSON_VALUE_PREFIX, ENCRYPTED_STRING_VALUE_PREFIX
1313
from apify._crypto import public_encrypt
1414

1515
if TYPE_CHECKING:
@@ -79,9 +79,9 @@ async def test_get_input_with_encrypted_secrets(
7979
secret_object = {'foo': 'bar', 'baz': 'qux'}
8080
secret_array = ['foo', 'bar', 'baz']
8181

82-
# The legacy encryption format uses ENCRYPTED_STRING_VALUE_PREFIX prefix, value in raw string and does not include schemahash.
83-
# The new format uses ENCRYPTED_JSON_VALUE_PREFIX prefix, value in JSON format and includes schemahash.
84-
# We are testing both formats to ensure backward compatibility.
82+
# The legacy encryption format uses ENCRYPTED_STRING_VALUE_PREFIX prefix, value in raw string and does
83+
# not include schemahash. The new format uses ENCRYPTED_JSON_VALUE_PREFIX prefix, value in JSON format
84+
# and includes schemahash. We are testing both formats to ensure backward compatibility.
8585

8686
encrypted_string_legacy = public_encrypt(secret_string_legacy, public_key=PUBLIC_KEY)
8787
encrypted_string = public_encrypt(json_dumps(secret_string), public_key=PUBLIC_KEY)
@@ -90,10 +90,26 @@ async def test_get_input_with_encrypted_secrets(
9090

9191
input_with_secret = {
9292
'foo': 'bar',
93-
'secret_string_legacy': f'{ENCRYPTED_STRING_VALUE_PREFIX}:{encrypted_string_legacy["encrypted_password"]}:{encrypted_string_legacy["encrypted_value"]}',
94-
'secret_string': f'{ENCRYPTED_JSON_VALUE_PREFIX}:schemahash:{encrypted_string["encrypted_password"]}:{encrypted_string["encrypted_value"]}',
95-
'secret_object': f'{ENCRYPTED_JSON_VALUE_PREFIX}:schemahash:{encrypted_object["encrypted_password"]}:{encrypted_object["encrypted_value"]}',
96-
'secret_array': f'{ENCRYPTED_JSON_VALUE_PREFIX}:schemahash:{encrypted_array["encrypted_password"]}:{encrypted_array["encrypted_value"]}',
93+
'secret_string_legacy': (
94+
f'{ENCRYPTED_STRING_VALUE_PREFIX}:'
95+
f'{encrypted_string_legacy["encrypted_password"]}:'
96+
f'{encrypted_string_legacy["encrypted_value"]}'
97+
),
98+
'secret_string': (
99+
f'{ENCRYPTED_JSON_VALUE_PREFIX}:schemahash:'
100+
f'{encrypted_string["encrypted_password"]}:'
101+
f'{encrypted_string["encrypted_value"]}'
102+
),
103+
'secret_object': (
104+
f'{ENCRYPTED_JSON_VALUE_PREFIX}:schemahash:'
105+
f'{encrypted_object["encrypted_password"]}:'
106+
f'{encrypted_object["encrypted_value"]}'
107+
),
108+
'secret_array': (
109+
f'{ENCRYPTED_JSON_VALUE_PREFIX}:schemahash:'
110+
f'{encrypted_array["encrypted_password"]}:'
111+
f'{encrypted_array["encrypted_value"]}'
112+
),
97113
}
98114

99115
await memory_storage_client.key_value_stores().get_or_create(id='default')

0 commit comments

Comments
 (0)