Publish licensed data snapshots with LAN LFS transfer and content audits
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
"""One real archive chunk upload and fresh download; never modifies source data."""
|
||||
import argparse
|
||||
import json
|
||||
from pathlib import Path
|
||||
import time
|
||||
from datetime import datetime, timezone
|
||||
|
||||
import lan_lfs_transfer as lan
|
||||
import publish_archives as archives
|
||||
|
||||
|
||||
def run(output):
|
||||
root = Path.cwd()
|
||||
receipt = archives.no_links(output)
|
||||
if receipt.exists() or root / 'registry/publication-20261001' not in receipt.parents:
|
||||
raise ValueError('New publication receipt required')
|
||||
catalog = archives.json_read(root / 'artifacts/public-resources-20261001/malecns-synaptic-partners/catalog.json')
|
||||
chunk = catalog['chunks'][0]
|
||||
oid, size = chunk['sha256'], chunk['bytes']
|
||||
source = root / '.git/lfs/objects' / oid[:2] / oid[2:4] / oid
|
||||
records = []
|
||||
for operation in ('upload', 'download'):
|
||||
agent = lan.Agent(dict(event='init', operation=operation, remote='origin',
|
||||
concurrent=True, concurrenttransfers=2), lambda value: None)
|
||||
original = agent.curl
|
||||
methods = []
|
||||
def observe(method, url, headers, **kwargs):
|
||||
result = original(method, url, headers, **kwargs)
|
||||
methods.append(method)
|
||||
return result
|
||||
agent.curl = observe
|
||||
start = time.perf_counter()
|
||||
result = agent.transfer(dict(event=operation, action=None, oid=oid, size=size,
|
||||
**({'path': str(source)} if operation == 'upload' else {})))
|
||||
record = dict(operation=operation, seconds=time.perf_counter()-start, methods=methods,
|
||||
sha256=oid, bytes=size, complete=result['event'] == 'complete')
|
||||
if operation == 'download':
|
||||
record['new_download_file'] = result['path']
|
||||
records.append(record)
|
||||
report = dict(schema='lfs-lan-roundtrip-smoke-v1', pass_all=True,
|
||||
observed_utc=datetime.now(timezone.utc).isoformat(),
|
||||
ip=lan.IP, hostname=lan.HOST, port=443, certificate_verification=True,
|
||||
proxy_used=False, transfers=records,
|
||||
adapter=archives.sha_file(lan.__file__))
|
||||
archives.write_new(receipt, archives.canonical(report))
|
||||
print(json.dumps(report), flush=True)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('--receipt', required=True)
|
||||
run(parser.parse_args().receipt)
|
||||
Reference in New Issue
Block a user