Files
Investidor-V2/tools/portal-country-https-active-flag.py
nala 287e991486
tests / ci (push) Waiting to run
oportunidades 7
2026-10-13 11:40:29 +02:00

24 lines
1.8 KiB
Python

"""Only the authorized COUNTRY02 flag. No SQL, key changes or other feature activation."""
from pathlib import Path
from datetime import datetime,timezone
import json,os,re,sys
ROOT=Path(__file__).resolve().parent.parent
DIR=ROOT/'storage/app/private/investmoz-v2/portal-audit'
mode=sys.argv[1] if len(sys.argv)>1 else ''
assert mode in ['enable','disable']
assert not (ROOT/'bootstrap/cache/config.php').exists(),'Effective configuration unexpectedly cached'
if mode=='enable':
proof=json.loads((DIR/'country-https-active-check-installed-disabled-20261011.json').read_text())
assert proof['result']=='passed' and proof['phase']=='installed-disabled' and not proof['country_enabled']
assert proof['code_hash']=='162daff6ce08117582dd7d796639d02b156d1b940cd85ef3587ff88a65747edd'
assert proof['installed_packages']==['2026_10_10_050000_extend_organization_country'] and proof['installation_audits']==1
assert 0<=(datetime.now(timezone.utc)-datetime.fromisoformat(proof['at'])).total_seconds()<900
file=ROOT/'.env';before=file.read_bytes();pattern=rb'(?m)^PORTAL_ORGANIZATION_COUNTRY_ENABLED=(false|true)(\r?)$'
assert len(re.findall(pattern,before))==1
after=re.sub(pattern,lambda m:b'PORTAL_ORGANIZATION_COUNTRY_ENABLED='+ (b'true' if mode=='enable' else b'false')+m[2],before)
temp=file.with_name('.env.country02-flag-new');assert not temp.exists();temp.write_bytes(after);os.replace(temp,file)
result={'result':'COUNTRY02_'+mode+'d','at':datetime.now(timezone.utc).isoformat(),'only_changed_env_key':'PORTAL_ORGANIZATION_COUNTRY_ENABLED',
'columns_data_ledger_audit_preserved':True,'active_SQL_writes':0,'other_packages_or_flags_changed':False}
(DIR/('country-https-active-flag-'+mode+'.json')).write_text(json.dumps(result,indent=2),encoding='utf-8')
print(json.dumps(result))