Initial skellies for the user stuff

This commit is contained in:
iamBadgers
2026-04-22 19:18:31 -07:00
parent 422ba48ce8
commit a0bc0f0feb
5 changed files with 105 additions and 10 deletions

View File

@@ -22,8 +22,7 @@ def build_container_routing_labels(prefix: str, strip_prefix=True):
labels = {}
labels[router_key] = "Host(`{host_name}`) && PathPrefix(`/{prefix}`)".format(
host_name=host_name,
prefix=prefix
host_name=host_name, prefix=prefix
)
if strip_prefix:
labels[middleware_key] = "/{prefix}".format(prefix=prefix)
@@ -31,6 +30,7 @@ def build_container_routing_labels(prefix: str, strip_prefix=True):
return labels
def delete_container(docker_id) -> bool:
if not docker_id:
return False
@@ -43,6 +43,7 @@ def delete_container(docker_id) -> bool:
except docker.errors.NotFound, docker.errors.APIError:
return False
def stop_container(docker_id) -> bool:
try:
client = docker.from_env()
@@ -56,7 +57,9 @@ def stop_container(docker_id) -> bool:
def start_foundry_container(table: GameTable, key: KeyTable):
client = docker.from_env()
container = None
networkName = client.containers.get(socket.gethostname()).attrs["HostConfig"]["NetworkMode"]
networkName = client.containers.get(socket.gethostname()).attrs["HostConfig"][
"NetworkMode"
]
data_bind = os.environ.get("FOUNDRY_DATA_BIND")
data_volume = os.environ.get("FOUNDRY_DATA_VOL")
@@ -83,19 +86,23 @@ def start_foundry_container(table: GameTable, key: KeyTable):
if data_volume:
os.makedirs("/data/{prefix}".format(prefix=table.game_table_link), exist_ok=True)
os.makedirs(
"/data/{prefix}".format(prefix=table.game_table_link), exist_ok=True
)
mounts = [
docker.types.Mount(
target="/data",
source=data_volume,
type="volume",
subpath=table.game_table_link),
subpath=table.game_table_link,
),
docker.types.Mount(
target="/data/container_cache",
source=data_volume,
type="volume",
subpath="container_cache")
subpath="container_cache",
),
]
container = client.containers.run(
@@ -105,14 +112,14 @@ def start_foundry_container(table: GameTable, key: KeyTable):
environment=environment,
ports=ports,
detach=True,
network=networkName
network=networkName,
)
else:
volumes = {
"{data_bind}/{prefix}".format(
data_bind=os.environ.get("FOUNDRY_DATA_BIND"),
prefix=table.game_table_link,
prefix=table.game_table_link,
): {"bind": "/data", "mode": "rw"},
"{data_bind}/container_cache".format(
data_bind=os.environ.get("FOUNDRY_DATA_BIND")
@@ -126,7 +133,7 @@ def start_foundry_container(table: GameTable, key: KeyTable):
environment=environment,
ports=ports,
detach=True,
network=networkName
network=networkName,
)
return container.id

View File

@@ -32,11 +32,21 @@ CREATE TABLE IF NOT EXISTS "game_keys" (
);
"""
_user_table_create = """
CREATE TABLE IF NOT EXISTS "" (
"id": INTEGER NOT NULL,
"username": TEXT NOT NULL,
"hash": TEXT NOT NULL,
PRIMARY KEY ("ID)
);
"""
def init_db(connection):
with SmartCursor(connection=connection) as smart_cursor:
smart_cursor.execute(_game_table_create)
smart_cursor.execute(_key_table_create)
smart_cursor.execute(_user_table_create)
connection.commit()

View File

@@ -53,7 +53,9 @@ class GameTable:
def commit(self, cursor):
if not self._created:
self._game_table_id = cursor.execute("""SELECT MAX(game_table_id) + 1 FROM game_tables""").fetchone()[0]
self._game_table_id = cursor.execute(
"""SELECT MAX(game_table_id) + 1 FROM game_tables"""
).fetchone()[0]
cursor.execute(
"""INSERT INTO game_tables

View File

@@ -5,6 +5,7 @@ from database import SmartCursor, get_db, init_db
import tables
import os
def create_app():
app = Flask(__name__)

75
src/users.py Normal file
View File

@@ -0,0 +1,75 @@
from typeing import List
from flask import Blueprint, current_app
from werkzeug.security import generate_password_hash, check_password_hash
class User:
_id: int
_username: str
_hash: str
_updated: bool
_created: bool
_delete: bool
def __init__(
self,
id,
username,
hash,
created: bool = False,
updated: bool = False,
delete: bool = False,
):
return
def check_password(self, password: str):
return
def commit(self):
return
@property
def hash(self):
return self._hash
@hash.setter
def set_hash(self, password: str):
self._updated = False
self._hash = generate_password_hash(password)
@property
def username(self):
return self.username
@username.setter
def set_username(self, username):
self._updated = False
self._username = username
class UserService:
def __init__():
return
def read_by_username(username: str) -> User:
return
def read_all() -> List[User]:
return []
def check_login(username: str, password: str):
return;
users = Blueprint("users_api", __name__)
@users.route("/login", method=["POST"])
def login():
return
@users.route("/logout", method=["POST"])
def logout():
return