|
30 | 30 | from typing import Optional
|
31 | 31 |
|
32 | 32 | from b2sdk.v1 import B2Api, InMemoryAccountInfo, InMemoryCache, fix_windows_path_limit
|
33 |
| -from b2sdk.v1 import EncryptionAlgorithm, EncryptionMode, EncryptionSetting, EncryptionKey |
| 33 | +from b2sdk.v1 import EncryptionAlgorithm, EncryptionMode, EncryptionSetting, EncryptionKey, SSE_C_KEY_ID_FILE_INFO_KEY_NAME |
34 | 34 |
|
35 | 35 | SSE_NONE = EncryptionSetting(mode=EncryptionMode.NONE,)
|
36 | 36 | SSE_B2_AES = EncryptionSetting(
|
@@ -138,7 +138,7 @@ def remove_warnings(text):
|
138 | 138 | )
|
139 | 139 |
|
140 | 140 |
|
141 |
| -def run_command(cmd, args, additional_env: Optional[dict]): |
| 141 | +def run_command(cmd, args, additional_env: Optional[dict] = None): |
142 | 142 | """
|
143 | 143 | :param cmd: a command to run
|
144 | 144 | :param args: command's arguments
|
@@ -166,7 +166,7 @@ def run_command(cmd, args, additional_env: Optional[dict]):
|
166 | 166 | stdout=subprocess.PIPE,
|
167 | 167 | stderr=subprocess.PIPE,
|
168 | 168 | close_fds=platform.system() != 'Windows',
|
169 |
| - env=env |
| 169 | + env=env, |
170 | 170 | )
|
171 | 171 | p.stdin.close()
|
172 | 172 | reader1 = threading.Thread(target=stdout.read_from, args=[p.stdout])
|
@@ -665,12 +665,15 @@ def encryption_summary(sse_dict, file_info):
|
665 | 665 | if isinstance(sse_dict, EncryptionSetting):
|
666 | 666 | sse_dict = sse_dict.as_dict()
|
667 | 667 | encryption = sse_dict['mode']
|
| 668 | + assert encryption in ( |
| 669 | + EncryptionMode.NONE.value, EncryptionMode.SSE_B2.value, EncryptionMode.SSE_C.value |
| 670 | + ) |
668 | 671 | algorithm = sse_dict.get('algorithm')
|
669 | 672 | if algorithm is not None:
|
670 | 673 | encryption += ':' + algorithm
|
671 | 674 | if sse_dict['mode'] == 'SSE-C':
|
672 |
| - sse_c_key_id = file_info.get('sse_c_key_id') |
673 |
| - encryption += '?' + 'sse_c_key_id=' + str(sse_c_key_id) |
| 675 | + sse_c_key_id = file_info.get(SSE_C_KEY_ID_FILE_INFO_KEY_NAME) |
| 676 | + encryption += '?%s=%s' % (SSE_C_KEY_ID_FILE_INFO_KEY_NAME, sse_c_key_id) |
674 | 677 |
|
675 | 678 | return encryption
|
676 | 679 |
|
@@ -743,7 +746,8 @@ def sync_up_helper(b2_tool, bucket_name, dir_, encryption=None):
|
743 | 746 | 'B2_DESTINATION_SSE_C_KEY_ID': SSE_C_AES.key.key_id,
|
744 | 747 | }
|
745 | 748 | expected_encryption_str = encryption_summary(
|
746 |
| - expected_encryption.as_dict(), {'sse_c_key_id': SSE_C_AES.key.key_id} |
| 749 | + expected_encryption.as_dict(), |
| 750 | + {SSE_C_KEY_ID_FILE_INFO_KEY_NAME: SSE_C_AES.key.key_id} |
747 | 751 | )
|
748 | 752 | else:
|
749 | 753 | raise NotImplementedError('unsupported encryption mode: %s' % encryption)
|
@@ -1161,7 +1165,8 @@ def sync_copy_helper(
|
1161 | 1165 | }
|
1162 | 1166 | )
|
1163 | 1167 | expected_encryption_str = encryption_summary(
|
1164 |
| - expected_encryption.as_dict(), {'sse_c_key_id': destination_encryption.key.key_id} |
| 1168 | + expected_encryption.as_dict(), |
| 1169 | + {SSE_C_KEY_ID_FILE_INFO_KEY_NAME: destination_encryption.key.key_id} |
1165 | 1170 | )
|
1166 | 1171 |
|
1167 | 1172 | else:
|
@@ -1341,7 +1346,8 @@ def sse_c_test(b2_tool, bucket_name):
|
1341 | 1346 | }, file_version_info['serverSideEncryption']
|
1342 | 1347 | )
|
1343 | 1348 | should_equal(
|
1344 |
| - 'user-generated-key-id \nąóźćż\nœøΩ≈ç\nßäöü', file_version_info['fileInfo']['sse_c_key_id'] |
| 1349 | + 'user-generated-key-id \nąóźćż\nœøΩ≈ç\nßäöü', |
| 1350 | + file_version_info['fileInfo'][SSE_C_KEY_ID_FILE_INFO_KEY_NAME] |
1345 | 1351 | )
|
1346 | 1352 |
|
1347 | 1353 | b2_tool.should_fail(
|
@@ -1498,9 +1504,12 @@ def sse_c_test(b2_tool, bucket_name):
|
1498 | 1504 | sorted(
|
1499 | 1505 | [
|
1500 | 1506 | {
|
1501 |
| - 'sse_c_key_id': f['fileInfo'].get('sse_c_key_id', 'missing_key'), |
1502 |
| - 'serverSideEncryption': f['serverSideEncryption'], |
1503 |
| - 'file_name': f['fileName'] |
| 1507 | + 'sse_c_key_id': |
| 1508 | + f['fileInfo'].get(SSE_C_KEY_ID_FILE_INFO_KEY_NAME, 'missing_key'), |
| 1509 | + 'serverSideEncryption': |
| 1510 | + f['serverSideEncryption'], |
| 1511 | + 'file_name': |
| 1512 | + f['fileName'] |
1504 | 1513 | } for f in list_of_files
|
1505 | 1514 | ],
|
1506 | 1515 | key=lambda r: r['file_name']
|
|
0 commit comments