Bind isolated restore to fetched artifact and document archive integrity gates
Assistant: codex Assistant-Model: gpt-6-astra Assistant-Session: 01a06ecb-456a-71c2-b41e-0755d336e883
This commit is contained in:
parent
0cca68da96
commit
480d181549
4 changed files with 41 additions and 3 deletions
|
|
@ -11,6 +11,8 @@ import zipfile
|
|||
|
||||
def validate_archive(path):
|
||||
with zipfile.ZipFile(path) as archive:
|
||||
if sum(i.file_size for i in archive.infolist()) > 20*1024**3:
|
||||
raise ValueError('archive exceeds recovery size bound')
|
||||
names = set(archive.namelist())
|
||||
if 'forgejo-db.sql' not in names or not any(n.startswith('repos/') for n in names):
|
||||
raise ValueError('required archive content missing')
|
||||
|
|
@ -48,7 +50,8 @@ def capture(namespace, pod, destination):
|
|||
piece = call(['dd','if='+remote+'.zip','bs='+str(chunk),'skip='+str(index),'count=1'])
|
||||
if len(piece) != min(chunk,size-index*chunk): raise ValueError('short archive chunk')
|
||||
out.write(piece)
|
||||
actual = hashlib.file_digest(destination.open('rb'),'sha256').hexdigest()
|
||||
with destination.open('rb') as source:
|
||||
actual = hashlib.file_digest(source,'sha256').hexdigest()
|
||||
if actual != expected: raise ValueError('archive transfer mismatch')
|
||||
validate_archive(destination)
|
||||
finally:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue