-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: #1 Duplicate user account; feat: Request rate limit, rich based …
…logger, new config parser;
- Loading branch information
Showing
8 changed files
with
66 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,21 @@ | ||
import json | ||
from typing import Any | ||
|
||
|
||
class Config: | ||
def __init__(self, config_path: str): | ||
with open(config_path, "r") as f: | ||
self.config = json.load(f) | ||
self.config: dict = json.load(f) | ||
|
||
def get_db_config(self, key: str) -> Any | None: | ||
try: | ||
return self.config["database"][key] | ||
except: | ||
return None | ||
def get_config(self, *keys) -> object | None: | ||
keys = [*keys] | ||
result: object | None = self.config | ||
while len(keys) > 0: | ||
key = keys.pop(0) | ||
if (isinstance(result, list) and key < len(result)) or (isinstance(result, dict) and key in result.keys()): | ||
result = result[key] | ||
else: | ||
return None | ||
return result | ||
|
||
|
||
config = Config("Configs/config.json") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from slowapi import Limiter | ||
from slowapi.util import get_remote_address | ||
|
||
|
||
limiter = Limiter(key_func=get_remote_address, default_limits=["1000/minute"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters