#!/usr/bin/env python3 """Atlas immutable transfer. No activation; strict existing SSH identity/host policy.""" import argparse from contextlib import nullcontext from pathlib import Path import subprocess import tarfile import time import sys sys.path.insert(0,str(Path(__file__).resolve().parent/'vendor')) from release import load, safe_name, require from transport import TRANSPORT_FILES, LEGACY_FILES def ssh(identity, command, host='85.190.124.132'): require(host=='85.190.124.132','Production transfer host must be web1') return ['ssh','-F','/dev/null','-i',identity,'-o','IdentitiesOnly=yes','-o','HostKeyAlgorithms=ssh-ed25519', '-o','StrictHostKeyChecking=yes','-o','UpdateHostKeys=no','plotdirector-website-deploy@'+host,command] def transfer(bundle, identity, host='85.190.124.132', meter=None): bundle=Path(bundle).resolve();release=safe_name(load(bundle/'authorization.json')['release_id']) names=TRANSPORT_FILES if (bundle/'transport.json').exists() else LEGACY_FILES start=time.monotonic();total=0 with meter.phase('transfer') if meter else nullcontext(): process=subprocess.Popen(ssh(identity,'upload '+release,host),stdin=subprocess.PIPE) try: with tarfile.open(fileobj=process.stdin,mode='w|',format=tarfile.USTAR_FORMAT) as tar: for name in names: path=bundle/name require(path.is_file() and not path.is_symlink(),'Invalid transfer input') entry=tarfile.TarInfo(name);entry.size=path.stat().st_size;entry.mode=0o600;total+=entry.size with path.open('rb') as stream:tar.addfile(entry,stream) process.stdin.close() require(process.wait()==0,'Restricted upload failed; incomplete staging retained for review') finally: if process.poll() is None:process.kill();process.wait() elapsed=time.monotonic()-start result={'source':'atlas-sender','bytes':total,'seconds':elapsed,'mib_per_second':total/elapsed/1024**2} if meter:meter.data['transfer']=result return result def main(): parser=argparse.ArgumentParser(description=__doc__) parser.add_argument('bundle');parser.add_argument('--identity',required=True) parser.add_argument('--host',default='85.190.124.132');args=parser.parse_args() transfer(args.bundle,args.identity,args.host) if __name__=='__main__':main()