認証サーバーがserver.jsonの設定ファイルを読み込むように

This commit is contained in:
suti7yk5032 2024-07-20 20:10:18 +09:00
parent 707e2e3ed6
commit 00a4c00fcf

View file

@ -4,23 +4,30 @@ import json
from flask import Flask, request, jsonify, render_template from flask import Flask, request, jsonify, render_template
config_dir_path = "./config/" config_dir_path = "./config/"
db_config_path = config_dir_path + "db.json" server_config_path = config_dir_path + "server.json"
if not os.path.isfile(db_config_path): if not os.path.isfile(server_config_path):
if not os.path.isdir(config_dir_path): if not os.path.isdir(config_dir_path):
os.mkdir(config_dir_path) os.mkdir(config_dir_path)
db_config = { server_config = {
"db": {
"host": "localhost", "host": "localhost",
"db": "dislocker", "port": "5432",
"db_name": "dislocker",
"username": "user", "username": "user",
"password": "example_pass", "password": "password"
"port": "5432" },
"bot": {
"token": "TYPE HERE BOTS TOKEN KEY",
"log_channel_id" : "TYPE HERE CHANNEL ID (YOU MUST USE INT !!!!)",
"config_channel_id": "TYPE HERE CHANNEL ID (YOU MUST USE INT !!!!)"
} }
with open(db_config_path, "w") as w: }
json.dump(db_config, w, indent=4) with open(server_config_path, "w") as w:
elif os.path.isfile(db_config_path): json.dump(server_config, w, indent=4)
with open(db_config_path, "r") as r: elif os.path.isfile(server_config_path):
db_config = json.load(r) with open(server_config_path, "r") as r:
server_config = json.load(r)
class Auth(): class Auth():
def __init__(self, host, db, port, user, password): def __init__(self, host, db, port, user, password):
@ -42,7 +49,7 @@ class Auth():
app = Flask(__name__, static_folder="./resource/") app = Flask(__name__, static_folder="./resource/")
auth = Auth(db_config["host"], db_config["db"], db_config["port"], db_config["username"], db_config["password"]) auth = Auth(server_config["db"]["host"], server_config["db"]["db_name"], server_config["db"]["port"], server_config["db"]["username"], server_config["db"]["password"])
@app.route('/verify', methods=['POST']) @app.route('/verify', methods=['POST'])
def verify(): def verify():