Allow full-size emblems and preserve safe web release retention
This commit is contained in:
parent
320dce718a
commit
d28edebb91
4 changed files with 47 additions and 67 deletions
|
|
@ -1,6 +1,8 @@
|
|||
export function panelBodyLimit(method,path){
|
||||
if(method!=='POST')return 65536;
|
||||
if(path==='/api/internal-mail/messages/send')return 32*1024*1024;
|
||||
// Emblem endpoints enforce their own raster validation and 2 MB image cap.
|
||||
if(/^\/api\/(?:clan|company)-emblems\/[a-f0-9]{8}(?:-[a-f0-9]{4}){3}-[a-f0-9]{12}$/i.test(path))return 2*1024*1024;
|
||||
if(path==='/api/ban-evidence')return 7*1024*1024;
|
||||
// A validated 2 MB image plus bounded multipart headers.
|
||||
if(path==='/api/account/avatar')return 2*1024*1024+65536;
|
||||
|
|
|
|||
|
|
@ -1,68 +1,43 @@
|
|||
#!/usr/bin/env python3
|
||||
"""Retain production and two rollback releases; preserve live dependencies."""
|
||||
import argparse
|
||||
import fcntl
|
||||
import json
|
||||
import pathlib
|
||||
import re
|
||||
import shutil
|
||||
|
||||
|
||||
def candidates(app):
|
||||
releases = (app / 'releases').resolve(strict=True)
|
||||
current = (app / 'current').resolve(strict=True)
|
||||
if current.parent != releases:
|
||||
raise RuntimeError('Current release is outside the release directory')
|
||||
versions = [p for p in releases.iterdir()
|
||||
if not p.is_symlink() and p.is_dir()
|
||||
and re.fullmatch(r'ci-[0-9a-f]{40}', p.name)]
|
||||
keep = {current}
|
||||
keep.update(sorted((p for p in versions if p != current),
|
||||
key=lambda p: p.stat().st_mtime, reverse=True)[:2])
|
||||
# Explicit rollback links and shared node_modules must remain usable.
|
||||
keep.update(p.resolve(strict=True) for p in app.iterdir() if p.is_symlink())
|
||||
for proc in pathlib.Path('/proc').glob('[0-9]*/cwd'):
|
||||
try:
|
||||
location = proc.resolve(strict=True)
|
||||
if location.parent == releases:
|
||||
keep.add(location)
|
||||
except (OSError, RuntimeError):
|
||||
pass
|
||||
pending = list(keep)
|
||||
while pending:
|
||||
directory = pending.pop()
|
||||
if directory.parent != releases or not directory.is_dir():
|
||||
continue
|
||||
for link in directory.rglob('*'):
|
||||
if not link.is_symlink():
|
||||
continue
|
||||
target = link.resolve(strict=True)
|
||||
if target.is_relative_to(releases):
|
||||
owner = releases / target.relative_to(releases).parts[0]
|
||||
if owner not in keep:
|
||||
keep.add(owner)
|
||||
pending.append(owner)
|
||||
return releases, [p for p in versions if p not in keep], keep
|
||||
|
||||
"""Prune only inactive web releases older than 24h, preserving rollback/dependencies."""
|
||||
import argparse,fcntl,json,pathlib,re,shutil,time
|
||||
APP=pathlib.Path('/home/dunerealms/apps/dunerealms')
|
||||
STATE=pathlib.Path('/mnt/HC_Volume_107481500/dunegit/ci/promotion')
|
||||
def candidates(app=APP,state=STATE,now=None):
|
||||
root=(app/'releases').resolve(strict=True);current=(app/'current').resolve(strict=True)
|
||||
if current.parent!=root:raise RuntimeError('Active release is outside release storage')
|
||||
versions=[p for p in root.iterdir() if not p.is_symlink() and p.is_dir() and re.fullmatch(r'ci-[0-9a-f]{40}',p.name)]
|
||||
keep={current};keep.update(sorted(versions,key=lambda p:p.stat().st_mtime,reverse=True)[:3])
|
||||
previous=state/'previous-release'
|
||||
if previous.exists():keep.add(pathlib.Path(previous.read_text().strip()).resolve())
|
||||
for p in app.iterdir():
|
||||
if p.is_symlink() and p.exists():keep.add(p.resolve())
|
||||
for proc in pathlib.Path('/proc').glob('[0-9]*/cwd'):
|
||||
try:
|
||||
location=proc.resolve(strict=True)
|
||||
if root in location.parents:keep.add(root/location.relative_to(root).parts[0])
|
||||
except (OSError,RuntimeError):pass
|
||||
pending=list(keep)
|
||||
while pending:
|
||||
directory=pending.pop()
|
||||
if directory.parent!=root or not directory.is_dir():continue
|
||||
for link in directory.rglob('*'):
|
||||
if not link.is_symlink() or not link.exists():continue
|
||||
target=link.resolve()
|
||||
if root in target.parents:
|
||||
owner=root/target.relative_to(root).parts[0]
|
||||
if owner not in keep:keep.add(owner);pending.append(owner)
|
||||
cutoff=(time.time() if now is None else now)-86400
|
||||
return root,[p for p in versions if p not in keep and p.stat().st_mtime<cutoff],keep
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--apply', action='store_true')
|
||||
args = parser.parse_args()
|
||||
app = pathlib.Path('/home/dunerealms/apps/dunerealms')
|
||||
# Share the promoter lock: never remove a candidate during traffic switch.
|
||||
with open('/var/lib/dunerealms-ci-promote/safe-lock', 'a') as lock:
|
||||
fcntl.flock(lock, fcntl.LOCK_EX)
|
||||
releases, obsolete, keep = candidates(app)
|
||||
for release in obsolete:
|
||||
if release.is_symlink() or release.resolve().parent != releases:
|
||||
raise RuntimeError('Unsafe deletion target')
|
||||
if args.apply:
|
||||
shutil.rmtree(release)
|
||||
print(json.dumps({'applied': args.apply,
|
||||
'obsolete': [p.name for p in obsolete],
|
||||
'protected': sorted(p.name for p in keep)}))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
parser=argparse.ArgumentParser();parser.add_argument('--apply',action='store_true');args=parser.parse_args()
|
||||
with (STATE/'safe-lock').open('a') as lock:
|
||||
try:fcntl.flock(lock,fcntl.LOCK_EX|fcntl.LOCK_NB)
|
||||
except BlockingIOError:return print(json.dumps({'skipped':'Promotion running'}))
|
||||
root,obsolete,keep=candidates()
|
||||
for p in obsolete:
|
||||
if p.is_symlink() or p.resolve().parent!=root:raise RuntimeError('Unsafe cleanup target')
|
||||
if args.apply:shutil.rmtree(p)
|
||||
print(json.dumps({'applied':args.apply,'obsolete':[p.name for p in obsolete],'preserved':sorted(p.name for p in keep)}))
|
||||
if __name__=='__main__':main()
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
import {pathToFileURL} from 'node:url';
|
||||
import {fileURLToPath} from 'node:url';
|
||||
import {realpathSync} from 'node:fs';
|
||||
import {applyUnicorpRoyalMailbox,reconcileRoyalCompanyMail} from '../node/company-royal-mail.mjs';
|
||||
export async function runUnicorpRoyalMailbox({db,keys,broker,apply=false}){const result=await applyUnicorpRoyalMailbox(db,keys,{apply});if(apply&&result.companyId){await reconcileRoyalCompanyMail(db,broker);return{...result,mailboxState:(await db.prepare('SELECT state FROM site_company_royal_mail WHERE company_id=?').bind(result.companyId).first()).state};}return result;}
|
||||
if(process.argv[1]&&import.meta.url===pathToFileURL(process.argv[1]).href){
|
||||
if(process.argv[1]&&fileURLToPath(import.meta.url)===realpathSync(process.argv[1])){
|
||||
if(process.argv.slice(2).some(a=>a!=='--apply'))throw Error('Usage: provision-unicorp-royal-mail.mjs [--apply]');
|
||||
const {openDatabase}=await import('../node/mysql.mjs'),{openOrganisationKeyService}=await import('../node/organisation-key-service.mjs'),{internalMailBroker}=await import('../node/internal-mail.mjs');
|
||||
const db=await openDatabase(process.env);try{console.log(JSON.stringify(await runUnicorpRoyalMailbox({db,keys:await openOrganisationKeyService(db,process.env),broker:internalMailBroker,apply:process.argv.includes('--apply')})));}finally{await db.close();}
|
||||
|
|
|
|||
|
|
@ -24,3 +24,5 @@ test('portrait transport permits the existing 2 MB file contract and retains tig
|
|||
test('the standalone adapter only loads its fixed service allowlist and retains existing client modules',async()=>{
|
||||
const source=await readFile(new URL('../control-panel/public/user-service-entry.mjs',import.meta.url),'utf8');assert.match(source,/modules:\['\.\/internal-mail\.mjs'\]/);assert.match(source,/modules:\['\.\/kit-market\.mjs'\]/);assert.match(source,/if\(!spec\)throw/);assert.doesNotMatch(source,/import\([^)]*searchParams/);
|
||||
});
|
||||
|
||||
test('Clan and Company emblem uploads use the image allowance without widening unrelated endpoints',()=>{const id='c434d560-fab5-4df6-b67a-4456adf823e7';for(const kind of ['clan','company']){assert.equal(panelBodyLimit('POST','/api/'+kind+'-emblems/'+id),2097152);assert.equal(panelBodyLimit('GET','/api/'+kind+'-emblems/'+id),65536);assert.equal(panelBodyLimit('POST','/api/'+kind+'-emblems/not-an-id'),65536);}assert.equal(panelBodyLimit('POST','/api/companies/deeds'),65536);});
|
||||
|
|
|
|||
Loading…
Reference in a new issue

Staff