mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-06 02:54:26 +00:00
Add lookup('asset', app, pkg, path) and lookup('asset_host'): both resolve
the asset origin through one shared resolve_host, returning the internal
CDN domain when web-svc-cdn is deployed with flavor internal and
cdn.jsdelivr.net otherwise, so template URLs and CSP origins can never
diverge. Versions come from the role's committed files/package-lock.json.
Roles declare frontend dependencies in files/package.json; web-svc-cdn
aggregates every role lockfile, runs one npm ci per role in a node
container and mirrors the packages under /npm/<pkg>@<version>/ following
jsdelivr's path scheme, so internal and external URLs differ only by host.
Convert web-app-dashboard (keycloak-js 24.0.5 UMD) and web-app-littlejs
(bootstrap, fontawesome) to the asset lookup, drop the vendored keycloak
blob, and add a repository lint forbidding hardcoded external CDN hosts
in templates and CSP metas; pre-existing external CDN entries are checked
out with nocheck markers and a migration TODO.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
25 lines
861 B
Python
25 lines
861 B
Python
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
from ansible.plugins.lookup import LookupBase
|
|
|
|
from plugins.lookup.asset import resolve_host
|
|
|
|
|
|
class LookupModule(LookupBase):
|
|
"""
|
|
Usage:
|
|
{{ lookup('asset_host') }}
|
|
|
|
Returns the origin that lookup('asset', ...) resolves against for the
|
|
current deployment (the internal CDN origin with web-svc-cdn flavor
|
|
internal, else https://cdn.jsdelivr.net). Use it to derive the CSP
|
|
script-/style-src origin from the same flavor decision the asset URLs
|
|
use, so the whitelist never drifts from where the assets load.
|
|
"""
|
|
|
|
def run(self, terms, variables: dict[str, Any] | None = None, **kwargs):
|
|
variables = variables or getattr(self._templar, "available_variables", {}) or {}
|
|
return [resolve_host(variables, self._loader, getattr(self, "_templar", None))]
|