From 593471a04dd6f69010bbeeb7192eb2cd6d43d14f Mon Sep 17 00:00:00 2001 From: kingbri Date: Wed, 15 Nov 2023 23:00:12 -0500 Subject: [PATCH] Auth: Fix init from YAML dict A class can't have multiple constructors. Signed-off-by: kingbri --- auth.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/auth.py b/auth.py index 3314034..c4a56db 100644 --- a/auth.py +++ b/auth.py @@ -1,7 +1,7 @@ import secrets import yaml from fastapi import Header, HTTPException -from typing import Optional, Dict +from typing import Optional """ This method of authorization is pretty insecure, but since TabbyAPI is a local @@ -16,10 +16,6 @@ class AuthKeys: self.api_key = api_key self.admin_key = admin_key - def __init__(self, d: Dict[str, str] = None): - for key, value in d.items(): - setattr(self, key, value) - auth_keys: Optional[AuthKeys] = None def load_auth_keys(): @@ -27,7 +23,10 @@ def load_auth_keys(): try: with open("api_tokens.yml", "r") as auth_file: auth_keys_dict = yaml.safe_load(auth_file) - auth_keys = AuthKeys(d = auth_keys_dict) + auth_keys = AuthKeys( + api_key = auth_keys_dict["api_key"], + admin_key = auth_keys_dict["admin_key"] + ) except: new_auth_keys = AuthKeys( api_key = secrets.token_hex(16),