From 3ec46b8b7efa723d1d4387394cf6f4a39107b72f Mon Sep 17 00:00:00 2001 From: benne238 Date: Wed, 14 Jul 2021 13:28:17 -0400 Subject: [PATCH 1/8] Added basic logic to check if the webqueue2api_config file exists in the root of the webqueue2api package directory and read the configurations from that file if so --- src/webqueue2api/__init__.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/webqueue2api/__init__.py b/src/webqueue2api/__init__.py index ba7b477..7bb54e8 100644 --- a/src/webqueue2api/__init__.py +++ b/src/webqueue2api/__init__.py @@ -1,2 +1,11 @@ from webqueue2api.parser import Item, Queue, load_queues -from .config import config \ No newline at end of file +from .config import config +import configparser, sys +from pathlib import Path as path + +config_parser_object = configparser.ConfigParser() +config_file_location = path.joinpath(path(sys.executable).parent.parent.parent, "webqueue2api_config") + +if path(config_file_location).exists(): + config_parser_object.read(config_file_location) + From 7dc383b09cab8c656fecee35dd9e90f09d48e4e6 Mon Sep 17 00:00:00 2001 From: benne238 Date: Wed, 14 Jul 2021 13:45:48 -0400 Subject: [PATCH 2/8] Logic to overwrite the queue_directory if the configuration file contains a queue_directory in the parser section --- src/webqueue2api/__init__.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/webqueue2api/__init__.py b/src/webqueue2api/__init__.py index 7bb54e8..95cbb1f 100644 --- a/src/webqueue2api/__init__.py +++ b/src/webqueue2api/__init__.py @@ -2,10 +2,15 @@ from .config import config import configparser, sys from pathlib import Path as path +import webqueue2api.parser config_parser_object = configparser.ConfigParser() config_file_location = path.joinpath(path(sys.executable).parent.parent.parent, "webqueue2api_config") if path(config_file_location).exists(): config_parser_object.read(config_file_location) + +if config_parser_object.has_section("parser"): + if config_parser_object.has_option("parser", "queue_directory"): + webqueue2api.parser.config.queue_directory = config_parser_object["parser"]["queue_directory"] From b11d2a8860a84d2e7ff910e348d5036b72c8d517 Mon Sep 17 00:00:00 2001 From: benne238 Date: Wed, 14 Jul 2021 13:48:12 -0400 Subject: [PATCH 3/8] Logic to overwrite the queues_to_ignore if it exists in the configuration file under the parser section --- src/webqueue2api/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/webqueue2api/__init__.py b/src/webqueue2api/__init__.py index 95cbb1f..fcf09eb 100644 --- a/src/webqueue2api/__init__.py +++ b/src/webqueue2api/__init__.py @@ -13,4 +13,5 @@ if config_parser_object.has_section("parser"): if config_parser_object.has_option("parser", "queue_directory"): webqueue2api.parser.config.queue_directory = config_parser_object["parser"]["queue_directory"] - + if config_parser_object.has_option("parser", "queues_to_ignore"): + webqueue2api.parser.config.queues_to_ignore = config_parser_object["parser"]["queues_to_ignore"] From e8115fc9063356a808211891eeebd41f248c8346 Mon Sep 17 00:00:00 2001 From: benne238 Date: Wed, 14 Jul 2021 13:50:43 -0400 Subject: [PATCH 4/8] Added logic to overwrite the environment variable if it exists in the config file under the api section --- src/webqueue2api/__init__.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/webqueue2api/__init__.py b/src/webqueue2api/__init__.py index fcf09eb..ed9c1ff 100644 --- a/src/webqueue2api/__init__.py +++ b/src/webqueue2api/__init__.py @@ -3,6 +3,7 @@ import configparser, sys from pathlib import Path as path import webqueue2api.parser +import webqueue2api.api config_parser_object = configparser.ConfigParser() config_file_location = path.joinpath(path(sys.executable).parent.parent.parent, "webqueue2api_config") @@ -15,3 +16,7 @@ webqueue2api.parser.config.queue_directory = config_parser_object["parser"]["queue_directory"] if config_parser_object.has_option("parser", "queues_to_ignore"): webqueue2api.parser.config.queues_to_ignore = config_parser_object["parser"]["queues_to_ignore"] + +if config_parser_object.has_section("api"): + if config_parser_object.has_option("api", "environment"): + webqueue2api.api.config.environment = config_parser_object["api"]["environment"] \ No newline at end of file From 0a30503fce8f7f36d3acb51a023d48753d0a3216 Mon Sep 17 00:00:00 2001 From: benne238 Date: Wed, 14 Jul 2021 13:55:47 -0400 Subject: [PATCH 5/8] Added logic to overwrite the jwt_secret_key if the variable exists in the config file under the api section --- src/webqueue2api/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/webqueue2api/__init__.py b/src/webqueue2api/__init__.py index ed9c1ff..8b36081 100644 --- a/src/webqueue2api/__init__.py +++ b/src/webqueue2api/__init__.py @@ -19,4 +19,6 @@ if config_parser_object.has_section("api"): if config_parser_object.has_option("api", "environment"): - webqueue2api.api.config.environment = config_parser_object["api"]["environment"] \ No newline at end of file + webqueue2api.api.config.environment = config_parser_object["api"]["environment"] + if config_parser_object.has_option("api", "jwt_secret_key"): + webqueue2api.api.config.jwt_secret_key = config_parser_object["api"]["jwt_secret_key"] \ No newline at end of file From 462182df61c5f595615443353e7fcc2dc52e45b6 Mon Sep 17 00:00:00 2001 From: Justin Campbell Date: Mon, 2 Aug 2021 19:22:59 -0400 Subject: [PATCH 6/8] Simplify config overrides and change config ext --- src/webqueue2api/__init__.py | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/src/webqueue2api/__init__.py b/src/webqueue2api/__init__.py index 8b36081..2461467 100644 --- a/src/webqueue2api/__init__.py +++ b/src/webqueue2api/__init__.py @@ -1,24 +1,22 @@ from webqueue2api.parser import Item, Queue, load_queues -from .config import config import configparser, sys -from pathlib import Path as path -import webqueue2api.parser -import webqueue2api.api - -config_parser_object = configparser.ConfigParser() -config_file_location = path.joinpath(path(sys.executable).parent.parent.parent, "webqueue2api_config") +from pathlib import Path +from .config import config -if path(config_file_location).exists(): - config_parser_object.read(config_file_location) +config_parser = configparser.ConfigParser() +config_file_path = Path.joinpath(Path(sys.executable).parent.parent.parent, "webqueue2api_config.config") -if config_parser_object.has_section("parser"): - if config_parser_object.has_option("parser", "queue_directory"): - webqueue2api.parser.config.queue_directory = config_parser_object["parser"]["queue_directory"] - if config_parser_object.has_option("parser", "queues_to_ignore"): - webqueue2api.parser.config.queues_to_ignore = config_parser_object["parser"]["queues_to_ignore"] +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_object.has_section("api"): - if config_parser_object.has_option("api", "environment"): - webqueue2api.api.config.environment = config_parser_object["api"]["environment"] - if config_parser_object.has_option("api", "jwt_secret_key"): - webqueue2api.api.config.jwt_secret_key = config_parser_object["api"]["jwt_secret_key"] \ No newline at end of file + 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"] \ No newline at end of file From 1600b7c80ec703379487662e451bbcde4cf40784 Mon Sep 17 00:00:00 2001 From: Justin Campbell Date: Mon, 2 Aug 2021 19:23:17 -0400 Subject: [PATCH 7/8] Fix config environment reference --- src/webqueue2api/api/app.py | 2 +- webqueue2api_config.config | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 webqueue2api_config.config diff --git a/src/webqueue2api/api/app.py b/src/webqueue2api/api/app.py index 99282be..477ce50 100644 --- a/src/webqueue2api/api/app.py +++ b/src/webqueue2api/api/app.py @@ -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 diff --git a/webqueue2api_config.config b/webqueue2api_config.config new file mode 100644 index 0000000..81d51dc --- /dev/null +++ b/webqueue2api_config.config @@ -0,0 +1,2 @@ +[api] +environment = dev \ No newline at end of file From 0c4523fac193989fd260dc998fd2c0ce5c23270a Mon Sep 17 00:00:00 2001 From: Justin Campbell Date: Mon, 2 Aug 2021 19:24:04 -0400 Subject: [PATCH 8/8] Remove testing config and rename config ext --- src/webqueue2api/__init__.py | 2 +- webqueue2api_config.config | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) delete mode 100644 webqueue2api_config.config diff --git a/src/webqueue2api/__init__.py b/src/webqueue2api/__init__.py index 2461467..96c62be 100644 --- a/src/webqueue2api/__init__.py +++ b/src/webqueue2api/__init__.py @@ -4,7 +4,7 @@ from .config import config config_parser = configparser.ConfigParser() -config_file_path = Path.joinpath(Path(sys.executable).parent.parent.parent, "webqueue2api_config.config") +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) diff --git a/webqueue2api_config.config b/webqueue2api_config.config deleted file mode 100644 index 81d51dc..0000000 --- a/webqueue2api_config.config +++ /dev/null @@ -1,2 +0,0 @@ -[api] -environment = dev \ No newline at end of file