Revision 133e3fcf snf-pithos-app/pithos/api/functions.py
b/snf-pithos-app/pithos/api/functions.py | ||
---|---|---|
55 | 55 |
copy_or_move_object, get_int_parameter, get_content_length, |
56 | 56 |
get_content_range, socket_read_iterator, SaveToBackendHandler, |
57 | 57 |
object_data_response, put_object_block, hashmap_md5, simple_list_response, |
58 |
api_method, is_uuid, |
|
59 |
retrieve_uuid, retrieve_uuids, retrieve_displaynames, |
|
60 |
get_pithos_usage |
|
58 |
api_method, is_uuid, retrieve_uuid, retrieve_uuids, |
|
59 |
retrieve_displaynames, get_pithos_usage, Checksum, NoChecksum |
|
61 | 60 |
) |
62 | 61 |
|
63 | 62 |
from pithos.api.settings import (UPDATE_MD5, TRANSLATE_UUIDS, |
... | ... | |
65 | 64 |
|
66 | 65 |
from pithos.api import settings |
67 | 66 |
|
68 |
from pithos.api import settings |
|
69 |
|
|
70 | 67 |
from pithos.backends.base import ( |
71 | 68 |
NotAllowedError, QuotaError, ContainerNotEmpty, ItemNotExists, |
72 | 69 |
VersionNotExists, ContainerExists) |
73 | 70 |
|
74 | 71 |
from pithos.backends.filter import parse_filters |
75 | 72 |
|
76 |
import hashlib |
|
77 |
|
|
78 | 73 |
import logging |
79 | 74 |
logger = logging.getLogger(__name__) |
80 | 75 |
|
... | ... | |
818 | 813 |
validate_matching_preconditions(request, meta) |
819 | 814 |
except faults.NotModified: |
820 | 815 |
response = HttpResponse(status=304) |
821 |
response['ETag'] = meta['checksum'] |
|
816 |
response['ETag'] = meta['hash'] if not UPDATE_MD5 else meta['checksum']
|
|
822 | 817 |
return response |
823 | 818 |
|
824 | 819 |
response = HttpResponse(status=200) |
... | ... | |
899 | 894 |
validate_matching_preconditions(request, meta) |
900 | 895 |
except faults.NotModified: |
901 | 896 |
response = HttpResponse(status=304) |
902 |
response['ETag'] = meta['checksum'] |
|
897 |
response['ETag'] = meta['hash'] if not UPDATE_MD5 else meta['checksum']
|
|
903 | 898 |
return response |
904 | 899 |
|
905 | 900 |
hashmap_reply = False |
... | ... | |
1083 | 1078 |
|
1084 | 1079 |
checksum = '' # Do not set to None (will copy previous value). |
1085 | 1080 |
else: |
1086 |
md5 = hashlib.md5() |
|
1081 |
etag = request.META.get('HTTP_ETAG') |
|
1082 |
checksum_compute = Checksum() if etag or UPDATE_MD5 else NoChecksum() |
|
1087 | 1083 |
size = 0 |
1088 | 1084 |
hashmap = [] |
1089 | 1085 |
for data in socket_read_iterator(request, content_length, |
... | ... | |
1093 | 1089 |
# and we stop before getting this much data. |
1094 | 1090 |
size += len(data) |
1095 | 1091 |
hashmap.append(request.backend.put_block(data)) |
1096 |
md5.update(data)
|
|
1092 |
checksum_compute.update(data)
|
|
1097 | 1093 |
|
1098 |
checksum = md5.hexdigest().lower() |
|
1099 |
etag = request.META.get('HTTP_ETAG') |
|
1094 |
checksum = checksum_compute.hexdigest() |
|
1100 | 1095 |
if etag and parse_etags(etag)[0].lower() != checksum: |
1101 | 1096 |
raise faults.UnprocessableEntity('Object ETag does not match') |
1102 | 1097 |
|
1103 | 1098 |
try: |
1104 |
version_id = \ |
|
1105 |
request.backend.update_object_hashmap(request.user_uniq, |
|
1106 |
v_account, v_container, |
|
1107 |
v_object, size, content_type, |
|
1108 |
hashmap, checksum, |
|
1109 |
'pithos', meta, True, |
|
1110 |
permissions) |
|
1099 |
version_id, merkle = request.backend.update_object_hashmap( |
|
1100 |
request.user_uniq, v_account, v_container, v_object, size, |
|
1101 |
content_type, hashmap, checksum, 'pithos', meta, True, permissions |
|
1102 |
) |
|
1111 | 1103 |
except NotAllowedError: |
1112 | 1104 |
raise faults.Forbidden('Not allowed') |
1113 | 1105 |
except IndexError, e: |
... | ... | |
1141 | 1133 |
raise faults.ItemNotFound('Object does not exist') |
1142 | 1134 |
|
1143 | 1135 |
response = HttpResponse(status=201) |
1144 |
if checksum: |
|
1145 |
response['ETag'] = checksum |
|
1136 |
response['ETag'] = merkle if not UPDATE_MD5 else checksum |
|
1146 | 1137 |
response['X-Object-Version'] = version_id |
1147 | 1138 |
return response |
1148 | 1139 |
|
... | ... | |
1163 | 1154 |
|
1164 | 1155 |
checksum = file.etag |
1165 | 1156 |
try: |
1166 |
version_id = \ |
|
1167 |
request.backend.update_object_hashmap(request.user_uniq, |
|
1168 |
v_account, v_container, |
|
1169 |
v_object, file.size, |
|
1170 |
file.content_type, |
|
1171 |
file.hashmap, checksum, |
|
1172 |
'pithos', {}, True) |
|
1157 |
version_id, merkle = request.backend.update_object_hashmap( |
|
1158 |
request.user_uniq, v_account, v_container, v_object, file.size, |
|
1159 |
file.content_type, file.hashmap, checksum, 'pithos', {}, True |
|
1160 |
) |
|
1173 | 1161 |
except NotAllowedError: |
1174 | 1162 |
raise faults.Forbidden('Not allowed') |
1175 | 1163 |
except ItemNotExists: |
... | ... | |
1178 | 1166 |
raise faults.RequestEntityTooLarge('Quota error: %s' % e) |
1179 | 1167 |
|
1180 | 1168 |
response = HttpResponse(status=201) |
1181 |
response['ETag'] = checksum |
|
1169 |
response['ETag'] = merkle if not UPDATE_MD5 else checksum
|
|
1182 | 1170 |
response['X-Object-Version'] = version_id |
1183 | 1171 |
response.content = checksum |
1184 | 1172 |
return response |
... | ... | |
1466 | 1454 |
checksum = hashmap_md5( |
1467 | 1455 |
request.backend, hashmap, size) if UPDATE_MD5 else '' |
1468 | 1456 |
try: |
1469 |
version_id = \ |
|
1470 |
request.backend.update_object_hashmap(request.user_uniq, |
|
1471 |
v_account, v_container, |
|
1472 |
v_object, size, |
|
1473 |
prev_meta['type'], |
|
1474 |
hashmap, checksum, 'pithos', |
|
1475 |
meta, replace, permissions) |
|
1457 |
version_id, merkle = request.backend.update_object_hashmap( |
|
1458 |
request.user_uniq, v_account, v_container, v_object, size, |
|
1459 |
prev_meta['type'], hashmap, checksum, 'pithos', meta, replace, |
|
1460 |
permissions |
|
1461 |
) |
|
1476 | 1462 |
except NotAllowedError: |
1477 | 1463 |
raise faults.Forbidden('Not allowed') |
1478 | 1464 |
except ItemNotExists: |
... | ... | |
1491 | 1477 |
raise faults.ItemNotFound('Object does not exist') |
1492 | 1478 |
|
1493 | 1479 |
response = HttpResponse(status=204) |
1494 |
response['ETag'] = checksum |
|
1480 |
response['ETag'] = merkle if not UPDATE_MD5 else checksum
|
|
1495 | 1481 |
response['X-Object-Version'] = version_id |
1496 | 1482 |
return response |
1497 | 1483 |
|
Also available in: Unified diff