33 lines
996 B
Python
33 lines
996 B
Python
|
|
import os
|
||
|
|
from dotenv import load_dotenv
|
||
|
|
|
||
|
|
from config import rest_config
|
||
|
|
from custom_logger.main_log import main_logger as LOG
|
||
|
|
|
||
|
|
|
||
|
|
class ApiKeyManager:
|
||
|
|
|
||
|
|
def __init__(self):
|
||
|
|
self.api_key = None
|
||
|
|
|
||
|
|
def set_api_key(self, env_path=rest_config.api_path):
|
||
|
|
|
||
|
|
if os.path.exists(env_path):
|
||
|
|
|
||
|
|
load_dotenv(dotenv_path=env_path)
|
||
|
|
key = os.getenv("GEMINI_API_KEY")
|
||
|
|
|
||
|
|
if key is None:
|
||
|
|
LOG.error(f"api key 파일에 GEMINI_API_KEY라는 변수가 없습니다")
|
||
|
|
elif key == "":
|
||
|
|
LOG.error(f"api key 파일에 내부 변수 GEMINI_API_KEY 값이 빈값입니다 값을 설정해주세요")
|
||
|
|
else:
|
||
|
|
self.api_key = key
|
||
|
|
|
||
|
|
else:
|
||
|
|
LOG.error(f"api key 파일이 없습니다 : {os.path.abspath(env_path)}")
|
||
|
|
|
||
|
|
def get_api_key(self):
|
||
|
|
if self.api_key is not None:
|
||
|
|
return self.api_key
|
||
|
|
|