Skip to content

Commit

Permalink
Merge pull request #46 from ECN/feature-implement-config-file-overrid…
Browse files Browse the repository at this point in the history
…e-for-webqueue2api-configs

Feature implement config file override for webqueue2api configs
  • Loading branch information
campb303 authored Aug 2, 2021
2 parents c88dc30 + 0c4523f commit f4f874e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
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

0 comments on commit f4f874e

Please sign in to comment.