24 lines
936 B
Python
24 lines
936 B
Python
"""Verify every committed original against PostgreSQL, without printing keys/tokens."""
|
|
import json
|
|
from faults import remote
|
|
|
|
code = '''from src.database import open_database,get_connection
|
|
from src.storage import s3,BUCKET
|
|
import hashlib,json
|
|
open_database()
|
|
with get_connection() as conn:
|
|
rows=conn.execute('SELECT object_key,size_bytes,sha256 FROM attachments').fetchall()
|
|
checked=total=0
|
|
for row in rows:
|
|
body=s3.get_object(Bucket=BUCKET,Key=row['object_key'])['Body']
|
|
digest=hashlib.sha256(); size=0
|
|
try:
|
|
for chunk in body.iter_chunks(65536):
|
|
size+=len(chunk); digest.update(chunk)
|
|
finally:
|
|
body.close()
|
|
assert size==row['size_bytes'] and digest.hexdigest()==row['sha256'], 'original mismatch'
|
|
checked+=1; total+=size
|
|
print(json.dumps({'verified_originals':checked,'verified_bytes':total,'all_checksums_match':True}))'''
|
|
print(json.dumps(json.loads(remote(code)),indent=2))
|