kopia lustrzana https://github.com/bugout-dev/moonstream
CORS origins synchronize service
rodzic
ae4de8831c
commit
d29c40e907
|
@ -23,8 +23,10 @@ SCRIPT_DIR="$(realpath $(dirname $0))"
|
|||
SECRETS_DIR="${SECRETS_DIR:-/home/ubuntu/engineapi-secrets}"
|
||||
PARAMETERS_ENV_PATH="${SECRETS_DIR}/app.env"
|
||||
|
||||
# API server service file
|
||||
# Engine API service files
|
||||
ENGINE_SERVICE_FILE="engine.service"
|
||||
ENGINE_ORIGINS_SYNC_SERVICE_FILE="engine-origins-sync.service"
|
||||
ENGINE_ORIGINS_SYNC_TIMER_FILE="engine-origins-sync.timer"
|
||||
|
||||
set -eu
|
||||
|
||||
|
@ -70,3 +72,12 @@ chmod 644 "${SCRIPT_DIR}/${ENGINE_SERVICE_FILE}"
|
|||
cp "${SCRIPT_DIR}/${ENGINE_SERVICE_FILE}" "/home/ubuntu/.config/systemd/user/${ENGINE_SERVICE_FILE}"
|
||||
XDG_RUNTIME_DIR="/run/user/1000" systemctl --user daemon-reload
|
||||
XDG_RUNTIME_DIR="/run/user/1000" systemctl --user restart --no-block "${ENGINE_SERVICE_FILE}"
|
||||
|
||||
echo
|
||||
echo
|
||||
echo -e "${PREFIX_INFO} Replacing existing CORS origins synchronize service and timer with: ${ENGINE_ORIGINS_SYNC_SERVICE_FILE}, ${ENGINE_ORIGINS_SYNC_TIMER_FILE}"
|
||||
chmod 644 "${SCRIPT_DIR}/${ENGINE_ORIGINS_SYNC_SERVICE_FILE}" "${SCRIPT_DIR}/${ENGINE_ORIGINS_SYNC_TIMER_FILE}"
|
||||
cp "${SCRIPT_DIR}/${ENGINE_ORIGINS_SYNC_SERVICE_FILE}" "/home/ubuntu/.config/systemd/user/${ENGINE_ORIGINS_SYNC_SERVICE_FILE}"
|
||||
cp "${SCRIPT_DIR}/${ENGINE_ORIGINS_SYNC_TIMER_FILE}" "/home/ubuntu/.config/systemd/user/${ENGINE_ORIGINS_SYNC_TIMER_FILE}"
|
||||
XDG_RUNTIME_DIR="/run/user/1000" systemctl --user daemon-reload
|
||||
XDG_RUNTIME_DIR="/run/user/1000" systemctl --user restart --no-block "${ENGINE_ORIGINS_SYNC_TIMER_FILE}"
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
[Unit]
|
||||
Description=Synchronize CORS origins for server
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/bin/curl http://127.0.0.1:7191/configs/origins/sync
|
||||
CPUWeight=50
|
||||
SyslogIdentifier=engine-origins-sync
|
|
@ -0,0 +1,9 @@
|
|||
[Unit]
|
||||
Description=Synchronize CORS origins for server
|
||||
|
||||
[Timer]
|
||||
OnBootSec=120s
|
||||
OnUnitActiveSec=5m
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
|
@ -1,14 +1,10 @@
|
|||
import logging
|
||||
from typing import Any, Dict, List, Set
|
||||
from typing import Any, Dict
|
||||
|
||||
from bugout.data import BugoutResource, BugoutResources
|
||||
from fastapi import (
|
||||
BackgroundTasks,
|
||||
Body,
|
||||
Depends,
|
||||
FastAPI,
|
||||
Form,
|
||||
HTTPException,
|
||||
Query,
|
||||
Request,
|
||||
)
|
||||
|
@ -46,6 +42,7 @@ whitelist_paths.update(
|
|||
"/configs/docs": "GET",
|
||||
"/configs/openapi.json": "GET",
|
||||
"/configs/is_origin": "GET",
|
||||
"/configs/origins/sync": "GET",
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -126,6 +123,14 @@ async def get_cors_origins(
|
|||
return cors_origins
|
||||
|
||||
|
||||
@app.get("/origins/sync", response_model=int)
|
||||
async def synchronize_cors_origins() -> int:
|
||||
cors_origins = fetch_and_set_cors_origins_cache()
|
||||
cors_origins_len = len(cors_origins.origins_set)
|
||||
|
||||
return cors_origins_len
|
||||
|
||||
|
||||
@app.post("/origin", response_model=data.CORSOrigins)
|
||||
async def add_cors_origin(
|
||||
request: Request,
|
||||
|
|
Ładowanie…
Reference in New Issue