repomatic.release.virustotal module¶
Upload release binaries to VirusTotal and record detection snapshots.
Submits compiled binaries (.bin, .exe) to the VirusTotal API for malware
scanning. This seeds antivirus vendor databases with the signatures of freshly
built binaries, which keeps false-positive rates in check for downstream
distributors.
Detection statistics polled after an upload are appended to a CSV history, one
record per binary per scan date. The sync-binaries command renders that
history into the binaries catalog page (docs/binaries.md).
Note
Scan results are deliberately kept out of GitHub release notes: a raw
flagged / total count next to a download link reads as a malware verdict to
visitors, when it is almost always Nuitka onefile false positives. See
kdeldycke/meta-package-manager#1911
for the confusion this caused. The catalog page provides the context release
notes cannot.
Note
The free-tier API allows 4 requests per minute. Every API call, upload or
poll, goes through one RequestPacer, which spaces the calls to stay
within that budget.
- repomatic.release.virustotal.FREE_TIER_RATE_LIMIT = 4¶
VirusTotal free-tier request budget, in API calls per minute.
The single source for the upload and polling pace: the
scan-virustotalCLI default andRequestPacerderive from it.
- repomatic.release.virustotal.UPLOAD_REQUESTS = 2¶
API calls one file upload costs.
upload_file()first asks for an upload URL, then posts the file to it.
- repomatic.release.virustotal.UPLOAD_TIMEOUT = 300¶
Socket timeout of a file upload, in seconds.
The file goes out as one
bytesbody, so the timeout bounds its whole transfer, not each block of it. TheDEFAULT_TIMEOUTof an API read would fail a binary of tens of megabytes on a slow link.
- repomatic.release.virustotal.RELEASE_ASSET_POLL_ATTEMPTS = 6¶
How many times
download_release_binaries()reads a release’s assets.
- repomatic.release.virustotal.RELEASE_ASSET_POLL_DELAY = 10¶
Seconds
download_release_binaries()waits between two reads.
- repomatic.release.virustotal.SCAN_HEADERS = ('tag', 'filename', 'sha256', 'scanned', 'malicious', 'suspicious', 'undetected', 'harmless')¶
Columns of the committed scan history, in file order.
The release and the file it identifies first, then the four verdict counts, so the table reads left to right from what was scanned to what came back. Rows are ordered by release version rather than alphabetically, which a plain sort of the tag strings would get wrong past
v9.
- repomatic.release.virustotal.VIRUSTOTAL_API_URL = 'https://www.virustotal.com/api/v3'¶
Base URL of the VirusTotal REST API.
- repomatic.release.virustotal.VIRUSTOTAL_GUI_URL = 'https://www.virustotal.com/gui/file/{sha256}'¶
URL template for the VirusTotal file analysis page.
- class repomatic.release.virustotal.RequestPacer(per_minute=4)[source]¶
Bases:
objectSpace VirusTotal API calls to stay within a per-minute budget.
One pacer serves every call of a run, uploads and polls alike, so the budget covers them all: the first poll waits on the last upload like any other call. A call reserves its share of the minute when it starts, so the time a slow upload takes counts toward the wait before the next call.
- interval¶
Seconds one API call reserves out of the budget.
- wait(calls=1)[source]¶
Sleep until the budget allows another request, then reserve it.
- Parameters:
calls (
int) – The API calls the coming request makes, likeUPLOAD_REQUESTSfor an upload.- Return type:
- class repomatic.release.virustotal.DetectionStats(malicious, suspicious, undetected, harmless)[source]¶
Bases:
objectDetection statistics from a completed VirusTotal analysis.
Stores only the four categories that constitute a definitive verdict.
type-unsupported,timeout, andfailurefrom the API response are excluded from the total.
- class repomatic.release.virustotal.ScanResult(filename, sha256, analysis_url, detection_stats=None)[source]¶
Bases:
objectResult of uploading a single file to VirusTotal.
- detection_stats: DetectionStats | None = None¶
Detection statistics, or
Noneif analysis is still pending.
- class repomatic.release.virustotal.ScanRecord(tag, filename, sha256, scanned, stats)[source]¶
Bases:
objectA detection snapshot for one binary, taken on a given date.
Records accumulate in a CSV history (see
upsert_scan_records()) committed to the repository. Each record freezes theflagged / totalverdict counts at scan time, so the history supports trend analysis across releases even after VirusTotal re-analyzes the files or vendors process false-positive reports.- stats: DetectionStats¶
Detection statistics at scan time.
- repomatic.release.virustotal.download_release_binaries(repository, tag, dest)[source]¶
Download a release’s versioned binaries once its asset list shows them.
A read landing seconds after a release is published can list no asset, and
gh release downloadthen fails withno assets to downloadon a release holding every binary. So the asset list is read first, up toRELEASE_ASSET_POLL_ATTEMPTStimes. The download still runs when the list stays empty: a release that ships no binary fails there, with the message ofgh.The patterns name the versioned files only. The versionless alias copies share their digest with a versioned sibling, so scanning them would only submit duplicates.
- Parameters:
- Raises:
RuntimeError – When
gh release downloadfails.- Return type:
- repomatic.release.virustotal.upload_file(api_key, path)[source]¶
Upload path to VirusTotal for analysis.
Two API calls, counted by
UPLOAD_REQUESTS: one for a single-use upload URL, which takes a file of any size wherePOST /filesstops at 32 MB, and one posting the file to it.- Parameters:
- Raises:
FetchError – When either call fails.
- Return type:
- repomatic.release.virustotal.analysis_stats(api_key, sha256)[source]¶
Read the
last_analysis_statsof the file report for sha256.- Parameters:
- Return type:
- Returns:
Verdict counts keyed by category, like
malicious.- Raises:
FetchError – While VirusTotal has no report for the file yet (an HTTP 404 until the upload is indexed), or when the call fails.
- repomatic.release.virustotal.scan_files(api_key, file_paths, pacer=None)[source]¶
Upload files to VirusTotal and return scan results.
Spaces the uploads through pacer to respect the free-tier rate limit.
- Parameters:
api_key (
str) – VirusTotal API key.pacer (
RequestPacer|None) – The pacer every API call of the run shares. A fresh one at the free-tier rate whenNone.
- Return type:
- Returns:
List of scan results with analysis URLs.
- repomatic.release.virustotal.poll_detection_stats(api_key, results, pacer=None, timeout=600)[source]¶
Poll VirusTotal for detection statistics of previously uploaded files.
Queries
GET /files/{sha256}for each file until analysis completes or the timeout is reached, spacing every query through pacer.- Parameters:
api_key (
str) – VirusTotal API key.results (
list[ScanResult]) – Scan results from a previous upload.pacer (
RequestPacer|None) – The pacer the uploads of the run went through, so the first poll waits on the last upload. A fresh one at the free-tier rate whenNone.timeout (
int) – Maximum seconds to wait for all analyses to complete.
- Return type:
- Returns:
Results with
detection_statspopulated (orNonefor files whose analysis did not complete before the timeout).
- repomatic.release.virustotal.records_from_results(results, tag, scanned=None)[source]¶
Build history records from scan results whose analysis completed.
Results still pending (no detection statistics) are skipped: a record without verdict counts carries no information the release assets don’t already provide.
- Parameters:
results (
list[ScanResult]) – Scan results, typically frompoll_detection_stats().tag (
str) – Git tag of the release the binaries belong to.scanned (
str|None) – Snapshot date inYYYY-MM-DDformat. Today (UTC) whenNone.
- Return type:
- Returns:
One record per result with detection statistics.
- repomatic.release.virustotal.load_scan_records(path)[source]¶
Load scan records from the CSV history file.
- Parameters:
path (
Path) – Path to the CSV file.- Return type:
- Returns:
The records, or an empty list when the file does not exist.
- Raises:
ValueError – When the file exists but cannot be parsed, or when it does not exist but a JSON history sits beside it. Loud on purpose: a history must never be silently clobbered by the next
upsert_scan_records()write, and a JSON one is the store of a release older than7.13.0, which nothing reads any more.
- repomatic.release.virustotal.upsert_scan_records(path, new_records)[source]¶
Merge new records into the CSV history at path.
Records sharing the same
(sha256, scanned)identity are replaced, so re-running a scan the same day is idempotent. The file is created (with its parent directories) when missing, and always rewritten in normalized form, sorted by version, filename and scan date.CSV also keeps the store out of the autofix lane: nothing there rewrites a
.csv, where a committed JSON file has to match whatever layout Biome is configured for orformat-jsonreformats it right back. Seedocs/operation-contracts.md§ Naming rules, rule 8, for the rest of that reasoning.- Parameters:
path (
Path) – Path to the CSV history.new_records (
list[ScanRecord]) – Records to merge in.
- Return type:
- Returns:
Truewhen the file content changed.