Skip to content

Feature implement config file override for webqueue2api configs #46

22 changes: 21 additions & 1 deletion src/webqueue2api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,22 @@
from webqueue2api.parser import Item, Queue, load_queues
from .config import config
import configparser, sys
from pathlib import Path
from .config import config

config_parser = configparser.ConfigParser()
config_file_path = Path.joinpath(Path(sys.executable).parent.parent.parent, "webqueue2api_config.ini")

if Path(config_file_path).exists():
config_parser.read(config_file_path)

if config_parser.has_section("parser"):
if config_parser.has_option("parser", "queue_directory"):
config.parser.queue_directory = config_parser["parser"]["queue_directory"]
if config_parser.has_option("parser", "queues_to_ignore"):
config.parser.queues_to_ignore = config_parser["parser"]["queues_to_ignore"]

if config_parser.has_section("api"):
if config_parser.has_option("api", "environment"):
config.api.environment = config_parser["api"]["environment"]
if config_parser.has_option("api", "jwt_secret_key"):
config.api.jwt_secret_key = config_parser["api"]["jwt_secret_key"]
2 changes: 1 addition & 1 deletion src/webqueue2api/api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# Look for JWTs in headers (for access) then cookies (for refresh)
app.config["JWT_TOKEN_LOCATION"] = ["headers", "cookies"]
# Restrict cookies to HTTPS in prod, allow HTTP in dev
app.config["JWT_COOKIE_SECURE"] = False if config.jwt_secret_key == "dev" else True
app.config["JWT_COOKIE_SECURE"] = False if config.environment == "dev" else True
# Restrict cookies using SameSite=strict flag
app.config["JWT_COOKIE_SAMESITE"] = "strict"
# Restrict refresh tokens to /token/refresh endpoint
Expand Down