Skip to content

Commit b650eb2

Browse files
committed
switch to toml based config
1 parent ca4271b commit b650eb2

7 files changed

+132
-72
lines changed

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -139,4 +139,7 @@ dmypy.json
139139
# Pyre type checker
140140
.pyre/
141141

142-
config.py
142+
#config.py
143+
devices/
144+
util_scripts
145+
*.toml

config.toml.example

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
[general]
2+
# Auto generated on first run if empty
3+
secret_key = ""
4+
database_uri = "sqlite:///db.sqlite3"
5+
redis_uri = "redis://localhost:6379/0"
6+
max_sessions = 60
7+
# List of CDMs that are used in CDM rotation
8+
default_cdms = ["cdm_identifier"]
9+
# List of CDMs that should use the blacklist, these are considered to be GetWVKeys System CDMs.
10+
system_cdms = ["cdm_identifier"]
11+
guild_id = ""
12+
verified_role_id = ""
13+
login_disabled = false
14+
registration_disabled = false
15+
log_format = "[%(asctime)s] [%(name)s] [%(funcName)s:%(lineno)d] %(levelname)s: %(message)s"
16+
log_date_format = "%I:%M:%S"
17+
18+
[api]
19+
host = "0.0.0.0"
20+
port = 8080
21+
base_url = "http://localhost:8080"
22+
23+
###
24+
# OAuth2 Configuration
25+
###
26+
[oauth]
27+
# Discord OAuth Client ID
28+
client_id = ""
29+
# Discord OAuth Client Secret
30+
client_secret = ""
31+
# Discord OAuth Redirect URI
32+
redirect_url = ""
33+
34+
[[url_blacklist]]
35+
url = ".*my\\.awesome\\.site\\.com.*"
36+
partial = true
37+
38+
[[url_blacklist]]
39+
url = "https://example.com/some_page_to_block"
40+
partial = false
41+
42+
[[external_build_info]]
43+
buildinfo = "build_info_string"
44+
url = "https://example.com/api"
45+
token = "s3cr$t"

getwvkeys/config.py

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
"""
2+
This file is part of the GetWVKeys project (https://github.com/GetWVKeys/getwvkeys)
3+
Copyright (C) 2022-2024 Notaghost, Puyodead1 and GetWVKeys contributors
4+
5+
This program is free software: you can redistribute it and/or modify
6+
it under the terms of the GNU Affero General Public License as published
7+
by the Free Software Foundation, version 3 of the License.
8+
9+
This program is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU Affero General Public License for more details.
13+
14+
You should have received a copy of the GNU Affero General Public License
15+
along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
"""
17+
18+
import logging
19+
import os
20+
import pathlib
21+
import time
22+
23+
import toml
24+
25+
logger = logging.getLogger(__name__)
26+
27+
IS_DEVELOPMENT = bool(os.environ.get("DEVELOPMENT", False))
28+
IS_STAGING = bool(os.environ.get("STAGING", False))
29+
CONFIG_FILE = "config.dev.toml" if IS_DEVELOPMENT else "config.staging.toml" if IS_STAGING else "config.toml"
30+
CONFIG = toml.load(CONFIG_FILE)
31+
32+
SECRET_KEY = CONFIG["general"]["secret_key"] # Flask secret key
33+
# auto generate secret key if not set
34+
if not SECRET_KEY:
35+
logger.warning("No secret key found in config.toml, generating a new one.")
36+
SECRET_KEY = os.urandom(32).hex()
37+
CONFIG["general"]["secret_key"] = SECRET_KEY
38+
with open(CONFIG_FILE, "w") as f:
39+
toml.dump(CONFIG, f)
40+
41+
OAUTH2_CLIENT_ID = CONFIG["oauth"]["client_id"] # Discord OAuth Client ID
42+
OAUTH2_CLIENT_SECRET = CONFIG["oauth"]["client_secret"] # Discord OAuth Client Secret
43+
OAUTH2_REDIRECT_URL = CONFIG["oauth"]["redirect_url"] # Discord OAuth Callback URL
44+
SQLALCHEMY_DATABASE_URI = CONFIG["general"]["database_uri"] # Database connection URI
45+
REDIS_URI = CONFIG["general"].get("redis_uri", None) # Redis connection URI
46+
47+
API_HOST = CONFIG.get("api", {}).get("host", "0.0.0.0")
48+
API_PORT = int(CONFIG.get("api", {}).get("port", 8080))
49+
API_URL = CONFIG.get("api", {}).get("base_url", "https://getwvkeys.cc")
50+
51+
MAX_SESSIONS = CONFIG["general"].get("max_sessions", 60)
52+
PROXY = {}
53+
DEFAULT_CDMS = CONFIG["general"].get("default_cdms", []) # list of build infos to use in key rotation
54+
APPENDERS = [] # passwords for dumping keys, deprecated in favor of flags
55+
GUILD_ID = CONFIG["general"]["guild_id"] # Discord Guild ID
56+
VERIFIED_ROLE_ID = CONFIG["general"]["verified_role_id"] # Discord Verified role ID
57+
LOGIN_DISABLED = CONFIG["general"].get("login_disabled", False)
58+
CONSOLE_LOG_LEVEL = logging.DEBUG
59+
FILE_LOG_LEVEL = logging.DEBUG
60+
LOG_FORMAT = CONFIG["general"].get(
61+
"log_format",
62+
"[%(asctime)s] [%(name)s] [%(funcName)s:%(lineno)d] %(levelname)s: %(message)s",
63+
)
64+
LOG_DATE_FORMAT = CONFIG["general"].get("log_date_format", "%I:%M:%S")
65+
WVK_LOG_FILE_PATH = pathlib.Path(os.getcwd(), "logs", f"GWVK_{time.strftime('%Y-%m-%d')}.log")
66+
URL_BLACKLIST = CONFIG.get("url_blacklist", [])
67+
EXTERNAL_API_BUILD_INFOS = CONFIG.get("external_build_info", [])
68+
# List of CDMs that should use the blacklist, these are considered to be GetWVKeys System CDMs.
69+
SYSTEM_CDMS = CONFIG["general"].get("system_cdms", [])

getwvkeys/config.py.example

-68
This file was deleted.

getwvkeys/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ class Blacklist:
217217
def __init__(self) -> None:
218218
self.blacklist: list[BlacklistEntry] = list()
219219

220-
for x in config.DEFAULT_BLACKLISTED_URLS:
220+
for x in config.URL_BLACKLIST:
221221
self.blacklist.append(BlacklistEntry(x))
222222

223223
def is_url_blacklisted(self, url: str):

poetry.lock

+12-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ mariadb = "^1.1.10"
2929
sqlalchemy = ">=2.0.16"
3030
waitress = "^3.0.0"
3131
flask-caching = "^2.3.0"
32+
toml = "^0.10.2"
3233

3334
[tool.poetry.dev-dependencies]
3435
black = "^22.3.0"

0 commit comments

Comments
 (0)