27 lines
2.2 KiB
Python
27 lines
2.2 KiB
Python
from pathlib import Path
|
|
import json,shutil,hashlib
|
|
R=Path(__file__).resolve().parent;ROOT=R.parents[1];Q=ROOT/'storage/app/private/investmoz-v2/portal-audit/portal-stability-source-20261011_083742'
|
|
b=json.loads((R/'B-final-backup-restoration-20261015.json').read_text(encoding='utf-8'));private=Path(b['private_recovery_directory']);clone=private/'application-boot'
|
|
assert not clone.exists();clone.mkdir()
|
|
for n in ['app','config','routes','resources/views','bootstrap']:
|
|
shutil.copytree(Q/n,clone/n,ignore=shutil.ignore_patterns('cache'))
|
|
for n in ['bootstrap/cache','storage/framework/views','storage/framework/cache/data','storage/framework/sessions','storage/logs','storage/app/private','public/build']:(clone/n).mkdir(parents=True,exist_ok=True)
|
|
for n in ['composer.json','composer.lock','package.json','package-lock.json']:
|
|
if (Q/n).exists():shutil.copy2(Q/n,clone/n)
|
|
i=json.loads((R/'B-final-inputs-20261015.json').read_text(encoding='utf-8'))
|
|
for n,h in i['source_files'].items():
|
|
src=private/'file-restore/candidate'/n;assert hashlib.sha256(src.read_bytes()).hexdigest()==h
|
|
dst=clone/n;dst.parent.mkdir(parents=True,exist_ok=True);shutil.copy2(src,dst)
|
|
for n,h in i['build_files'].items():
|
|
src=private/'file-restore/candidate/public/build'/n;assert hashlib.sha256(src.read_bytes()).hexdigest()==h
|
|
dst=clone/'public/build'/n;dst.parent.mkdir(parents=True,exist_ok=True);shutil.copy2(src,dst)
|
|
# Keep runtime secret material outside the workspace/review artifact.
|
|
env=(private/'file-restore/private-runtime/.env.stability-consumers').read_text(encoding='utf-8')
|
|
import re
|
|
overrides={'APP_ENV':'testing','APP_DEBUG':'false','DB_HOST':'127.0.0.1','DB_PORT':'55441','DB_DATABASE':b['restore']['database'],'SESSION_DRIVER':'array','CACHE_STORE':'array','QUEUE_CONNECTION':'sync','MAIL_MAILER':'log','APP_URL':'https://b-final-restore.test','INERTIA_SSR_ENABLED':'false','PORTAL_NOTIFICATIONS_ENABLED':'false'}
|
|
for k,v in overrides.items():
|
|
env,c=re.subn(r'^'+k+r'=.*$',k+'='+v,env,flags=re.M)
|
|
if not c:env+='\n'+k+'='+v+'\n'
|
|
(clone/'.env').write_text(env,encoding='utf-8')
|
|
print(json.dumps({'clone_root':str(clone),'restore_database':b['restore']['database'],'source_build_from_restored_files':True}))
|