laife.web.vendor
¶
Third-party files for the page: a manifest in git, a checked cache outside it.
The manifest, ui/vendor.toml, pins every npm package by exact version and by
the integrity hash the npm registry publishes for its tarball, and lists the
files to take from it. :func:ensure_vendor downloads what is missing into
cache/vendor/, refuses a tarball whose hash does not match, and extracts
only the listed files.
npm publishes one hash per tarball, not per file, so each extracted file is
recorded in a lock beside it with its own sha256. The server checks a file
against that lock before sending it (:func:verified_path), so a cache edited
after the fact is refused rather than served.
The same scheme as abyss's abyss.ui.vendor, without its plain-file pins.
Run as python -m laife.web.vendor, which is what make vendor does.
Classes:
-
Manifest–The parsed
ui/vendor.toml. -
NpmPackage–One npm package pinned in the manifest.
-
UnsafeArchiveMemberError–The manifest names a path that leaves its package folder.
-
UnsafeUrlError–A URL to fetch is not plain https.
-
VendorFileMissingError–A file was asked for that the manifest or the cache does not have.
-
VendorIntegrityError–Downloaded or cached bytes do not match their pinned hash.
Functions:
-
download–Fetch url, which must be https.
-
ensure_vendor–Download and check every package the manifest lists that is not cached yet.
-
extract_package–Check tarball against its pin, extract the listed files into dest, return the lock.
-
load_manifest–Parse the manifest,
ui/vendor.tomlby default. -
package_is_current–Tell whether folder holds exactly the files the manifest lists for pkg.
-
sha256_hex–Return the lowercase hex sha256 of data.
-
sri_digest–Hash data in the Subresource Integrity format npm uses,
<algorithm>-<base64>. -
verified_path–Return the cached path of member of pkg, after checking it against the lock.
Manifest
dataclass
¶
The parsed ui/vendor.toml.
Methods:
-
package–Return the package pinned as name.
package
¶
Return the package pinned as name.
Raises:
-
VendorFileMissingError–If the manifest does not list it.
Source code in src/laife/web/vendor.py
NpmPackage
dataclass
¶
One npm package pinned in the manifest.
Attributes:
-
folder_name(str) –Return the cache folder name, with the version, safe for a filesystem.
-
tarball_url(str) –Return the registry URL of the tarball, scoped names included.
UnsafeArchiveMemberError
¶
Bases: ValueError
The manifest names a path that leaves its package folder.
Name the path.
Source code in src/laife/web/vendor.py
UnsafeUrlError
¶
Bases: ValueError
A URL to fetch is not plain https.
Name the URL.
Source code in src/laife/web/vendor.py
VendorFileMissingError
¶
Bases: FileNotFoundError
A file was asked for that the manifest or the cache does not have.
Name the package and, when one was asked for, the file in it.
Source code in src/laife/web/vendor.py
VendorIntegrityError
¶
Bases: RuntimeError
Downloaded or cached bytes do not match their pinned hash.
Name the item and both hashes, and say what to do.
Source code in src/laife/web/vendor.py
download
¶
Fetch url, which must be https.
Raises:
-
UnsafeUrlError–If the URL is not https.
Source code in src/laife/web/vendor.py
ensure_vendor
¶
Download and check every package the manifest lists that is not cached yet.
Source code in src/laife/web/vendor.py
extract_package
¶
Check tarball against its pin, extract the listed files into dest, return the lock.
The lock maps each extracted file to its sha256 and is written beside them.
Raises:
-
VendorIntegrityError–If the tarball does not match the pin.
-
VendorFileMissingError–If a listed file is not in the tarball.
Source code in src/laife/web/vendor.py
load_manifest
¶
Parse the manifest, ui/vendor.toml by default.
Raises:
-
UnsafeArchiveMemberError–If a listed file would leave its package.
Source code in src/laife/web/vendor.py
package_is_current
¶
Tell whether folder holds exactly the files the manifest lists for pkg.
Source code in src/laife/web/vendor.py
sha256_hex
¶
sri_digest
¶
Hash data in the Subresource Integrity format npm uses, <algorithm>-<base64>.
Source code in src/laife/web/vendor.py
verified_path
¶
Return the cached path of member of pkg, after checking it against the lock.
Raises:
-
VendorFileMissingError–If the file is not listed or not cached.
-
VendorIntegrityError–If the cached bytes no longer match the lock.