Extraction des secrets
This commit is contained in:
@@ -19,7 +19,10 @@ function latestMonthEntry(months) {
|
||||
|
||||
async function run({ stat }) {
|
||||
const toolsConfig = await loadToolsConfig();
|
||||
const url = stat.url || toolsConfig.goaccess?.url || "";
|
||||
const url = stat.url || toolsConfig.goaccess?.url;
|
||||
if (!url) {
|
||||
throw new Error("URL GoAccess manquante (GOACCESS_URL ou goaccess.url dans tools/config.json)");
|
||||
}
|
||||
const metric = stat.metric || "hits";
|
||||
const windowDays = Number.isFinite(stat.days) ? stat.days : 30;
|
||||
const data = await loadData(url);
|
||||
|
||||
@@ -14,6 +14,25 @@ if TOOLS_DIR not in sys.path:
|
||||
sys.path.append(TOOLS_DIR)
|
||||
|
||||
|
||||
def load_env(env_path=None):
|
||||
path = env_path or os.path.join(ROOT_DIR, ".env")
|
||||
if not os.path.exists(path):
|
||||
return
|
||||
try:
|
||||
with open(path, "r", encoding="utf-8") as handle:
|
||||
for line in handle:
|
||||
stripped = line.strip()
|
||||
if not stripped or stripped.startswith("#") or "=" not in stripped:
|
||||
continue
|
||||
key, value = stripped.split("=", 1)
|
||||
key = key.strip()
|
||||
if not key or key in os.environ:
|
||||
continue
|
||||
os.environ[key] = value
|
||||
except Exception as exc: # noqa: BLE001
|
||||
print(f"Failed to load .env: {exc}", file=sys.stderr)
|
||||
|
||||
|
||||
def load_config():
|
||||
cfg_path = os.path.join(ROOT_DIR, "tools", "config.json")
|
||||
try:
|
||||
@@ -63,8 +82,13 @@ def main():
|
||||
public_path = payload.get("publicPath")
|
||||
url = payload.get("stat", {}).get("url")
|
||||
|
||||
load_env()
|
||||
cfg = load_config()
|
||||
goaccess_url = url or (cfg.get("goaccess") or {}).get("url") or ""
|
||||
goaccess_url = url or os.environ.get("GOACCESS_URL") or (cfg.get("goaccess") or {}).get("url")
|
||||
|
||||
if not goaccess_url:
|
||||
print("Missing GoAccess URL (set GOACCESS_URL or goaccess.url in tools/config.json)", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
data = fetch_goaccess(goaccess_url)
|
||||
|
||||
@@ -11,7 +11,10 @@ async function run({ stat, outputPath, publicPath }) {
|
||||
}
|
||||
|
||||
const toolsConfig = await loadToolsConfig();
|
||||
const url = stat.url || toolsConfig.goaccess?.url || "";
|
||||
const url = stat.url || toolsConfig.goaccess?.url;
|
||||
if (!url) {
|
||||
throw new Error("URL GoAccess manquante (GOACCESS_URL ou goaccess.url dans tools/config.json)");
|
||||
}
|
||||
const data = await fetchGoAccessJson(url);
|
||||
const months = groupVisitsByMonth(data, { adjustCrawlers: true });
|
||||
|
||||
|
||||
Reference in New Issue
Block a user