Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a6a5de4a35
|
||
|
|
6ad50df3c2
|
||
|
|
6243618abb
|
@@ -1,5 +1,2 @@
|
|||||||
__pycache__
|
__pycache__
|
||||||
gatekeeper.db
|
gatekeeper.db
|
||||||
.env
|
|
||||||
.coverage
|
|
||||||
result
|
|
||||||
|
|||||||
Vendored
-11
@@ -1,11 +0,0 @@
|
|||||||
{
|
|
||||||
"[python]": {
|
|
||||||
"editor.formatOnSave": true,
|
|
||||||
"editor.defaultFormatter": "charliermarsh.ruff"
|
|
||||||
},
|
|
||||||
"python.testing.pytestArgs": [
|
|
||||||
"test"
|
|
||||||
],
|
|
||||||
"python.testing.unittestEnabled": false,
|
|
||||||
"python.testing.pytestEnabled": true
|
|
||||||
}
|
|
||||||
@@ -1,47 +1,15 @@
|
|||||||
## Gatekeeper - Door access system
|
## Gatekeeper - Door access system
|
||||||
#### Status: "WORKING" - Base functionality is there, mayor issues
|
Status: WIP - not prod ready
|
||||||
|
|
||||||
Start prod server `nix run`<br>
|
Dev with `nix develop`
|
||||||
Start dev server `nix run .#dev` or `nix run .#dev -- {args}`<br>
|
start dev server `uv run fastapi dev`
|
||||||
Interactive dev with `nix develop`, then sync deps with `uv sync`<br>
|
Swagger UI @ http://127.0.0.1:8000/docs
|
||||||
There is a nix module you can use by importing `inputs.gatekeeper.nixosModules.gatekeeper`<br>
|
start prod server `uv run fastapi run`
|
||||||
Swagger UI @ http://127.0.0.1:8000/api/v1/docs<br>
|
|
||||||
OpenApi @ http://127.0.0.1:8000/api/v1/openapi.json<br>
|
|
||||||
|
|
||||||
#### Config:
|
Issues:
|
||||||
|
- `nix run` currently broken
|
||||||
Nixos config for the card reader:
|
- no auth
|
||||||
```
|
- no door state
|
||||||
services.pcscd = {
|
- no door operations
|
||||||
enable = true;
|
- card system is dummy until I get hardware
|
||||||
plugins = [ pkgs.acsccid ]; #<-- Needed for the ACE1552U
|
|
||||||
};
|
|
||||||
```
|
|
||||||
|
|
||||||
This application is configured using env vars. You can use `cp .env.example .env` and then edit `.env` to change the keys to something else.
|
|
||||||
|
|
||||||
|
|
||||||
### A note on keycard scanners
|
|
||||||
I have tried two scanners while developing this project, the TWN4 MultiTech 2 from elatec and the ACR1552U from acs.<br>
|
|
||||||
##### TWN4
|
|
||||||
From the factory the TWN4 comes with firmware that emulates a HID and just inputs the serial of any scanned card. To be usable with pcscd it had to be flashed with the `TWN4_xPx520_S1SC161_Multi_CCID_1Slot_Standard.bix` firmware found in the `TWN4DevPack520` which can be downloaded under https://www.elatec-rfid.com/int/elatec-software (They send you a download link via email).
|
|
||||||
This software seems to not work under wine. I had to setup a win10 vm and pass the usb to be able to flash.<br>
|
|
||||||
Range: In my testing the TWN4 has a range of about 22mm when interfacing with our Mifare DESFire v2 cards. This is not enough for our idea of mounting the scanner on the inside of a glass window.
|
|
||||||
|
|
||||||
#### ACR1552U
|
|
||||||
The ACR1552U comes preloaded with PC/SC firmware. You need to install the acsccid package with your package-manager of choice (Nixos user see above) for the scanner to work but after that I had no problems with the hardware interfacing.<br>
|
|
||||||
Range: The range of the ACR1552U was much better at over 60mm (almost 70mm if you take of the face plate)
|
|
||||||
|
|
||||||
|
|
||||||
#### Issues:
|
|
||||||
- cards can only unlock, not lock
|
|
||||||
- documentation missing
|
|
||||||
- i don't like the error handling in the scanner - doesn't pass errors correctly
|
|
||||||
- cors for frontend: https://fastapi.tiangolo.com/tutorial/cors
|
|
||||||
- Load cors from env var or something
|
|
||||||
- BackgroundScanner shouldn't get a single session for the whole lifecycle
|
|
||||||
- input validation maybe
|
|
||||||
- inconsistent logging (request logging?)
|
|
||||||
- rate limiting maybe
|
|
||||||
- pretty sure the controllers are doing too much stuff
|
|
||||||
- hardware call tests or sth
|
|
||||||
|
|||||||
-149
@@ -1,149 +0,0 @@
|
|||||||
# A generic, single database configuration.
|
|
||||||
|
|
||||||
[alembic]
|
|
||||||
# path to migration scripts.
|
|
||||||
# this is typically a path given in POSIX (e.g. forward slashes)
|
|
||||||
# format, relative to the token %(here)s which refers to the location of this
|
|
||||||
# ini file
|
|
||||||
script_location = %(here)s/alembic
|
|
||||||
|
|
||||||
# template used to generate migration file names; The default value is %%(rev)s_%%(slug)s
|
|
||||||
# Uncomment the line below if you want the files to be prepended with date and time
|
|
||||||
# see https://alembic.sqlalchemy.org/en/latest/tutorial.html#editing-the-ini-file
|
|
||||||
# for all available tokens
|
|
||||||
# file_template = %%(year)d_%%(month).2d_%%(day).2d_%%(hour).2d%%(minute).2d-%%(rev)s_%%(slug)s
|
|
||||||
# Or organize into date-based subdirectories (requires recursive_version_locations = true)
|
|
||||||
# file_template = %%(year)d/%%(month).2d/%%(day).2d_%%(hour).2d%%(minute).2d_%%(second).2d_%%(rev)s_%%(slug)s
|
|
||||||
|
|
||||||
# sys.path path, will be prepended to sys.path if present.
|
|
||||||
# defaults to the current working directory. for multiple paths, the path separator
|
|
||||||
# is defined by "path_separator" below.
|
|
||||||
prepend_sys_path = .
|
|
||||||
|
|
||||||
|
|
||||||
# timezone to use when rendering the date within the migration file
|
|
||||||
# as well as the filename.
|
|
||||||
# If specified, requires the tzdata library which can be installed by adding
|
|
||||||
# `alembic[tz]` to the pip requirements.
|
|
||||||
# string value is passed to ZoneInfo()
|
|
||||||
# leave blank for localtime
|
|
||||||
# timezone =
|
|
||||||
|
|
||||||
# max length of characters to apply to the "slug" field
|
|
||||||
# truncate_slug_length = 40
|
|
||||||
|
|
||||||
# set to 'true' to run the environment during
|
|
||||||
# the 'revision' command, regardless of autogenerate
|
|
||||||
# revision_environment = false
|
|
||||||
|
|
||||||
# set to 'true' to allow .pyc and .pyo files without
|
|
||||||
# a source .py file to be detected as revisions in the
|
|
||||||
# versions/ directory
|
|
||||||
# sourceless = false
|
|
||||||
|
|
||||||
# version location specification; This defaults
|
|
||||||
# to <script_location>/versions. When using multiple version
|
|
||||||
# directories, initial revisions must be specified with --version-path.
|
|
||||||
# The path separator used here should be the separator specified by "path_separator"
|
|
||||||
# below.
|
|
||||||
# version_locations = %(here)s/bar:%(here)s/bat:%(here)s/alembic/versions
|
|
||||||
|
|
||||||
# path_separator; This indicates what character is used to split lists of file
|
|
||||||
# paths, including version_locations and prepend_sys_path within configparser
|
|
||||||
# files such as alembic.ini.
|
|
||||||
# The default rendered in new alembic.ini files is "os", which uses os.pathsep
|
|
||||||
# to provide os-dependent path splitting.
|
|
||||||
#
|
|
||||||
# Note that in order to support legacy alembic.ini files, this default does NOT
|
|
||||||
# take place if path_separator is not present in alembic.ini. If this
|
|
||||||
# option is omitted entirely, fallback logic is as follows:
|
|
||||||
#
|
|
||||||
# 1. Parsing of the version_locations option falls back to using the legacy
|
|
||||||
# "version_path_separator" key, which if absent then falls back to the legacy
|
|
||||||
# behavior of splitting on spaces and/or commas.
|
|
||||||
# 2. Parsing of the prepend_sys_path option falls back to the legacy
|
|
||||||
# behavior of splitting on spaces, commas, or colons.
|
|
||||||
#
|
|
||||||
# Valid values for path_separator are:
|
|
||||||
#
|
|
||||||
# path_separator = :
|
|
||||||
# path_separator = ;
|
|
||||||
# path_separator = space
|
|
||||||
# path_separator = newline
|
|
||||||
#
|
|
||||||
# Use os.pathsep. Default configuration used for new projects.
|
|
||||||
path_separator = os
|
|
||||||
|
|
||||||
# set to 'true' to search source files recursively
|
|
||||||
# in each "version_locations" directory
|
|
||||||
# new in Alembic version 1.10
|
|
||||||
# recursive_version_locations = false
|
|
||||||
|
|
||||||
# the output encoding used when revision files
|
|
||||||
# are written from script.py.mako
|
|
||||||
# output_encoding = utf-8
|
|
||||||
|
|
||||||
# database URL. This is consumed by the user-maintained env.py script only.
|
|
||||||
# other means of configuring database URLs may be customized within the env.py
|
|
||||||
# file.
|
|
||||||
sqlalchemy.url = sqlite:///./gatekeeper.db
|
|
||||||
|
|
||||||
|
|
||||||
[post_write_hooks]
|
|
||||||
# post_write_hooks defines scripts or Python functions that are run
|
|
||||||
# on newly generated revision scripts. See the documentation for further
|
|
||||||
# detail and examples
|
|
||||||
|
|
||||||
# format using "black" - use the console_scripts runner, against the "black" entrypoint
|
|
||||||
# hooks = black
|
|
||||||
# black.type = console_scripts
|
|
||||||
# black.entrypoint = black
|
|
||||||
# black.options = -l 79 REVISION_SCRIPT_FILENAME
|
|
||||||
|
|
||||||
# lint with attempts to fix using "ruff" - use the module runner, against the "ruff" module
|
|
||||||
# hooks = ruff
|
|
||||||
# ruff.type = module
|
|
||||||
# ruff.module = ruff
|
|
||||||
# ruff.options = check --fix REVISION_SCRIPT_FILENAME
|
|
||||||
|
|
||||||
# Alternatively, use the exec runner to execute a binary found on your PATH
|
|
||||||
# hooks = ruff
|
|
||||||
# ruff.type = exec
|
|
||||||
# ruff.executable = ruff
|
|
||||||
# ruff.options = check --fix REVISION_SCRIPT_FILENAME
|
|
||||||
|
|
||||||
# Logging configuration. This is also consumed by the user-maintained
|
|
||||||
# env.py script only.
|
|
||||||
[loggers]
|
|
||||||
keys = root,sqlalchemy,alembic
|
|
||||||
|
|
||||||
[handlers]
|
|
||||||
keys = console
|
|
||||||
|
|
||||||
[formatters]
|
|
||||||
keys = generic
|
|
||||||
|
|
||||||
[logger_root]
|
|
||||||
level = WARNING
|
|
||||||
handlers = console
|
|
||||||
qualname =
|
|
||||||
|
|
||||||
[logger_sqlalchemy]
|
|
||||||
level = WARNING
|
|
||||||
handlers =
|
|
||||||
qualname = sqlalchemy.engine
|
|
||||||
|
|
||||||
[logger_alembic]
|
|
||||||
level = INFO
|
|
||||||
handlers =
|
|
||||||
qualname = alembic
|
|
||||||
|
|
||||||
[handler_console]
|
|
||||||
class = StreamHandler
|
|
||||||
args = (sys.stderr,)
|
|
||||||
level = NOTSET
|
|
||||||
formatter = generic
|
|
||||||
|
|
||||||
[formatter_generic]
|
|
||||||
format = %(levelname)-5.5s [%(name)s] %(message)s
|
|
||||||
datefmt = %H:%M:%S
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
Generic single-database configuration.
|
|
||||||
@@ -1,80 +0,0 @@
|
|||||||
from logging.config import fileConfig
|
|
||||||
|
|
||||||
from sqlalchemy import engine_from_config
|
|
||||||
from sqlalchemy import pool
|
|
||||||
|
|
||||||
from alembic import context
|
|
||||||
|
|
||||||
# this is the Alembic Config object, which provides
|
|
||||||
# access to the values within the .ini file in use.
|
|
||||||
config = context.config
|
|
||||||
|
|
||||||
# Interpret the config file for Python logging.
|
|
||||||
# This line sets up loggers basically.
|
|
||||||
#if config.config_file_name is not None:
|
|
||||||
# fileConfig(config.config_file_name, disable_existing_loggers=False)
|
|
||||||
|
|
||||||
# add your model's MetaData object here
|
|
||||||
# for 'autogenerate' support
|
|
||||||
# from myapp import mymodel
|
|
||||||
# target_metadata = mymodel.Base.metadata
|
|
||||||
from app.model import models
|
|
||||||
|
|
||||||
target_metadata = models.Base.metadata
|
|
||||||
|
|
||||||
# other values from the config, defined by the needs of env.py,
|
|
||||||
# can be acquired:
|
|
||||||
# my_important_option = config.get_main_option("my_important_option")
|
|
||||||
# ... etc.
|
|
||||||
|
|
||||||
|
|
||||||
def run_migrations_offline() -> None:
|
|
||||||
"""Run migrations in 'offline' mode.
|
|
||||||
|
|
||||||
This configures the context with just a URL
|
|
||||||
and not an Engine, though an Engine is acceptable
|
|
||||||
here as well. By skipping the Engine creation
|
|
||||||
we don't even need a DBAPI to be available.
|
|
||||||
|
|
||||||
Calls to context.execute() here emit the given string to the
|
|
||||||
script output.
|
|
||||||
|
|
||||||
"""
|
|
||||||
url = config.get_main_option("sqlalchemy.url")
|
|
||||||
context.configure(
|
|
||||||
url=url,
|
|
||||||
target_metadata=target_metadata,
|
|
||||||
literal_binds=True,
|
|
||||||
dialect_opts={"paramstyle": "named"},
|
|
||||||
)
|
|
||||||
|
|
||||||
with context.begin_transaction():
|
|
||||||
context.run_migrations()
|
|
||||||
|
|
||||||
|
|
||||||
def run_migrations_online() -> None:
|
|
||||||
"""Run migrations in 'online' mode.
|
|
||||||
|
|
||||||
In this scenario we need to create an Engine
|
|
||||||
and associate a connection with the context.
|
|
||||||
|
|
||||||
"""
|
|
||||||
connectable = engine_from_config(
|
|
||||||
config.get_section(config.config_ini_section, {}),
|
|
||||||
prefix="sqlalchemy.",
|
|
||||||
poolclass=pool.NullPool,
|
|
||||||
)
|
|
||||||
|
|
||||||
with connectable.connect() as connection:
|
|
||||||
context.configure(
|
|
||||||
connection=connection, target_metadata=target_metadata
|
|
||||||
)
|
|
||||||
|
|
||||||
with context.begin_transaction():
|
|
||||||
context.run_migrations()
|
|
||||||
|
|
||||||
|
|
||||||
if context.is_offline_mode():
|
|
||||||
run_migrations_offline()
|
|
||||||
else:
|
|
||||||
run_migrations_online()
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
"""${message}
|
|
||||||
|
|
||||||
Revision ID: ${up_revision}
|
|
||||||
Revises: ${down_revision | comma,n}
|
|
||||||
Create Date: ${create_date}
|
|
||||||
|
|
||||||
"""
|
|
||||||
from typing import Sequence, Union
|
|
||||||
|
|
||||||
from alembic import op
|
|
||||||
import sqlalchemy as sa
|
|
||||||
${imports if imports else ""}
|
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
|
||||||
revision: str = ${repr(up_revision)}
|
|
||||||
down_revision: Union[str, Sequence[str], None] = ${repr(down_revision)}
|
|
||||||
branch_labels: Union[str, Sequence[str], None] = ${repr(branch_labels)}
|
|
||||||
depends_on: Union[str, Sequence[str], None] = ${repr(depends_on)}
|
|
||||||
|
|
||||||
|
|
||||||
def upgrade() -> None:
|
|
||||||
"""Upgrade schema."""
|
|
||||||
${upgrades if upgrades else "pass"}
|
|
||||||
|
|
||||||
|
|
||||||
def downgrade() -> None:
|
|
||||||
"""Downgrade schema."""
|
|
||||||
${downgrades if downgrades else "pass"}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
"""init
|
|
||||||
|
|
||||||
Revision ID: 4a40fa23e086
|
|
||||||
Revises:
|
|
||||||
Create Date: 2026-07-28 00:07:19.402303
|
|
||||||
|
|
||||||
"""
|
|
||||||
from typing import Sequence, Union
|
|
||||||
|
|
||||||
from alembic import op
|
|
||||||
import sqlalchemy as sa
|
|
||||||
|
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
|
||||||
revision: str = '4a40fa23e086'
|
|
||||||
down_revision: Union[str, Sequence[str], None] = None
|
|
||||||
branch_labels: Union[str, Sequence[str], None] = None
|
|
||||||
depends_on: Union[str, Sequence[str], None] = None
|
|
||||||
|
|
||||||
|
|
||||||
def upgrade() -> None:
|
|
||||||
"""Upgrade schema."""
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def downgrade() -> None:
|
|
||||||
"""Downgrade schema."""
|
|
||||||
pass
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
MIFARE_APP_MASTER_KEY="7b195adb892073c9e34ebe7e0ca28b2b"
|
|
||||||
# 16 bytes AES key
|
|
||||||
MIFARE_ACL_READ_BASE_KEY="741a50f2b189cc9f151e0600f50a6e1a"
|
|
||||||
# 16 bytes AES key
|
|
||||||
MIFARE_ACL_WRITE_BASE_KEY="f1aa99f81cca268de98d422ee0ccb65c"
|
|
||||||
# 16 bytes AES key
|
|
||||||
SECRET_KEY="8b14d0b447bff7efa24d5019cc59a999786e31f6f865173bbd642bf18de5ad85"
|
|
||||||
#Key for oauth
|
|
||||||
#THESE ARE TESTING KEYS - DO NOT USE IN PROD
|
|
||||||
|
|
||||||
SQLALCHEMY_DATABASE_PATH="./gatekeeper.db"
|
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
from fastapi import FastAPI
|
||||||
|
from .controllers import userManager, cardManager
|
||||||
|
|
||||||
|
app = FastAPI()
|
||||||
|
app.include_router(userManager.user_router)
|
||||||
|
app.include_router(cardManager.card_router)
|
||||||
+25
-100
@@ -1,85 +1,41 @@
|
|||||||
import logging
|
from fastapi import APIRouter, Depends, HTTPException
|
||||||
|
|
||||||
from fastapi import APIRouter, Depends, HTTPException, status
|
|
||||||
from sqlalchemy.orm import selectinload
|
|
||||||
from sqlmodel import Session, select
|
from sqlmodel import Session, select
|
||||||
|
from sqlalchemy.orm import selectinload
|
||||||
|
from typing import List
|
||||||
|
|
||||||
from app.model.models import (
|
from ..model.models import *
|
||||||
AccessAuthorizationCreate,
|
from ..services.database import engine, get_session, add_and_refresh
|
||||||
AccessAuthorizationDB,
|
import uuid as gen_uuid
|
||||||
AccessAuthorizationResponse,
|
|
||||||
AccessAuthorizationUpdate,
|
|
||||||
GroupDB,
|
|
||||||
GroupResponse,
|
|
||||||
OneShotAccess,
|
|
||||||
Timetable,
|
|
||||||
)
|
|
||||||
from app.services.auth import auth_is_admin
|
|
||||||
from app.services.database import add_and_refresh, get_session
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
aa_router = APIRouter(prefix="/api/v1/aa", tags=["AccessAuth"])
|
|
||||||
|
|
||||||
|
aa_router = APIRouter(prefix="/aa", tags=["AccessAuth"])
|
||||||
|
|
||||||
@aa_router.post("/", response_model=AccessAuthorizationResponse)
|
@aa_router.post("/", response_model=AccessAuthorizationResponse)
|
||||||
def add_accessauth(
|
def add_accessauth(*, db: Session = Depends(get_session), aa: AccessAuthorizationCreate):
|
||||||
*,
|
print("Creating accessauth with data: ", aa)
|
||||||
db: Session = Depends(get_session),
|
timetables = [Timetable.model_validate(t) for t in aa.timetables]
|
||||||
aa: AccessAuthorizationCreate,
|
|
||||||
admin: bool = Depends(auth_is_admin),
|
|
||||||
):
|
|
||||||
logger.info(f"Creating accessauth with data: {aa}")
|
|
||||||
if aa.timetables != []:
|
|
||||||
timetables = [Timetable.model_validate(t) for t in aa.timetables]
|
|
||||||
else:
|
|
||||||
timetables = []
|
|
||||||
if aa.oneshot is not None:
|
|
||||||
oneshot = OneShotAccess.model_validate(aa.oneshot)
|
|
||||||
else:
|
|
||||||
oneshot = None
|
|
||||||
db_aa = AccessAuthorizationDB(
|
db_aa = AccessAuthorizationDB(
|
||||||
name=aa.name,
|
name=aa.name,
|
||||||
type=aa.type,
|
|
||||||
is_active=aa.is_active,
|
is_active=aa.is_active,
|
||||||
timetables=timetables,
|
timetables=timetables
|
||||||
oneshot=oneshot,
|
|
||||||
)
|
)
|
||||||
return add_and_refresh(db, db_aa)
|
return add_and_refresh(db, db_aa)
|
||||||
|
|
||||||
|
@aa_router.get("/", response_model=List[AccessAuthorizationResponse])
|
||||||
@aa_router.get("/", response_model=list[AccessAuthorizationResponse])
|
def get_all_accessauths(db: Session = Depends(get_session)):
|
||||||
def get_all_accessauths(
|
|
||||||
db: Session = Depends(get_session), admin: bool = Depends(auth_is_admin)
|
|
||||||
):
|
|
||||||
return db.exec(
|
return db.exec(
|
||||||
select(AccessAuthorizationDB).options(
|
select(AccessAuthorizationDB)
|
||||||
selectinload(AccessAuthorizationDB.timetables)
|
.options(selectinload(AccessAuthorizationDB.timetables))
|
||||||
)
|
).all()
|
||||||
).all()
|
|
||||||
|
|
||||||
|
|
||||||
@aa_router.get("/{aa_id}", response_model=AccessAuthorizationResponse)
|
@aa_router.get("/{aa_id}", response_model=AccessAuthorizationResponse)
|
||||||
def get_one_accessauth(
|
def get_one_accessauth(*, db: Session = Depends(get_session), aa_id: int):
|
||||||
*,
|
|
||||||
db: Session = Depends(get_session),
|
|
||||||
aa_id: int,
|
|
||||||
admin: bool = Depends(auth_is_admin),
|
|
||||||
):
|
|
||||||
db_aa = db.get(AccessAuthorizationDB, aa_id)
|
db_aa = db.get(AccessAuthorizationDB, aa_id)
|
||||||
if db_aa is None:
|
if db_aa is None:
|
||||||
raise HTTPException(status_code=404, detail="AA not found")
|
raise HTTPException(status_code=404, detail="AA not found")
|
||||||
return db_aa
|
return db_aa
|
||||||
|
|
||||||
|
|
||||||
@aa_router.put("/assign/{group_id}/{aa_id}", response_model=GroupResponse)
|
@aa_router.put("/assign/{group_id}/{aa_id}", response_model=GroupResponse)
|
||||||
def assign_accessauth(
|
def assign_accessauth(*, db: Session = Depends(get_session), group_id: int, aa_id: int):
|
||||||
*,
|
|
||||||
db: Session = Depends(get_session),
|
|
||||||
group_id: int,
|
|
||||||
aa_id: int,
|
|
||||||
admin: bool = Depends(auth_is_admin),
|
|
||||||
):
|
|
||||||
db_group = db.get(GroupDB, group_id)
|
db_group = db.get(GroupDB, group_id)
|
||||||
if db_group is None:
|
if db_group is None:
|
||||||
raise HTTPException(status_code=404, detail="Group not found")
|
raise HTTPException(status_code=404, detail="Group not found")
|
||||||
@@ -87,21 +43,12 @@ def assign_accessauth(
|
|||||||
if db_aa is None:
|
if db_aa is None:
|
||||||
raise HTTPException(status_code=404, detail="AA not found")
|
raise HTTPException(status_code=404, detail="AA not found")
|
||||||
if db_aa in db_group.accessauths:
|
if db_aa in db_group.accessauths:
|
||||||
raise HTTPException(
|
raise HTTPException(status_code=200, detail="AA already assigned to group")
|
||||||
status_code=status.HTTP_409_CONFLICT, detail="AA already assigned to group"
|
|
||||||
)
|
|
||||||
db_group.accessauths.append(db_aa)
|
db_group.accessauths.append(db_aa)
|
||||||
return add_and_refresh(db, db_group)
|
return add_and_refresh(db, db_group)
|
||||||
|
|
||||||
|
|
||||||
@aa_router.put("/unassign/{group_id}/{aa_id}", response_model=GroupResponse)
|
@aa_router.put("/unassign/{group_id}/{aa_id}", response_model=GroupResponse)
|
||||||
def unassign_accessauth(
|
def unassign_accessauth(*, db: Session = Depends(get_session), group_id: int, aa_id: int):
|
||||||
*,
|
|
||||||
db: Session = Depends(get_session),
|
|
||||||
group_id: int,
|
|
||||||
aa_id: int,
|
|
||||||
admin: bool = Depends(auth_is_admin),
|
|
||||||
):
|
|
||||||
db_group = db.get(GroupDB, group_id)
|
db_group = db.get(GroupDB, group_id)
|
||||||
if db_group is None:
|
if db_group is None:
|
||||||
raise HTTPException(status_code=404, detail="Group not found")
|
raise HTTPException(status_code=404, detail="Group not found")
|
||||||
@@ -109,46 +56,24 @@ def unassign_accessauth(
|
|||||||
if db_aa is None:
|
if db_aa is None:
|
||||||
raise HTTPException(status_code=404, detail="AA not found")
|
raise HTTPException(status_code=404, detail="AA not found")
|
||||||
if db_aa not in db_group.accessauths:
|
if db_aa not in db_group.accessauths:
|
||||||
raise HTTPException(status_code=404, detail="AA not assigned to group")
|
raise HTTPException(status_code=200, detail="AA not assigned to group")
|
||||||
db_group.accessauths.remove(db_aa)
|
db_group.accessauths.remove(db_aa)
|
||||||
return add_and_refresh(db, db_group)
|
return add_and_refresh(db, db_group)
|
||||||
|
|
||||||
|
|
||||||
@aa_router.patch("/{aa_id}", response_model=AccessAuthorizationResponse)
|
@aa_router.patch("/{aa_id}", response_model=AccessAuthorizationResponse)
|
||||||
def change_accessauth(
|
def change_accessauth(*, db: Session = Depends(get_session), aa_id: int, aa: AccessAuthorizationUpdate):
|
||||||
*,
|
|
||||||
db: Session = Depends(get_session),
|
|
||||||
aa_id: int,
|
|
||||||
aa: AccessAuthorizationUpdate,
|
|
||||||
admin: bool = Depends(auth_is_admin),
|
|
||||||
):
|
|
||||||
db_aa = db.get(AccessAuthorizationDB, aa_id)
|
db_aa = db.get(AccessAuthorizationDB, aa_id)
|
||||||
if db_aa is None:
|
if db_aa is None:
|
||||||
raise HTTPException(status_code=404, detail="AccessAuthorization not found")
|
raise HTTPException(status_code=404, detail="AccessAuthorization not found")
|
||||||
aa_data = aa.model_dump(exclude_unset=True, exclude_none=True)
|
aa_data = aa.dict(exclude_unset=True)
|
||||||
if "timetables" in aa_data and aa_data["timetables"] is not None:
|
|
||||||
db_aa.timetables.clear()
|
|
||||||
timetables = [Timetable.model_validate(t) for t in aa_data["timetables"]]
|
|
||||||
db_aa.timetables = timetables
|
|
||||||
aa_data.pop("timetables")
|
|
||||||
if "oneshot" in aa_data and aa_data["oneshot"] is not None:
|
|
||||||
oneshot = OneShotAccess.model_validate(aa_data["oneshot"])
|
|
||||||
db_aa.oneshot = oneshot
|
|
||||||
aa_data.pop("oneshot")
|
|
||||||
db_aa.sqlmodel_update(aa_data)
|
db_aa.sqlmodel_update(aa_data)
|
||||||
return add_and_refresh(db, db_aa)
|
return add_and_refresh(db, db_aa)
|
||||||
|
|
||||||
|
|
||||||
@aa_router.delete("/{aa_id}")
|
@aa_router.delete("/{aa_id}")
|
||||||
def delete_accessauth(
|
def delete_accessauth(*, db: Session = Depends(get_session), aa_id: int):
|
||||||
*,
|
|
||||||
db: Session = Depends(get_session),
|
|
||||||
aa_id: int,
|
|
||||||
admin: bool = Depends(auth_is_admin),
|
|
||||||
):
|
|
||||||
db_aa = db.get(AccessAuthorizationDB, aa_id)
|
db_aa = db.get(AccessAuthorizationDB, aa_id)
|
||||||
if db_aa is None:
|
if db_aa is None:
|
||||||
raise HTTPException(status_code=404, detail="AccessAuthorization not found")
|
raise HTTPException(status_code=404, detail="AccessAuthorization not found")
|
||||||
db.delete(db_aa)
|
db.delete(db_aa)
|
||||||
db.commit()
|
db.commit()
|
||||||
return {"message": "AccessAuthorization deleted successfully"}
|
return {"message": "AccessAuthorization deleted successfully"}
|
||||||
@@ -1,112 +1,39 @@
|
|||||||
import logging
|
from fastapi import APIRouter, Depends, HTTPException
|
||||||
|
|
||||||
from fastapi import APIRouter, Depends, HTTPException, status
|
|
||||||
from sqlalchemy.exc import NoResultFound
|
|
||||||
from sqlmodel import Session, select
|
from sqlmodel import Session, select
|
||||||
|
from typing import List
|
||||||
|
|
||||||
from app.model.models import Card, CardCreate, CardUpdate, GroupDB
|
from ..model.models import Card
|
||||||
from app.services.auth import auth_is_admin
|
from ..services.database import engine, get_session, add_and_refresh
|
||||||
from app.services.database import add_and_refresh, get_session
|
import uuid as gen_uuid
|
||||||
from app.services.scanner import DeleteCard, WriteNewCard
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
card_router = APIRouter(prefix="/cards", tags=["Card"])
|
||||||
|
|
||||||
card_router = APIRouter(prefix="/api/v1/cards", tags=["Card"])
|
def register_card(group_id: int):
|
||||||
|
uuid = str(gen_uuid.uuid4()) #hier code für mifare registrierung
|
||||||
|
card = Card(group_id=group_id, uuid=uuid)
|
||||||
def register_card(cardInput: CardCreate):
|
|
||||||
key, uid = WriteNewCard()
|
|
||||||
if key is None:
|
|
||||||
logger.info("No card registered. Check logs!")
|
|
||||||
raise HTTPException(
|
|
||||||
status.HTTP_417_EXPECTATION_FAILED, detail="No card registered. Check logs!"
|
|
||||||
)
|
|
||||||
card = Card(
|
|
||||||
group_id=cardInput.group_id,
|
|
||||||
key=key,
|
|
||||||
name=cardInput.name,
|
|
||||||
card_serial=uid,
|
|
||||||
enabled=cardInput.enabled,
|
|
||||||
)
|
|
||||||
return card
|
return card
|
||||||
|
|
||||||
|
@card_router.post("/{group_id}", response_model=Card)
|
||||||
@card_router.post("/", response_model=Card)
|
def add_card(*, db: Session = Depends(get_session), group_id: int):
|
||||||
def add_card(
|
card = register_card(group_id)
|
||||||
cardInput: CardCreate,
|
|
||||||
db: Session = Depends(get_session),
|
|
||||||
admin: bool = Depends(auth_is_admin),
|
|
||||||
):
|
|
||||||
try:
|
|
||||||
assert (
|
|
||||||
db.exec(select(Card).where(Card.name == cardInput.name)).one_or_none()
|
|
||||||
is None
|
|
||||||
)
|
|
||||||
except AssertionError:
|
|
||||||
raise HTTPException(status.HTTP_409_CONFLICT, detail="Name already used!")
|
|
||||||
try:
|
|
||||||
assert (
|
|
||||||
db.exec(
|
|
||||||
select(GroupDB).where(GroupDB.id == cardInput.group_id)
|
|
||||||
).one_or_none()
|
|
||||||
is not None
|
|
||||||
)
|
|
||||||
except AssertionError:
|
|
||||||
raise HTTPException(status.HTTP_404_NOT_FOUND, detail="GroupID not found!")
|
|
||||||
card = register_card(cardInput)
|
|
||||||
return add_and_refresh(db, card)
|
return add_and_refresh(db, card)
|
||||||
|
|
||||||
|
@card_router.delete("/{card_id}")
|
||||||
@card_router.delete("/")
|
def del_card(*, db: Session = Depends(get_session), card_id: int):
|
||||||
def del_card(
|
card = db.get(Card, card_id)
|
||||||
*, db: Session = Depends(get_session), admin: bool = Depends(auth_is_admin)
|
if card is None:
|
||||||
):
|
raise HTTPException(status_code=404, detail="Card not found")
|
||||||
key = DeleteCard()
|
|
||||||
logger.info(key)
|
|
||||||
try:
|
|
||||||
card = db.exec(select(Card).where(Card.key == key)).one()
|
|
||||||
except NoResultFound:
|
|
||||||
logger.info(f"The key:'{key}' was not found in db!")
|
|
||||||
raise HTTPException(
|
|
||||||
status.HTTP_500_INTERNAL_SERVER_ERROR,
|
|
||||||
detail="Key on card not found in DB. Please tell an admin about this. KEY={key}", # noqa: E501
|
|
||||||
)
|
|
||||||
db.delete(card)
|
db.delete(card)
|
||||||
db.commit()
|
db.commit()
|
||||||
return {"message": "Card deleted successfully"}
|
return {"message": "Card deleted successfully"}
|
||||||
|
##TBH not a big fan of having creation using group_id but deletion using card_id
|
||||||
|
@card_router.get("/{group_id}", response_model=List[Card])
|
||||||
@card_router.get("/{group_id}", response_model=list[Card])
|
def get_cards(*, db: Session = Depends(get_session), group_id: int):
|
||||||
def get_cards(
|
|
||||||
*,
|
|
||||||
db: Session = Depends(get_session),
|
|
||||||
group_id: int,
|
|
||||||
admin: bool = Depends(auth_is_admin),
|
|
||||||
):
|
|
||||||
cards = db.exec(select(Card).where(Card.group_id == group_id)).all()
|
cards = db.exec(select(Card).where(Card.group_id == group_id)).all()
|
||||||
return cards
|
return cards
|
||||||
|
|
||||||
|
|
||||||
@card_router.patch("/{card_id}", response_model=Card)
|
#TODO:
|
||||||
def update_card(
|
# -Split Authorisations + Cards
|
||||||
card_id: int,
|
# -Deactivation
|
||||||
cardInput: CardUpdate,
|
# -Deleting
|
||||||
db: Session = Depends(get_session),
|
|
||||||
admin: bool = Depends(auth_is_admin),
|
|
||||||
):
|
|
||||||
db_card = db.get(Card, card_id)
|
|
||||||
if db_card is None:
|
|
||||||
raise HTTPException(status.HTTP_404_NOT_FOUND, detail="Card not found!")
|
|
||||||
card_data = cardInput.model_dump(exclude_unset=True, exclude_none=True)
|
|
||||||
if "group_id" in card_data:
|
|
||||||
try:
|
|
||||||
assert (
|
|
||||||
db.exec(
|
|
||||||
select(GroupDB).where(GroupDB.id == cardInput.group_id)
|
|
||||||
).one_or_none()
|
|
||||||
is not None
|
|
||||||
)
|
|
||||||
except AssertionError:
|
|
||||||
raise HTTPException(status.HTTP_404_NOT_FOUND, detail="GroupID not found!")
|
|
||||||
db_card.sqlmodel_update(card_data)
|
|
||||||
return add_and_refresh(db, db_card)
|
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
import logging
|
|
||||||
|
|
||||||
from fastapi import APIRouter, Depends, HTTPException
|
|
||||||
from sqlalchemy import exc
|
|
||||||
from sqlmodel import Session, select
|
|
||||||
|
|
||||||
from app.model.models import Card
|
|
||||||
from app.services.auth import auth_is_admin
|
|
||||||
from app.services.database import add_and_refresh, get_session
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
debug_router = APIRouter(
|
|
||||||
prefix="/api/v1/debug",
|
|
||||||
tags=["Debug items - maybe dont show this in UI"],
|
|
||||||
dependencies=[Depends(auth_is_admin)],
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@debug_router.put("/addcard/")
|
|
||||||
def add_card_manually(
|
|
||||||
groupid: int,
|
|
||||||
card_key: str,
|
|
||||||
name: str,
|
|
||||||
enabled: bool,
|
|
||||||
db: Session = Depends(get_session),
|
|
||||||
):
|
|
||||||
"""Add cards manually (you also have to delete them manually)"""
|
|
||||||
logger.critical(
|
|
||||||
f"Manual db change: adding a card with key: {card_key} to group: {groupid}"
|
|
||||||
)
|
|
||||||
card = Card(
|
|
||||||
group_id=groupid,
|
|
||||||
key=card_key,
|
|
||||||
name=name,
|
|
||||||
enabled=enabled,
|
|
||||||
card_serial="00:00:00:00:00:00:00",
|
|
||||||
)
|
|
||||||
add_and_refresh(db, card)
|
|
||||||
return card
|
|
||||||
|
|
||||||
|
|
||||||
@debug_router.get("/rmcard/{card_id}")
|
|
||||||
def remove_card_manually(card_id: str, db: Session = Depends(get_session)):
|
|
||||||
try:
|
|
||||||
card = db.exec(select(Card).where(Card.id == card_id)).one()
|
|
||||||
except exc.NoResultFound:
|
|
||||||
raise HTTPException(status_code=500, detail="No card with that id found.")
|
|
||||||
logger.critical(f"Manual db change: removing a card with attrs: {card}")
|
|
||||||
db.delete(card)
|
|
||||||
db.commit()
|
|
||||||
return {"message": "Card deleted successfully"}
|
|
||||||
|
|
||||||
|
|
||||||
@debug_router.put("/getcards")
|
|
||||||
def list_all_cards(db: Session = Depends(get_session)):
|
|
||||||
logger.info("Debug Setting: Getting cards.")
|
|
||||||
cards = db.exec(select(Card)).all()
|
|
||||||
print(cards)
|
|
||||||
out = []
|
|
||||||
for i in cards:
|
|
||||||
out.append({i.key: i.group.name})
|
|
||||||
return out
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
from fastapi import APIRouter, Depends
|
|
||||||
from sqlmodel import Session
|
|
||||||
|
|
||||||
import app.services.door as doorService
|
|
||||||
from app.services.auth import auth_is_admin
|
|
||||||
from app.services.database import get_session
|
|
||||||
|
|
||||||
door_router = APIRouter(prefix="/api/v1/door", tags=["Door"])
|
|
||||||
|
|
||||||
|
|
||||||
@door_router.put("/open")
|
|
||||||
def open_door(db: Session = Depends(get_session), admin: bool = Depends(auth_is_admin)):
|
|
||||||
doorService.openDoor()
|
|
||||||
|
|
||||||
|
|
||||||
@door_router.put("/close")
|
|
||||||
def close_door(
|
|
||||||
db: Session = Depends(get_session), admin: bool = Depends(auth_is_admin)
|
|
||||||
):
|
|
||||||
doorService.closeDoor()
|
|
||||||
|
|
||||||
|
|
||||||
@door_router.put("/status")
|
|
||||||
def is_door_open(
|
|
||||||
db: Session = Depends(get_session), admin: bool = Depends(auth_is_admin)
|
|
||||||
):
|
|
||||||
return doorService.isDoorOpen()
|
|
||||||
|
|
||||||
|
|
||||||
@door_router.post("/test")
|
|
||||||
def test_access(input: str, db: Session = Depends(get_session)):
|
|
||||||
return doorService.checkAccess(input, db=db)
|
|
||||||
@@ -1,47 +1,27 @@
|
|||||||
from fastapi import APIRouter, Depends, HTTPException, status
|
from fastapi import APIRouter, HTTPException, Depends
|
||||||
from sqlmodel import Session, select
|
from sqlmodel import Session, select
|
||||||
|
from typing import List
|
||||||
|
|
||||||
from ..model.models import GroupCreate, GroupDB, GroupResponse
|
from ..model.models import GroupDB, GroupResponse, GroupCreate
|
||||||
from ..services.auth import auth_is_admin
|
from ..services.database import engine, get_session, add_and_refresh
|
||||||
from ..services.database import add_and_refresh, get_session
|
|
||||||
|
|
||||||
group_router = APIRouter(prefix="/api/v1/groups", tags=["Group"])
|
group_router = APIRouter(prefix="/groups", tags=["Group"])
|
||||||
|
|
||||||
|
@group_router.get("/", response_model=List[GroupResponse])
|
||||||
@group_router.get("/", response_model=list[GroupResponse])
|
def get_groups(*, db: Session = Depends(get_session)):
|
||||||
def get_groups(
|
|
||||||
*, db: Session = Depends(get_session), admin: bool = Depends(auth_is_admin)
|
|
||||||
):
|
|
||||||
groups = db.exec(select(GroupDB)).all()
|
groups = db.exec(select(GroupDB)).all()
|
||||||
return groups
|
return groups
|
||||||
|
|
||||||
|
|
||||||
@group_router.post("/", response_model=GroupResponse)
|
@group_router.post("/", response_model=GroupResponse)
|
||||||
def create_group(
|
def create_group(*, db: Session = Depends(get_session), group: GroupCreate):
|
||||||
*,
|
|
||||||
db: Session = Depends(get_session),
|
|
||||||
group: GroupCreate,
|
|
||||||
admin: bool = Depends(auth_is_admin),
|
|
||||||
):
|
|
||||||
db_group = GroupDB.model_validate(group)
|
db_group = GroupDB.model_validate(group)
|
||||||
group = db.exec(select(GroupDB).where(GroupDB.name == db_group.name)).first()
|
|
||||||
if group is not None:
|
|
||||||
raise HTTPException(
|
|
||||||
status_code=status.HTTP_409_CONFLICT, detail="Group already exists!"
|
|
||||||
)
|
|
||||||
return add_and_refresh(db, db_group)
|
return add_and_refresh(db, db_group)
|
||||||
|
|
||||||
|
|
||||||
@group_router.delete("/{group_id}")
|
@group_router.delete("/{group_id}")
|
||||||
def delete_group(
|
def delete_group(*, db: Session = Depends(get_session), group_id: int):
|
||||||
*,
|
|
||||||
db: Session = Depends(get_session),
|
|
||||||
group_id: int,
|
|
||||||
admin: bool = Depends(auth_is_admin),
|
|
||||||
):
|
|
||||||
db_group = db.get(GroupDB, group_id)
|
db_group = db.get(GroupDB, group_id)
|
||||||
if db_group is None:
|
if db_group is None:
|
||||||
raise HTTPException(status_code=404, detail="Group not found")
|
raise HTTPException(status_code=404, detail="Group not found")
|
||||||
db.delete(db_group)
|
db.delete(db_group)
|
||||||
db.commit()
|
db.commit()
|
||||||
return {"message": "Group deleted successfully"}
|
return {"message": "Group deleted successfully"}
|
||||||
@@ -1,73 +1,34 @@
|
|||||||
import logging
|
from fastapi import APIRouter, HTTPException, Depends
|
||||||
|
|
||||||
from fastapi import APIRouter, Depends, HTTPException, status
|
|
||||||
from sqlmodel import Session, select
|
from sqlmodel import Session, select
|
||||||
|
from typing import List
|
||||||
|
|
||||||
from app.model.models import UserCreate, UserDB, UserResponse, UserUpdate
|
from ..model.models import UserResponse, UserCreate, UserDB, UserUpdate
|
||||||
from app.services.auth import auth_is_admin, get_password_hash
|
from ..services.database import engine, get_session, add_and_refresh
|
||||||
from app.services.auth import get_current_user as auth_user
|
from ..services.auth import get_password_hash, get_current_user
|
||||||
from app.services.database import add_and_refresh, get_session
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
user_router = APIRouter(tags=["Users"])
|
||||||
|
|
||||||
user_router = APIRouter(tags=["Users"], prefix="/api/v1/users")
|
@user_router.post("/users/", response_model=UserResponse)
|
||||||
|
def create_user(*, db: Session = Depends(get_session), user: UserCreate):
|
||||||
|
print("creating user with data ", user)
|
||||||
@user_router.post("/", response_model=UserResponse)
|
|
||||||
def create_user(
|
|
||||||
*,
|
|
||||||
db: Session = Depends(get_session),
|
|
||||||
user: UserCreate,
|
|
||||||
admin: bool = Depends(auth_is_admin),
|
|
||||||
):
|
|
||||||
hashed_password = {"passwordhash": get_password_hash(user.password)}
|
hashed_password = {"passwordhash": get_password_hash(user.password)}
|
||||||
try:
|
|
||||||
assert (
|
|
||||||
db.exec(select(UserDB).where(UserDB.name == user.name)).one_or_none()
|
|
||||||
is None
|
|
||||||
)
|
|
||||||
except AssertionError:
|
|
||||||
raise HTTPException(status.HTTP_409_CONFLICT, detail="Name already used!")
|
|
||||||
db_user = UserDB.model_validate(user, update=hashed_password)
|
db_user = UserDB.model_validate(user, update=hashed_password)
|
||||||
return add_and_refresh(db, db_user)
|
return add_and_refresh(db, db_user)
|
||||||
|
|
||||||
|
@user_router.get("/users/", response_model=List[UserResponse])
|
||||||
@user_router.get("/", response_model=list[UserResponse])
|
def read_users(*, db: Session = Depends(get_session)):
|
||||||
def read_users(
|
|
||||||
*, db: Session = Depends(get_session), admin: bool = Depends(auth_is_admin)
|
|
||||||
):
|
|
||||||
users = db.exec(select(UserDB)).all()
|
users = db.exec(select(UserDB)).all()
|
||||||
return users
|
return users
|
||||||
|
|
||||||
|
@user_router.get("/users/{user_id}", response_model=UserResponse)
|
||||||
@user_router.get("/current", response_model=UserResponse)
|
def read_user(*, db: Session = Depends(get_session), user_id: int):
|
||||||
def get_current_user(
|
|
||||||
db: Session = Depends(get_session), user: UserDB = Depends(auth_user)
|
|
||||||
):
|
|
||||||
return user
|
|
||||||
|
|
||||||
|
|
||||||
@user_router.get("/{user_id}", response_model=UserResponse)
|
|
||||||
def read_user(
|
|
||||||
*,
|
|
||||||
db: Session = Depends(get_session),
|
|
||||||
user_id: int,
|
|
||||||
admin: bool = Depends(auth_is_admin),
|
|
||||||
):
|
|
||||||
db_user = db.get(UserDB, user_id)
|
db_user = db.get(UserDB, user_id)
|
||||||
if db_user is None:
|
if db_user is None:
|
||||||
raise HTTPException(status_code=404, detail="User not found")
|
raise HTTPException(status_code=404, detail="User not found")
|
||||||
return db_user
|
return db_user
|
||||||
|
|
||||||
|
@user_router.patch("/users/{user_id}", response_model=UserResponse)
|
||||||
@user_router.patch("/{user_id}", response_model=UserResponse)
|
def update_user(*, db: Session = Depends(get_session), user_id: int, user: UserUpdate):
|
||||||
def update_user(
|
|
||||||
*,
|
|
||||||
db: Session = Depends(get_session),
|
|
||||||
user_id: int,
|
|
||||||
user: UserUpdate,
|
|
||||||
admin: bool = Depends(auth_is_admin),
|
|
||||||
):
|
|
||||||
db_user = db.get(UserDB, user_id)
|
db_user = db.get(UserDB, user_id)
|
||||||
if db_user is None:
|
if db_user is None:
|
||||||
raise HTTPException(status_code=404, detail="User not found")
|
raise HTTPException(status_code=404, detail="User not found")
|
||||||
@@ -79,17 +40,11 @@ def update_user(
|
|||||||
db_user.sqlmodel_update(user_data, update=hashed_password)
|
db_user.sqlmodel_update(user_data, update=hashed_password)
|
||||||
return add_and_refresh(db, db_user)
|
return add_and_refresh(db, db_user)
|
||||||
|
|
||||||
|
@user_router.delete("/users/{user_id}")
|
||||||
@user_router.delete("/{user_id}")
|
def delete_user(*, db: Session = Depends(get_session), user_id: int):
|
||||||
def delete_user(
|
|
||||||
*,
|
|
||||||
db: Session = Depends(get_session),
|
|
||||||
user_id: int,
|
|
||||||
admin: bool = Depends(auth_is_admin),
|
|
||||||
):
|
|
||||||
db_user = db.get(UserDB, user_id)
|
db_user = db.get(UserDB, user_id)
|
||||||
if db_user is None:
|
if db_user is None:
|
||||||
raise HTTPException(status_code=404, detail="User not found")
|
raise HTTPException(status_code=404, detail="User not found")
|
||||||
db.delete(db_user)
|
db.delete(db_user)
|
||||||
db.commit()
|
db.commit()
|
||||||
return {"message": "User deleted successfully"}
|
return {"message": "User deleted successfully"}
|
||||||
+9
-62
@@ -1,74 +1,21 @@
|
|||||||
import logging
|
|
||||||
from contextlib import asynccontextmanager
|
|
||||||
|
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
from fastapi.middleware.cors import CORSMiddleware
|
|
||||||
from fastapi.security import OAuth2PasswordBearer
|
from fastapi.security import OAuth2PasswordBearer
|
||||||
|
from .controllers import userManager, cardManager, groupManager, aaManager
|
||||||
from app.controllers import (
|
from .services.database import create_db_and_tables
|
||||||
aaManager,
|
from .services.auth import token_router, create_first_user
|
||||||
cardManager,
|
|
||||||
debugManager,
|
|
||||||
doorManager,
|
|
||||||
groupManager,
|
|
||||||
userManager,
|
|
||||||
)
|
|
||||||
from app.services.auth import create_first_user, token_router
|
|
||||||
from app.services.database import create_db_and_tables, get_db_session
|
|
||||||
from app.services.door import DoorController, init_controller
|
|
||||||
from app.services.scanner import BackgroundScanner
|
|
||||||
from app.services.settings import settings
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token")
|
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token")
|
||||||
scanner = BackgroundScanner(db=get_db_session())
|
|
||||||
logging.basicConfig(level=logging.INFO)
|
|
||||||
|
|
||||||
|
app = FastAPI()
|
||||||
@asynccontextmanager
|
@app.on_event("startup")
|
||||||
async def lifespan(app: FastAPI):
|
def on_startup():
|
||||||
create_db_and_tables()
|
create_db_and_tables()
|
||||||
create_first_user(db=get_db_session())
|
create_first_user()
|
||||||
init_controller(
|
print("Database created and tables initialized.")
|
||||||
DoorController(
|
|
||||||
mqtt_host=settings.mqtt_host,
|
|
||||||
mqtt_port=settings.mqtt_port,
|
|
||||||
mock_factory=settings.mock,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
if not settings.disable_cards:
|
|
||||||
scanner.start()
|
|
||||||
|
|
||||||
logger.info("-" * 63)
|
|
||||||
logger.info("---- Documentation is at http://127.0.0.1:8000/api/v1/docs ----")
|
|
||||||
logger.info("-" * 63)
|
|
||||||
yield
|
|
||||||
# scanner.stop()
|
|
||||||
|
|
||||||
|
|
||||||
app = FastAPI(
|
|
||||||
lifespan=lifespan, docs_url="/api/v1/docs", openapi_url="/api/v1/openapi.json"
|
|
||||||
)
|
|
||||||
|
|
||||||
origins = [
|
|
||||||
"http://127.0.0.1",
|
|
||||||
"http://localhost",
|
|
||||||
"http://localhost:8080",
|
|
||||||
]
|
|
||||||
|
|
||||||
app.add_middleware(
|
|
||||||
CORSMiddleware,
|
|
||||||
allow_origins=origins,
|
|
||||||
allow_credentials=True,
|
|
||||||
allow_methods=["GET", "PUT", "POST", "DELETE", "PATCH"],
|
|
||||||
allow_headers=["*"],
|
|
||||||
)
|
|
||||||
|
|
||||||
app.include_router(token_router)
|
app.include_router(token_router)
|
||||||
app.include_router(userManager.user_router)
|
app.include_router(userManager.user_router)
|
||||||
app.include_router(groupManager.group_router)
|
app.include_router(groupManager.group_router)
|
||||||
app.include_router(cardManager.card_router)
|
app.include_router(cardManager.card_router)
|
||||||
app.include_router(aaManager.aa_router)
|
app.include_router(aaManager.aa_router)
|
||||||
app.include_router(doorManager.door_router)
|
|
||||||
app.include_router(debugManager.debug_router)
|
|
||||||
+19
-106
@@ -1,188 +1,101 @@
|
|||||||
from datetime import datetime, time
|
from sqlmodel import Field, Relationship, Session, SQLModel
|
||||||
from typing import Literal
|
from typing import List
|
||||||
|
|
||||||
from pydantic import model_validator
|
|
||||||
from sqlmodel import Field, Relationship, SQLModel
|
|
||||||
|
|
||||||
|
|
||||||
class Base(SQLModel):
|
class Base(SQLModel):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
#### User
|
#### User
|
||||||
class UserBase(Base):
|
class UserBase(Base):
|
||||||
name: str = Field(index=True, unique=True)
|
name: str = Field(index=True)
|
||||||
email: str | None = None
|
email: str | None = None
|
||||||
is_admin: bool = False
|
is_admin: bool = False
|
||||||
|
|
||||||
|
|
||||||
class UserResponse(UserBase):
|
class UserResponse(UserBase):
|
||||||
id: int
|
id: int
|
||||||
|
|
||||||
|
|
||||||
class UserCreate(UserBase):
|
class UserCreate(UserBase):
|
||||||
password: str
|
password: str
|
||||||
|
|
||||||
|
|
||||||
class UserDB(UserBase, table=True):
|
class UserDB(UserBase, table=True):
|
||||||
id: int | None = Field(default=None, primary_key=True)
|
id: int | None = Field(default=None, primary_key=True)
|
||||||
passwordhash: str
|
passwordhash: str
|
||||||
|
|
||||||
|
|
||||||
class UserUpdate(Base):
|
class UserUpdate(Base):
|
||||||
name: str | None = None
|
name: str | None = None
|
||||||
email: str | None = None
|
email: str | None = None
|
||||||
is_admin: bool | None = None
|
is_admin: bool | None = None
|
||||||
password: str | None = None
|
password: str | None = None
|
||||||
|
|
||||||
|
|
||||||
#### Special
|
#### Special
|
||||||
class AaGroupLink(Base, table=True):
|
class AaGroupLink(Base, table=True):
|
||||||
group_id: int | None = Field(
|
group_id: int | None = Field(default=None, foreign_key="groupdb.id", primary_key=True)
|
||||||
default=None, foreign_key="groupdb.id", primary_key=True
|
accessauth_id: int | None = Field(default=None, foreign_key="accessauthorizationdb.id", primary_key=True)
|
||||||
)
|
|
||||||
accessauth_id: int | None = Field(
|
|
||||||
default=None, foreign_key="accessauthorizationdb.id", primary_key=True
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
#### Token
|
#### Token
|
||||||
class Token(Base):
|
class Token(Base):
|
||||||
access_token: str
|
access_token: str
|
||||||
token_type: str
|
token_type: str
|
||||||
|
|
||||||
|
|
||||||
class TokenData(Base):
|
class TokenData(Base):
|
||||||
username: str | None = None
|
username: str | None = None
|
||||||
|
|
||||||
|
|
||||||
#### Group
|
#### Group
|
||||||
class GroupBase(Base):
|
class GroupBase(Base):
|
||||||
name: str = Field(index=True, unique=True)
|
name: str = Field(index=True, unique=True)
|
||||||
|
|
||||||
|
|
||||||
class GroupCreate(GroupBase):
|
class GroupCreate(GroupBase):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class GroupDB(GroupBase, table=True):
|
class GroupDB(GroupBase, table=True):
|
||||||
id: int | None = Field(default=None, primary_key=True)
|
id: int | None = Field(default=None, primary_key=True)
|
||||||
cards: list["Card"] = Relationship(back_populates="group")
|
cards: List["Card"] = Relationship(back_populates="group")
|
||||||
accessauths: list["AccessAuthorizationDB"] = Relationship(
|
accessauths: List["AccessAuthorizationDB"] = Relationship(back_populates="groups", link_model=AaGroupLink)
|
||||||
back_populates="groups", link_model=AaGroupLink
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class GroupResponse(GroupBase):
|
class GroupResponse(GroupBase):
|
||||||
id: int
|
id: int
|
||||||
cards: list["Card"] | None
|
cards: List["Card"] | None
|
||||||
accessauths: list["AccessAuthorizationDB"] | None
|
accessauths: List["AccessAuthorizationDB"] | None
|
||||||
|
|
||||||
|
|
||||||
#### AccessAuthorization
|
#### AccessAuthorization
|
||||||
class AccessAuthorizationBase(Base):
|
class AccessAuthorizationBase(Base):
|
||||||
name: str = Field(index=True)
|
name: str = Field(index=True)
|
||||||
type: Literal["timetable", "oneshot", "somefuturespec"]
|
|
||||||
is_active: bool
|
is_active: bool
|
||||||
|
|
||||||
|
|
||||||
class AccessAuthorizationDB(AccessAuthorizationBase, table=True):
|
class AccessAuthorizationDB(AccessAuthorizationBase, table=True):
|
||||||
id: int | None = Field(default=None, primary_key=True)
|
id: int | None = Field(default=None, primary_key=True)
|
||||||
type: str
|
groups: List["GroupDB"] = Relationship(back_populates="accessauths", link_model=AaGroupLink)
|
||||||
groups: list["GroupDB"] = Relationship(
|
timetables: List["Timetable"] = Relationship(back_populates="accessauth", cascade_delete=True)
|
||||||
back_populates="accessauths", link_model=AaGroupLink
|
|
||||||
)
|
|
||||||
timetables: list["Timetable"] = Relationship(
|
|
||||||
back_populates="accessauth", cascade_delete=True
|
|
||||||
)
|
|
||||||
oneshot: "OneShotAccess" = Relationship(
|
|
||||||
back_populates="accessauth", cascade_delete=True
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class OneShotAccessBase(Base):
|
|
||||||
uses: int = 1
|
|
||||||
ends_at: datetime
|
|
||||||
|
|
||||||
|
|
||||||
class OneShotAccess(OneShotAccessBase, table=True):
|
|
||||||
id: int | None = Field(default=None, primary_key=True)
|
|
||||||
accessauth_id: int = Field(default=None, foreign_key="accessauthorizationdb.id")
|
|
||||||
accessauth: AccessAuthorizationDB = Relationship(back_populates="oneshot")
|
|
||||||
|
|
||||||
|
|
||||||
class AccessAuthorizationCreate(AccessAuthorizationBase):
|
class AccessAuthorizationCreate(AccessAuthorizationBase):
|
||||||
timetables: list["TimetableCreate"] = []
|
timetables: List["TimetableCreate"]
|
||||||
oneshot: OneShotAccessBase | None = None
|
|
||||||
|
|
||||||
@model_validator(mode="after")
|
|
||||||
def check_type(self):
|
|
||||||
if self.type == "timetable":
|
|
||||||
if not self.timetables:
|
|
||||||
raise ValueError(
|
|
||||||
"timetable auths require at least one timetable object"
|
|
||||||
)
|
|
||||||
if self.oneshot is not None:
|
|
||||||
raise ValueError("timetable auths are not allowed oneshot objects")
|
|
||||||
elif self.type == "oneshot":
|
|
||||||
if not self.oneshot:
|
|
||||||
raise ValueError("oneshot auths require a oneshot object")
|
|
||||||
if self.timetables:
|
|
||||||
raise ValueError("oneshot auths are not allowed timetable objects")
|
|
||||||
elif self.type == "somefuturespec":
|
|
||||||
raise ValueError("somefuturespec is not jet implemented. Please do not use")
|
|
||||||
return self
|
|
||||||
|
|
||||||
|
|
||||||
class AccessAuthorizationResponse(AccessAuthorizationBase):
|
class AccessAuthorizationResponse(AccessAuthorizationBase):
|
||||||
id: int
|
id: int
|
||||||
timetables: list["Timetable"] = []
|
timetables: List["Timetable"]
|
||||||
oneshot: OneShotAccessBase | None = None
|
groups: List["GroupDB"]
|
||||||
groups: list["GroupDB"]
|
|
||||||
|
|
||||||
|
|
||||||
class AccessAuthorizationUpdate(Base):
|
class AccessAuthorizationUpdate(Base):
|
||||||
name: str | None = None
|
name: str | None = None
|
||||||
type: Literal["timetable", "oneshot", "somefuturespec"] | None = None
|
|
||||||
is_active: bool | None = None
|
is_active: bool | None = None
|
||||||
timetables: list["TimetableCreate"] | None = None
|
timetables: List["TimetableCreate"] | None = None
|
||||||
oneshot: OneShotAccessBase | None = None
|
|
||||||
|
|
||||||
|
|
||||||
#### Card
|
#### Card
|
||||||
class Card(Base, table=True):
|
class Card(Base, table=True):
|
||||||
id: int | None = Field(default=None, primary_key=True)
|
id: int | None = Field(default=None, primary_key=True)
|
||||||
key: str
|
uuid: str
|
||||||
card_serial: str
|
|
||||||
enabled: bool = True
|
|
||||||
name: str = Field(unique=True, max_length=32)
|
|
||||||
group_id: int | None = Field(default=None, foreign_key="groupdb.id")
|
group_id: int | None = Field(default=None, foreign_key="groupdb.id")
|
||||||
group: GroupDB | None = Relationship(back_populates="cards")
|
group: GroupDB | None = Relationship(back_populates="cards")
|
||||||
|
|
||||||
|
|
||||||
class CardCreate(Base):
|
|
||||||
name: str = Field(unique=True, max_length=32)
|
|
||||||
enabled: bool = True
|
|
||||||
group_id: int
|
|
||||||
|
|
||||||
|
|
||||||
class CardUpdate(Base):
|
|
||||||
name: str | None = None
|
|
||||||
enabled: bool | None = None
|
|
||||||
group_id: int | None = None
|
|
||||||
|
|
||||||
|
|
||||||
class TimetableBase(Base):
|
class TimetableBase(Base):
|
||||||
weekday: int = Field(le=6, ge=0)
|
weekday: int = Field(le=7, ge=1)
|
||||||
starttime: time
|
starttime: str
|
||||||
duration: int = Field(gt=0, lt=1440)
|
duration: int = Field(gt=0, lt=1440)
|
||||||
|
|
||||||
|
|
||||||
class Timetable(TimetableBase, table=True):
|
class Timetable(TimetableBase, table=True):
|
||||||
id: int | None = Field(default=None, primary_key=True)
|
id: int | None = Field(default=None, primary_key=True)
|
||||||
accessauth_id: int = Field(default=None, foreign_key="accessauthorizationdb.id")
|
accessauth_id: int = Field(default=None, foreign_key="accessauthorizationdb.id")
|
||||||
accessauth: AccessAuthorizationDB = Relationship(back_populates="timetables")
|
accessauth: AccessAuthorizationDB = Relationship(back_populates="timetables")
|
||||||
|
|
||||||
|
|
||||||
class TimetableCreate(TimetableBase):
|
class TimetableCreate(TimetableBase):
|
||||||
pass
|
pass
|
||||||
|
|||||||
+54
-78
@@ -1,46 +1,37 @@
|
|||||||
import logging
|
|
||||||
import secrets
|
|
||||||
import string
|
|
||||||
from datetime import UTC, datetime, timedelta
|
|
||||||
from typing import Annotated
|
from typing import Annotated
|
||||||
|
from datetime import datetime, timedelta, timezone
|
||||||
import jwt
|
from fastapi import APIRouter, HTTPException, Depends, status
|
||||||
from fastapi import APIRouter, Depends, HTTPException, status
|
|
||||||
from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm
|
from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm
|
||||||
from jwt.exceptions import InvalidTokenError
|
|
||||||
from pwdlib import PasswordHash
|
|
||||||
from sqlmodel import Session, select
|
from sqlmodel import Session, select
|
||||||
|
from pwdlib import PasswordHash
|
||||||
|
import jwt
|
||||||
|
from jwt.exceptions import InvalidTokenError
|
||||||
|
from ..model.models import UserDB, Token, TokenData, UserCreate
|
||||||
|
from ..services.database import *
|
||||||
|
import secrets, string
|
||||||
|
|
||||||
from app.model.models import Token, TokenData, UserDB
|
SECRET_KEY = "8b14d0b447bff7efa24d5019cc59a999786e31f6f865173bbd642bf18de5ad85" #Encrypt and change later or store in env file or somehthing
|
||||||
from app.services.database import add_and_refresh, get_session
|
|
||||||
from app.services.settings import settings
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
SECRET_KEY = settings.secret_key
|
|
||||||
ALGORITHM = "HS256"
|
ALGORITHM = "HS256"
|
||||||
ACCESS_TOKEN_EXPIRE_MINUTES = 120
|
ACCESS_TOKEN_EXPIRE_MINUTES = 30
|
||||||
|
|
||||||
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="/api/v1/token")
|
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token")
|
||||||
|
|
||||||
token_router = APIRouter(tags=["Token"], prefix="/api/v1")
|
token_router = APIRouter(tags=["Token"])
|
||||||
|
|
||||||
password_hash = PasswordHash.recommended()
|
password_hash = PasswordHash.recommended()
|
||||||
|
|
||||||
|
|
||||||
def verify_password(plain_password, hashed_password):
|
def verify_password(plain_password, hashed_password):
|
||||||
return password_hash.verify(plain_password, hashed_password)
|
return password_hash.verify(plain_password, hashed_password)
|
||||||
|
|
||||||
|
|
||||||
def get_password_hash(password):
|
def get_password_hash(password):
|
||||||
return password_hash.hash(password)
|
return password_hash.hash(password)
|
||||||
|
|
||||||
|
|
||||||
def get_user(db, username: str):
|
def get_user(db, username: str):
|
||||||
user = db.exec(select(UserDB).where(UserDB.name == username)).first()
|
user = db.exec(select(UserDB).where(UserDB.name == username)).first()
|
||||||
|
if user is None:
|
||||||
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Username not found in get_user, this shouldn't happen")
|
||||||
return user
|
return user
|
||||||
|
|
||||||
|
|
||||||
def authenticate_user(db, username: str, password: str):
|
def authenticate_user(db, username: str, password: str):
|
||||||
user = get_user(db, username)
|
user = get_user(db, username)
|
||||||
if not user:
|
if not user:
|
||||||
@@ -49,79 +40,63 @@ def authenticate_user(db, username: str, password: str):
|
|||||||
return False
|
return False
|
||||||
return user
|
return user
|
||||||
|
|
||||||
|
|
||||||
def create_access_token(data: dict, expires_delta: timedelta | None = None):
|
def create_access_token(data: dict, expires_delta: timedelta | None = None):
|
||||||
to_encode = data.copy()
|
to_encode = data.copy()
|
||||||
if expires_delta:
|
if expires_delta:
|
||||||
expire = datetime.now(UTC) + expires_delta
|
expire = datetime.now(timezone.utc) + expires_delta
|
||||||
else:
|
else:
|
||||||
expire = datetime.now(UTC) + timedelta(minutes=15)
|
expire = datetime.now(timezone.utc) + expires_delta(minutes=15)
|
||||||
to_encode.update({"exp": expire})
|
to_encode.update({"exp": expire})
|
||||||
encoded_jwt = jwt.encode(to_encode, SECRET_KEY, algorithm=ALGORITHM)
|
encoded_jwt = jwt.encode(to_encode, SECRET_KEY, algorithm=ALGORITHM)
|
||||||
return encoded_jwt
|
return encoded_jwt
|
||||||
|
|
||||||
|
def get_current_user(token: Annotated[str, Depends(oauth2_scheme)]):
|
||||||
def get_current_user(
|
with Session(engine) as db:
|
||||||
token: Annotated[str, Depends(oauth2_scheme)],
|
credentials_exception = HTTPException(
|
||||||
db: Session = Depends(get_session),
|
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||||
):
|
detail="Could not validate credentials",
|
||||||
credentials_exception = HTTPException(
|
headers={"WWW-Authenticate": "Bearer"}
|
||||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
)
|
||||||
detail="Could not validate credentials",
|
try:
|
||||||
headers={"WWW-Authenticate": "Bearer"},
|
payload = jwt.decode(token, SECRET_KEY, algorithms=[ALGORITHM])
|
||||||
)
|
username = payload.get("sub")
|
||||||
try:
|
if username is None:
|
||||||
payload = jwt.decode(token, SECRET_KEY, algorithms=[ALGORITHM])
|
raise credentials_exception
|
||||||
username = payload.get("sub")
|
token_data = TokenData(username=username)
|
||||||
if username is None:
|
except InvalidTokenError:
|
||||||
raise credentials_exception
|
raise credentials_exception
|
||||||
token_data = TokenData(username=username)
|
user = get_user(db, username=token_data.username)
|
||||||
except InvalidTokenError:
|
if user is None:
|
||||||
raise credentials_exception
|
raise credentials_exception
|
||||||
user = get_user(db, username=token_data.username)
|
return user
|
||||||
if user is None:
|
|
||||||
raise credentials_exception
|
|
||||||
return user
|
|
||||||
|
|
||||||
|
def create_first_user():
|
||||||
def auth_is_admin(
|
print("Checking for admin user")
|
||||||
token: str = Depends(oauth2_scheme),
|
with Session(engine) as db:
|
||||||
db: Session = Depends(get_session),
|
admin_user = db.exec(select(UserDB)).first()
|
||||||
):
|
if admin_user is None:
|
||||||
user = get_current_user(token=token, db=db)
|
password = ''.join(secrets.choice(string.digits) for i in range(8))
|
||||||
if not user.is_admin:
|
print("Creating first admin user with password", password)
|
||||||
raise HTTPException(
|
user = UserDB(
|
||||||
status_code=status.HTTP_403_FORBIDDEN,
|
name="admin",
|
||||||
detail="Not authorized to perform this action",
|
passwordhash=get_password_hash(password),
|
||||||
headers={"WWW-Authenticate": "Bearer"},
|
is_admin=True
|
||||||
)
|
)
|
||||||
return True
|
return add_and_refresh(db, user)
|
||||||
|
print(f"Admin user already exists: {admin_user.name}")
|
||||||
|
|
||||||
def create_first_user(db: Session):
|
|
||||||
logger.info("Checking for admin user")
|
|
||||||
admin_user = db.exec(select(UserDB)).first()
|
|
||||||
if admin_user is None:
|
|
||||||
password = "".join(secrets.choice(string.digits) for i in range(8))
|
|
||||||
logger.info(f"Creating first admin user with password: {password}")
|
|
||||||
user = UserDB(
|
|
||||||
name="admin", passwordhash=get_password_hash(password), is_admin=True
|
|
||||||
)
|
|
||||||
return add_and_refresh(db, user)
|
|
||||||
logger.info(f"Admin user already exists: {admin_user.name}")
|
|
||||||
|
|
||||||
|
|
||||||
@token_router.post("/token")
|
@token_router.post("/token")
|
||||||
def login_for_access_token(
|
def login_for_access_token(
|
||||||
form_data: Annotated[OAuth2PasswordRequestForm, Depends()],
|
form_data: Annotated[OAuth2PasswordRequestForm, Depends()],
|
||||||
db: Session = Depends(get_session),
|
db: Session = Depends(get_session)
|
||||||
) -> Token:
|
) -> Token:
|
||||||
user = authenticate_user(db, form_data.username, form_data.password)
|
user = authenticate_user(db, form_data.username, form_data.password)
|
||||||
if not user:
|
if not user:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||||
detail="Incorrect username or pw",
|
detail="Incorrect username or pw",
|
||||||
headers={"WWW-Authenticate": "Bearer"},
|
headers={"WWW-Authenticate": "Bearer"}
|
||||||
)
|
)
|
||||||
access_token_expires = timedelta(minutes=ACCESS_TOKEN_EXPIRE_MINUTES)
|
access_token_expires = timedelta(minutes=ACCESS_TOKEN_EXPIRE_MINUTES)
|
||||||
access_token = create_access_token(
|
access_token = create_access_token(
|
||||||
@@ -129,7 +104,8 @@ def login_for_access_token(
|
|||||||
)
|
)
|
||||||
return Token(access_token=access_token, token_type="bearer")
|
return Token(access_token=access_token, token_type="bearer")
|
||||||
|
|
||||||
|
|
||||||
@token_router.get("/test/login")
|
@token_router.get("/test/login")
|
||||||
def test_login(current_user: Annotated[UserDB, Depends(get_current_user)]) -> UserDB:
|
def test_login(
|
||||||
return current_user
|
current_user: Annotated[UserDB, Depends(get_current_user)]
|
||||||
|
) -> UserDB:
|
||||||
|
return current_user
|
||||||
@@ -1,52 +1,20 @@
|
|||||||
import logging
|
from sqlmodel import create_engine, SQLModel, Session
|
||||||
from functools import lru_cache
|
|
||||||
|
|
||||||
from sqlalchemy import inspect
|
from ..model.models import Base
|
||||||
from sqlmodel import Session, SQLModel, create_engine
|
|
||||||
|
|
||||||
from app.services.settings import settings
|
SQLALCHEMY_DATABASE_URL = "sqlite:///./gatekeeper.db"
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
@lru_cache
|
|
||||||
def get_engine():
|
|
||||||
return create_engine(
|
|
||||||
settings.sqlalchemy_database_url, connect_args={"check_same_thread": False}
|
|
||||||
)
|
|
||||||
|
|
||||||
|
engine = create_engine(SQLALCHEMY_DATABASE_URL)
|
||||||
|
|
||||||
def create_db_and_tables():
|
def create_db_and_tables():
|
||||||
inspector = inspect(get_engine())
|
SQLModel.metadata.create_all(engine)
|
||||||
existing_tables = inspector.get_table_names()
|
|
||||||
if not existing_tables:
|
|
||||||
SQLModel.metadata.create_all(get_engine())
|
|
||||||
from alembic.config import Config
|
|
||||||
|
|
||||||
from alembic import command
|
|
||||||
|
|
||||||
alembic_cfg = Config(settings.alembic_config)
|
|
||||||
alembic_cfg.set_main_option("sqlalchemy.url", str(get_engine().url))
|
|
||||||
alembic_cfg.attributes["sqlalchemy.url"] = settings.sqlalchemy_database_url
|
|
||||||
command.stamp(alembic_cfg, "head")
|
|
||||||
logger.info("Database created and tables initialized.")
|
|
||||||
else:
|
|
||||||
logger.info(
|
|
||||||
"Database already initialized (%d tables found).", len(existing_tables)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def get_session():
|
def get_session():
|
||||||
with Session(get_engine()) as db:
|
with Session(engine) as db:
|
||||||
yield db
|
yield db
|
||||||
|
|
||||||
|
|
||||||
def get_db_session():
|
|
||||||
return Session(get_engine())
|
|
||||||
|
|
||||||
|
|
||||||
def add_and_refresh(db: Session, obj):
|
def add_and_refresh(db: Session, obj):
|
||||||
db.add(obj)
|
db.add(obj)
|
||||||
db.commit()
|
db.commit()
|
||||||
db.refresh(obj)
|
db.refresh(obj)
|
||||||
return obj
|
return obj
|
||||||
@@ -1,136 +0,0 @@
|
|||||||
import logging
|
|
||||||
from datetime import date, datetime, timedelta
|
|
||||||
from time import sleep
|
|
||||||
|
|
||||||
from sqlalchemy import exc
|
|
||||||
from sqlmodel import select
|
|
||||||
|
|
||||||
from app.model.models import Card, OneShotAccess
|
|
||||||
from app.services.database import Session, add_and_refresh
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
# See: https://github.com/technyon/nuki_hub#gpio-lock-control-optional
|
|
||||||
# TODO: add sensor pin
|
|
||||||
class DoorController:
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
mqtt_host: str = "localhost",
|
|
||||||
mqtt_port: int = 1883,
|
|
||||||
mock_factory: bool = False,
|
|
||||||
|
|
||||||
):
|
|
||||||
self._is_open: bool = False
|
|
||||||
self._mqtt = None
|
|
||||||
self._mqtt_topic = "nukihub/lock/action"
|
|
||||||
self._mock = mock_factory
|
|
||||||
|
|
||||||
if not mock_factory:
|
|
||||||
import paho.mqtt.client as mqtt
|
|
||||||
self._mqtt = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2)
|
|
||||||
self._mqtt.connect(mqtt_host, mqtt_port) #TODO: add login with username+pw, tls
|
|
||||||
self._mqtt.loop_start()
|
|
||||||
logger.info("Mqtt client connect to %s:%s", mqtt_host, mqtt_port)
|
|
||||||
|
|
||||||
logger.info(
|
|
||||||
"DoorController started. topic=%s mock=%s", self._mqtt_topic,
|
|
||||||
mock_factory,
|
|
||||||
)
|
|
||||||
|
|
||||||
def open(self):
|
|
||||||
if self._mock:
|
|
||||||
self._is_open = True
|
|
||||||
logger.info("Door unlocked.[MOCK]")
|
|
||||||
return
|
|
||||||
|
|
||||||
self._mqtt.publish(self._mqtt_topic, "unlock")
|
|
||||||
self._is_open = True
|
|
||||||
logger.info("Door unlocked!")
|
|
||||||
|
|
||||||
def close(self):
|
|
||||||
if self._mock:
|
|
||||||
self._is_open = False
|
|
||||||
logger.info("Door locked.[MOCK]")
|
|
||||||
return
|
|
||||||
|
|
||||||
self._mqtt.publish(self._mqtt_topic, "lock")
|
|
||||||
self._is_open = False
|
|
||||||
logger.info("Door locked!")
|
|
||||||
|
|
||||||
def is_open(self):
|
|
||||||
return self._is_open
|
|
||||||
|
|
||||||
|
|
||||||
_contoller: DoorController | None = None
|
|
||||||
|
|
||||||
|
|
||||||
def init_controller(ctrl: DoorController):
|
|
||||||
global _contoller
|
|
||||||
_contoller = ctrl
|
|
||||||
|
|
||||||
|
|
||||||
def get_controller():
|
|
||||||
if _contoller is None:
|
|
||||||
raise RuntimeError("DoorController not initialized.")
|
|
||||||
return _contoller
|
|
||||||
|
|
||||||
|
|
||||||
def openDoor():
|
|
||||||
get_controller().open()
|
|
||||||
|
|
||||||
|
|
||||||
def closeDoor():
|
|
||||||
get_controller().close()
|
|
||||||
|
|
||||||
|
|
||||||
def isDoorOpen():
|
|
||||||
return get_controller().is_open()
|
|
||||||
|
|
||||||
|
|
||||||
def decrementOneshot(db: Session, oneshot: OneShotAccess):
|
|
||||||
data = oneshot.model_dump()
|
|
||||||
if data["uses"] > 0:
|
|
||||||
data["uses"] = data["uses"] - 1
|
|
||||||
oneshot.sqlmodel_update(oneshot, update=data)
|
|
||||||
add_and_refresh(db, oneshot)
|
|
||||||
|
|
||||||
|
|
||||||
def checkAccess(key: str, db: Session):
|
|
||||||
try:
|
|
||||||
current_weekday = datetime.weekday(date.today())
|
|
||||||
current_time = datetime.now()
|
|
||||||
card = db.exec(select(Card).where(Card.key == key)).one()
|
|
||||||
if not card.enabled:
|
|
||||||
logger.info("Card Inactive!")
|
|
||||||
return False
|
|
||||||
for auth in card.group.accessauths:
|
|
||||||
logger.info(f"checking auth: {auth.name}")
|
|
||||||
if not auth.is_active:
|
|
||||||
logger.info("AA inactive!")
|
|
||||||
continue
|
|
||||||
if auth.type == "timetable":
|
|
||||||
for timetable in auth.timetables:
|
|
||||||
logger.info(f" checking timetable {timetable.id}")
|
|
||||||
logger.info(
|
|
||||||
f" comparing weekday: CUR:{current_weekday} TT:{timetable.weekday}"
|
|
||||||
)
|
|
||||||
if current_weekday == timetable.weekday:
|
|
||||||
starttime = datetime.combine(date.today(), timetable.starttime)
|
|
||||||
endtime = starttime + timedelta(minutes=timetable.duration)
|
|
||||||
logger.info(
|
|
||||||
f" comparing time: Start:{starttime} Current:{current_time} End:{endtime}"
|
|
||||||
)
|
|
||||||
if starttime < current_time < endtime:
|
|
||||||
logger.info("Access Valid!")
|
|
||||||
return True
|
|
||||||
if auth.type == "oneshot":
|
|
||||||
logger.info(f" oneshot auth found: {auth.oneshot}")
|
|
||||||
if current_time < auth.oneshot.ends_at:
|
|
||||||
if auth.oneshot.uses > 0:
|
|
||||||
decrementOneshot(db, auth.oneshot)
|
|
||||||
return True
|
|
||||||
logger.info("No more auths found")
|
|
||||||
return False
|
|
||||||
except exc.NoResultFound:
|
|
||||||
raise Exception("No AccessAuth with that key found!")
|
|
||||||
@@ -1,339 +0,0 @@
|
|||||||
import logging
|
|
||||||
import secrets
|
|
||||||
import threading
|
|
||||||
import time
|
|
||||||
|
|
||||||
from desfire import (
|
|
||||||
DESFire,
|
|
||||||
DESFireKey,
|
|
||||||
PCSCDevice,
|
|
||||||
diversify_key,
|
|
||||||
get_list,
|
|
||||||
to_hex_string,
|
|
||||||
)
|
|
||||||
from desfire.enums import (
|
|
||||||
DESFireCommunicationMode,
|
|
||||||
DESFireFileType,
|
|
||||||
DESFireKeySettings,
|
|
||||||
DESFireKeyType,
|
|
||||||
)
|
|
||||||
from desfire.schemas import FilePermissions, FileSettings, KeySettings
|
|
||||||
from fastapi import HTTPException, status
|
|
||||||
from smartcard.CardRequest import CardRequest
|
|
||||||
from smartcard.CardType import AnyCardType
|
|
||||||
from smartcard.Exceptions import CardRequestTimeoutException
|
|
||||||
|
|
||||||
from app.services.door import checkAccess, closeDoor, isDoorOpen, openDoor
|
|
||||||
from app.services.settings import settings
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
# ENV vars
|
|
||||||
MIFARE_APP_MASTER_KEY = settings.mifare_app_master_key
|
|
||||||
MIFARE_ACL_READ_BASE_KEY = settings.mifare_acl_read_base_key
|
|
||||||
MIFARE_ACL_WRITE_BASE_KEY = settings.mifare_acl_write_base_key
|
|
||||||
|
|
||||||
# Constants
|
|
||||||
MIFARE_APP_ID = "DEAFFE" # 7 bytes
|
|
||||||
MIFARE_ACL_READ_BASE_KEY_ID = 0x1
|
|
||||||
MIFARE_ACL_WRITE_BASE_KEY_ID = 0x2
|
|
||||||
MIFARE_SYS_ID = "FF0000" # 3 bytes, can essentially be anything
|
|
||||||
MIFARE_ENCRYPTED_FILE_ID = 0x1
|
|
||||||
|
|
||||||
|
|
||||||
def checkForKey():
|
|
||||||
if MIFARE_APP_MASTER_KEY is None:
|
|
||||||
logger.critical("NO MASTER KEY LOADED")
|
|
||||||
raise HTTPException(
|
|
||||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
|
||||||
detail="No key loaded! Check application.",
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def getCardService(timeout: int = 10):
|
|
||||||
cardtype = AnyCardType()
|
|
||||||
cardrequest = CardRequest(timeout=timeout, cardType=cardtype)
|
|
||||||
cardservice = cardrequest.waitforcard()
|
|
||||||
cardservice.connection.connect()
|
|
||||||
return cardservice
|
|
||||||
|
|
||||||
|
|
||||||
def readFileOnCard(desfire: DESFire):
|
|
||||||
if not MIFARE_ACL_READ_BASE_KEY:
|
|
||||||
logger.critical("MIFARE_ACL_READ_BASE_KEY not found! Reading skipped!")
|
|
||||||
return
|
|
||||||
# create keys
|
|
||||||
# desfire = DESFire(PCSCDevice(cardservice.connection.component))
|
|
||||||
aes_keysettings = KeySettings(key_type=DESFireKeyType.DF_KEY_AES)
|
|
||||||
keysettings = desfire.get_key_setting()
|
|
||||||
desKey = DESFireKey(keysettings, "00" * 8)
|
|
||||||
|
|
||||||
# Get real UID
|
|
||||||
desfire.authenticate(0x0, desKey)
|
|
||||||
# To get the uid you have to auth with an empty (default) key
|
|
||||||
uid = desfire.get_real_uid()
|
|
||||||
applications = desfire.get_application_ids()
|
|
||||||
try:
|
|
||||||
assert len(applications) == 1
|
|
||||||
assert applications[0] == get_list(MIFARE_APP_ID)
|
|
||||||
except AssertionError:
|
|
||||||
logger.error("No application found! The card must be registered first!")
|
|
||||||
time.sleep(4)
|
|
||||||
return
|
|
||||||
# Then use the key derivation with that uid, the appid, the sysid
|
|
||||||
diversification_data = (
|
|
||||||
[0x01] + uid + get_list(MIFARE_APP_ID) + get_list(MIFARE_SYS_ID)
|
|
||||||
)
|
|
||||||
read_div_key_bytes = diversify_key(
|
|
||||||
get_list(MIFARE_ACL_READ_BASE_KEY), diversification_data, pad_to_32=False
|
|
||||||
)
|
|
||||||
|
|
||||||
# Log in with derived read key
|
|
||||||
logger.debug("Start auth")
|
|
||||||
aes_app_read_key = DESFireKey(aes_keysettings, read_div_key_bytes)
|
|
||||||
desfire.select_application(MIFARE_APP_ID)
|
|
||||||
|
|
||||||
desfire.authenticate(MIFARE_ACL_READ_BASE_KEY_ID, aes_app_read_key)
|
|
||||||
|
|
||||||
logger.debug(f"Read data from {MIFARE_ENCRYPTED_FILE_ID}")
|
|
||||||
file_data = desfire.get_file_settings(MIFARE_ENCRYPTED_FILE_ID)
|
|
||||||
rdata = desfire.read_file_data(MIFARE_ENCRYPTED_FILE_ID, file_data)
|
|
||||||
# convert list of int to str
|
|
||||||
rdata = to_hex_string(rdata).replace(" ", "").lower()
|
|
||||||
logger.debug(f"Data on card: {rdata}")
|
|
||||||
return rdata
|
|
||||||
|
|
||||||
|
|
||||||
def DeleteCard():
|
|
||||||
try:
|
|
||||||
checkForKey()
|
|
||||||
from app.main import scanner as scannerThread
|
|
||||||
|
|
||||||
scannerThread.stop()
|
|
||||||
cardservice = getCardService(15)
|
|
||||||
|
|
||||||
# Create Desfire object
|
|
||||||
desfire = DESFire(PCSCDevice(cardservice.connection.component))
|
|
||||||
|
|
||||||
rdata = readFileOnCard(desfire=desfire)
|
|
||||||
|
|
||||||
# Create Key objects
|
|
||||||
aes_keysettings = KeySettings(key_type=DESFireKeyType.DF_KEY_AES)
|
|
||||||
des_keysettings = KeySettings(key_type=DESFireKeyType.DF_KEY_2K3DES)
|
|
||||||
desKey = DESFireKey(des_keysettings, "00" * 8)
|
|
||||||
aes_master_key = DESFireKey(aes_keysettings, MIFARE_APP_MASTER_KEY)
|
|
||||||
aes_null_key = DESFireKey(aes_keysettings, "00" * 16)
|
|
||||||
|
|
||||||
desfire.select_application(0x0)
|
|
||||||
desfire.authenticate(0x0, desKey)
|
|
||||||
|
|
||||||
applications = desfire.get_application_ids()
|
|
||||||
logger.debug(f"Applications: {applications}")
|
|
||||||
if len(applications) == 0:
|
|
||||||
raise HTTPException(
|
|
||||||
status_code=status.HTTP_410_GONE, detail="Card is empty."
|
|
||||||
)
|
|
||||||
|
|
||||||
desfire.select_application(MIFARE_APP_ID)
|
|
||||||
desfire.authenticate(0x0, aes_master_key)
|
|
||||||
|
|
||||||
try:
|
|
||||||
desfire.delete_application(MIFARE_APP_ID)
|
|
||||||
logger.info("App deleted!")
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
scannerThread.start()
|
|
||||||
return rdata
|
|
||||||
except (Exception, AssertionError) as e:
|
|
||||||
logger.error(f"Error in deletion function: {e}", exc_info=True)
|
|
||||||
raise HTTPException(
|
|
||||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=f"Error: {e}"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def WriteNewCard():
|
|
||||||
try:
|
|
||||||
checkForKey()
|
|
||||||
from app.main import scanner as scannerThread
|
|
||||||
|
|
||||||
scannerThread.stop()
|
|
||||||
|
|
||||||
cardservice = getCardService(20)
|
|
||||||
|
|
||||||
desfire = DESFire(PCSCDevice(cardservice.connection.component))
|
|
||||||
|
|
||||||
# Create Key objects
|
|
||||||
aes_keysettings = KeySettings(key_type=DESFireKeyType.DF_KEY_AES)
|
|
||||||
aes_null_key = DESFireKey(aes_keysettings, "00" * 16)
|
|
||||||
aes_master_key = DESFireKey(aes_keysettings, MIFARE_APP_MASTER_KEY)
|
|
||||||
desKey = DESFireKey(desfire.get_key_setting(), "00" * 8)
|
|
||||||
|
|
||||||
# Authenticate with default DES key
|
|
||||||
logger.debug("Authenticating with default DES key...")
|
|
||||||
desfire.authenticate(0x0, desKey)
|
|
||||||
|
|
||||||
# get uid
|
|
||||||
uid = desfire.get_real_uid()
|
|
||||||
|
|
||||||
applications = desfire.get_application_ids()
|
|
||||||
logger.debug(f"Applications: {applications}")
|
|
||||||
if len(applications) >= 1:
|
|
||||||
raise HTTPException(
|
|
||||||
status_code=status.HTTP_409_CONFLICT, detail="This Card already has a key!"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Set default key
|
|
||||||
logger.debug("Setting default key...")
|
|
||||||
desfire.change_default_key(aes_null_key, 0x0)
|
|
||||||
|
|
||||||
# Create application
|
|
||||||
logger.debug("Creating application...")
|
|
||||||
app_settings = KeySettings(
|
|
||||||
settings=[
|
|
||||||
DESFireKeySettings.KS_ALLOW_CHANGE_MK,
|
|
||||||
DESFireKeySettings.KS_LISTING_WITHOUT_MK,
|
|
||||||
DESFireKeySettings.KS_CREATE_DELETE_WITHOUT_MK,
|
|
||||||
DESFireKeySettings.KS_CONFIGURATION_CHANGEABLE,
|
|
||||||
],
|
|
||||||
key_type=DESFireKeyType.DF_KEY_AES,
|
|
||||||
)
|
|
||||||
desfire.create_application(MIFARE_APP_ID, app_settings, 4)
|
|
||||||
|
|
||||||
# Verify application creation
|
|
||||||
applications = desfire.get_application_ids()
|
|
||||||
assert len(applications) == 1
|
|
||||||
assert applications[0] == get_list(MIFARE_APP_ID)
|
|
||||||
logger.debug(" - Application created successfully.")
|
|
||||||
|
|
||||||
# Select application
|
|
||||||
desfire.select_application(MIFARE_APP_ID)
|
|
||||||
|
|
||||||
# recreate key object
|
|
||||||
desfire.authenticate(0x0, aes_null_key)
|
|
||||||
desfire.change_key(0x0, aes_null_key, aes_master_key, 0x1)
|
|
||||||
|
|
||||||
logger.debug("new key auth")
|
|
||||||
desfire.authenticate(0x0, aes_master_key)
|
|
||||||
|
|
||||||
aes_null_key = DESFireKey(aes_keysettings, "00" * 16)
|
|
||||||
|
|
||||||
# generate div data
|
|
||||||
diversification_data = (
|
|
||||||
[0x01] + uid + get_list(MIFARE_APP_ID) + get_list(MIFARE_SYS_ID)
|
|
||||||
)
|
|
||||||
read_div_key_bytes = diversify_key(
|
|
||||||
get_list(MIFARE_ACL_READ_BASE_KEY), diversification_data, pad_to_32=False
|
|
||||||
)
|
|
||||||
write_div_key_bytes = diversify_key(
|
|
||||||
get_list(MIFARE_ACL_WRITE_BASE_KEY), diversification_data, pad_to_32=False
|
|
||||||
)
|
|
||||||
|
|
||||||
logger.debug("Changing file read key...")
|
|
||||||
aes_file_read_key = DESFireKey(aes_keysettings, read_div_key_bytes)
|
|
||||||
desfire.change_key(
|
|
||||||
MIFARE_ACL_READ_BASE_KEY_ID, aes_null_key, aes_file_read_key, 0x1
|
|
||||||
)
|
|
||||||
|
|
||||||
logger.debug("Changing file write key...")
|
|
||||||
aes_file_write_key = DESFireKey(aes_keysettings, write_div_key_bytes)
|
|
||||||
desfire.change_key(
|
|
||||||
MIFARE_ACL_WRITE_BASE_KEY_ID, aes_null_key, aes_file_write_key, 0x1
|
|
||||||
)
|
|
||||||
|
|
||||||
logger.debug("Create encrypted file containing key...")
|
|
||||||
file_settings = FileSettings(
|
|
||||||
file_size=16,
|
|
||||||
encryption=DESFireCommunicationMode.ENCRYPTED,
|
|
||||||
permissions=FilePermissions(
|
|
||||||
read_key=MIFARE_ACL_READ_BASE_KEY_ID,
|
|
||||||
write_key=MIFARE_ACL_WRITE_BASE_KEY_ID,
|
|
||||||
),
|
|
||||||
file_type=DESFireFileType.MDFT_STANDARD_DATA_FILE,
|
|
||||||
)
|
|
||||||
desfire.create_standard_file(MIFARE_ENCRYPTED_FILE_ID, file_settings)
|
|
||||||
file_data = desfire.get_file_settings(MIFARE_ENCRYPTED_FILE_ID)
|
|
||||||
|
|
||||||
logger.debug("Writing UID to encrypted file...")
|
|
||||||
key = secrets.token_hex(16)
|
|
||||||
desfire.write_file_data(
|
|
||||||
MIFARE_ENCRYPTED_FILE_ID, 0x0, file_data.encryption, get_list(key)
|
|
||||||
)
|
|
||||||
|
|
||||||
logger.debug("Reading from encrypted file...")
|
|
||||||
rdata = desfire.read_file_data(MIFARE_ENCRYPTED_FILE_ID, file_data)
|
|
||||||
assert rdata == get_list(key)
|
|
||||||
logger.debug(" - Data written successfully.")
|
|
||||||
scannerThread.start()
|
|
||||||
return key, to_hex_string(data=uid, separator=":")
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
logger.error(f"Error in write function: {e}", exc_info=False)
|
|
||||||
scannerThread.start()
|
|
||||||
raise HTTPException(
|
|
||||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=f"Error: {e}"
|
|
||||||
)
|
|
||||||
|
|
||||||
class BackgroundScanner:
|
|
||||||
def __init__(self, db):
|
|
||||||
self.db = db
|
|
||||||
self.is_running = False
|
|
||||||
self.thread: threading.Thread | None = None
|
|
||||||
|
|
||||||
def start(self):
|
|
||||||
if self.is_running:
|
|
||||||
logger.error("Scanner already running")
|
|
||||||
return
|
|
||||||
self.is_running = True
|
|
||||||
self.thread = threading.Thread(target=self._scan_loop, daemon=True)
|
|
||||||
self.thread.start()
|
|
||||||
logger.info("Scanner started")
|
|
||||||
|
|
||||||
def stop(self):
|
|
||||||
self.is_running = False
|
|
||||||
if self.thread:
|
|
||||||
self.thread.join()
|
|
||||||
logger.info("Scanner stopped")
|
|
||||||
|
|
||||||
def _scan_loop(self):
|
|
||||||
while self.is_running:
|
|
||||||
try:
|
|
||||||
card_content = self._read_card()
|
|
||||||
if card_content:
|
|
||||||
self._check_db(card_content)
|
|
||||||
time.sleep(5)
|
|
||||||
logger.debug("READY after success")
|
|
||||||
else:
|
|
||||||
time.sleep(0.1)
|
|
||||||
logger.debug("READY after timout")
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
logger.error(f"Error in function _scan_loop: {e}", exc_info=False)
|
|
||||||
time.sleep(6)
|
|
||||||
|
|
||||||
def _read_card(self):
|
|
||||||
time.sleep(0.5)
|
|
||||||
try:
|
|
||||||
cardservice = getCardService(3)
|
|
||||||
except CardRequestTimeoutException:
|
|
||||||
logger.debug("No tag detected within the timeout.")
|
|
||||||
return
|
|
||||||
# Create Desfire object
|
|
||||||
desfire = DESFire(PCSCDevice(cardservice.connection.component))
|
|
||||||
try:
|
|
||||||
rdata = readFileOnCard(desfire=desfire)
|
|
||||||
return rdata
|
|
||||||
except Exception as e:
|
|
||||||
logger.error(f"Error in function _read_card: {e}", exc_info=False)
|
|
||||||
time.sleep(5)
|
|
||||||
|
|
||||||
def _check_db(self, key):
|
|
||||||
if isDoorOpen():
|
|
||||||
closeDoor()
|
|
||||||
logger.info("Door closed by key %s", key)
|
|
||||||
else:
|
|
||||||
check = checkAccess(key, self.db)
|
|
||||||
if check:
|
|
||||||
openDoor()
|
|
||||||
logger.info("Access granted!")
|
|
||||||
else:
|
|
||||||
logger.error("Access denied!")
|
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
import logging
|
|
||||||
from functools import lru_cache
|
|
||||||
|
|
||||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
class Settings(BaseSettings):
|
|
||||||
model_config = SettingsConfigDict(env_file=".env")
|
|
||||||
|
|
||||||
secret_key: str
|
|
||||||
sqlalchemy_database_url: str = "sqlite:///./gatekeeper.db"
|
|
||||||
mqtt_host: str = "localhost"
|
|
||||||
mqtt_port: int = 1883
|
|
||||||
mock: bool = True
|
|
||||||
alembic_config: str = "./alembic.ini"
|
|
||||||
|
|
||||||
disable_cards: bool = False
|
|
||||||
mifare_app_master_key: str | None = None
|
|
||||||
mifare_acl_read_base_key: str | None = None
|
|
||||||
mifare_acl_write_base_key: str | None = None
|
|
||||||
|
|
||||||
|
|
||||||
@lru_cache(1)
|
|
||||||
def _create_settings():
|
|
||||||
settings = Settings()
|
|
||||||
if not settings.disable_cards:
|
|
||||||
missing = [
|
|
||||||
name.upper()
|
|
||||||
for name in (
|
|
||||||
"mifare_app_master_key",
|
|
||||||
"mifare_acl_read_base_key",
|
|
||||||
"mifare_acl_write_base_key",
|
|
||||||
)
|
|
||||||
if not getattr(settings, name)
|
|
||||||
]
|
|
||||||
if missing:
|
|
||||||
logger.critical(
|
|
||||||
"Missing environment variable for scanner start: %s"
|
|
||||||
"Card scanner and related funcionality is disabled!",
|
|
||||||
", ".join(missing),
|
|
||||||
)
|
|
||||||
settings.disable_cards = True
|
|
||||||
return settings
|
|
||||||
|
|
||||||
|
|
||||||
class _SettingsProxy:
|
|
||||||
_instance: Settings | None = None
|
|
||||||
|
|
||||||
def _load(self) -> Settings:
|
|
||||||
if self._instance is None:
|
|
||||||
self._instance = _create_settings()
|
|
||||||
return self._instance
|
|
||||||
|
|
||||||
def __getattr__(self, name: str):
|
|
||||||
return getattr(self._load(), name)
|
|
||||||
|
|
||||||
def __setattr__(self, name: str, value):
|
|
||||||
if name == "_instance":
|
|
||||||
super().__setattr__(name, value)
|
|
||||||
else:
|
|
||||||
setattr(self._load(), name, value)
|
|
||||||
|
|
||||||
def reset(self) -> None:
|
|
||||||
self._instance = None
|
|
||||||
_create_settings.cache_clear()
|
|
||||||
|
|
||||||
|
|
||||||
settings = _SettingsProxy()
|
|
||||||
Generated
+12
-12
@@ -2,11 +2,11 @@
|
|||||||
"nodes": {
|
"nodes": {
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1778869304,
|
"lastModified": 1775710090,
|
||||||
"narHash": "sha256-30sZNZoA1cqF5JNO9fVX+wgiQYjB7HJqqJ4ztCDeBZE=",
|
"narHash": "sha256-ar3rofg+awPB8QXDaFJhJ2jJhu+KqN/PRCXeyuXR76E=",
|
||||||
"owner": "nixos",
|
"owner": "nixos",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "d233902339c02a9c334e7e593de68855ad26c4cb",
|
"rev": "4c1018dae018162ec878d42fec712642d214fdfa",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -29,11 +29,11 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1776659114,
|
"lastModified": 1773870109,
|
||||||
"narHash": "sha256-qapCOQmR++yZSY43dzrp3wCrkOTLpod+ONtJWBk6iKU=",
|
"narHash": "sha256-ZoTdqZP03DcdoyxvpFHCAek4bkPUTUPUF3oCCgc3dP4=",
|
||||||
"owner": "pyproject-nix",
|
"owner": "pyproject-nix",
|
||||||
"repo": "build-system-pkgs",
|
"repo": "build-system-pkgs",
|
||||||
"rev": "ffaa2161dd5d63e0e94591f86b54fc239660fb2e",
|
"rev": "b6e74f433b02fa4b8a7965ee24680f4867e2926f",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -49,11 +49,11 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1778901413,
|
"lastModified": 1776120154,
|
||||||
"narHash": "sha256-GSKXTAnFqRAMlZkJrIPcQMYf+lpMr66K3i60mB9STvc=",
|
"narHash": "sha256-mtIBTmVKzyoFYoAGdd8Cd7iswFna9YQVyjObZLXPO64=",
|
||||||
"owner": "pyproject-nix",
|
"owner": "pyproject-nix",
|
||||||
"repo": "pyproject.nix",
|
"repo": "pyproject.nix",
|
||||||
"rev": "a228447c3e179d477c1b6246ef3efa8cfe3c469a",
|
"rev": "29dc4e9960d2b7f122b52b155e0e8f87cd5c5c08",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -80,11 +80,11 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1779269674,
|
"lastModified": 1776114780,
|
||||||
"narHash": "sha256-P1LHCRdYpdtHAEzuEsNHrI6d9mVPl5a2fyFDZGHNVbI=",
|
"narHash": "sha256-aYUgp40qkY7oNSm+G9A/woNYP+eDeFM0bYckfmxEUiY=",
|
||||||
"owner": "pyproject-nix",
|
"owner": "pyproject-nix",
|
||||||
"repo": "uv2nix",
|
"repo": "uv2nix",
|
||||||
"rev": "69aec536f6d1acc415ed2e20299312802aba98c6",
|
"rev": "73ff87a3e489b07b9cf842f917963a9e40d49225",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|||||||
@@ -25,7 +25,6 @@
|
|||||||
|
|
||||||
outputs =
|
outputs =
|
||||||
{
|
{
|
||||||
self,
|
|
||||||
nixpkgs,
|
nixpkgs,
|
||||||
pyproject-nix,
|
pyproject-nix,
|
||||||
uv2nix,
|
uv2nix,
|
||||||
@@ -59,17 +58,6 @@
|
|||||||
lib.composeManyExtensions [
|
lib.composeManyExtensions [
|
||||||
pyproject-build-systems.overlays.wheel
|
pyproject-build-systems.overlays.wheel
|
||||||
overlay
|
overlay
|
||||||
(final: prev: {
|
|
||||||
pyscard = prev.pyscard.overrideAttrs (old: {
|
|
||||||
nativeBuildInputs = (old.nativeBuildInputs or []) ++ [ pkgs.swig pkgs.pkg-config];
|
|
||||||
buildInputs = (old.buildInputs or []) ++ [ pkgs.pcsclite.dev ];
|
|
||||||
NIX_CFLAGS_COMPILE = "-I${pkgs.pcsclite.dev}/include/PCSC";
|
|
||||||
});
|
|
||||||
lgpio = prev.lgpio.overrideAttrs (old: {
|
|
||||||
nativeBuildInputs = (old.nativeBuildInputs or []) ++ [ pkgs.swig ];
|
|
||||||
buildInputs = (old.buildInputs or []) ++ [ pkgs.lgpio ];
|
|
||||||
});
|
|
||||||
})
|
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@@ -88,16 +76,11 @@
|
|||||||
packages = [
|
packages = [
|
||||||
virtualenv
|
virtualenv
|
||||||
pkgs.uv
|
pkgs.uv
|
||||||
pkgs.pcsclite
|
|
||||||
pkgs.pcsclite.dev
|
|
||||||
pkgs.swig
|
|
||||||
pkgs.pkg-config
|
|
||||||
];
|
];
|
||||||
env = {
|
env = {
|
||||||
UV_NO_SYNC = "1";
|
UV_NO_SYNC = "1";
|
||||||
UV_PYTHON = pythonSet.python.interpreter;
|
UV_PYTHON = pythonSet.python.interpreter;
|
||||||
UV_PYTHON_DOWNLOADS = "never";
|
UV_PYTHON_DOWNLOADS = "never";
|
||||||
LD_LIBRARY_PATH = "${lib.getLib pkgs.pcsclite}/lib:${lib.getLib pkgs.lgpio}/lib";
|
|
||||||
};
|
};
|
||||||
shellHook = ''
|
shellHook = ''
|
||||||
unset PYTHONPATH
|
unset PYTHONPATH
|
||||||
@@ -110,24 +93,5 @@
|
|||||||
packages = forAllSystems (system: {
|
packages = forAllSystems (system: {
|
||||||
default = pythonSets.${system}.mkVirtualEnv "gatekeeper" workspace.deps.default;
|
default = pythonSets.${system}.mkVirtualEnv "gatekeeper" workspace.deps.default;
|
||||||
});
|
});
|
||||||
|
|
||||||
apps = forAllSystems (system: {
|
|
||||||
default = {
|
|
||||||
type = "app";
|
|
||||||
program = toString (nixpkgs.legacyPackages.${system}.writeShellScript "gatekeeper" ''
|
|
||||||
export LD_LIBRARY_PATH="${lib.getLib nixpkgs.legacyPackages.${system}.pcsclite}/lib''${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
|
|
||||||
exec ${self.packages.${system}.default}/bin/fastapi run ${self}/app/main.py "$@";
|
|
||||||
'');
|
|
||||||
};
|
|
||||||
dev = {
|
|
||||||
type = "app";
|
|
||||||
program = toString (nixpkgs.legacyPackages.${system}.writeShellScript "gatekeeper" ''
|
|
||||||
export LD_LIBRARY_PATH="${lib.getLib nixpkgs.legacyPackages.${system}.pcsclite}/lib''${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
|
|
||||||
exec ${self.packages.${system}.default}/bin/fastapi dev ${self}/app/main.py "$@";
|
|
||||||
'');
|
|
||||||
};
|
|
||||||
});
|
|
||||||
nixosModules.gatekeeper = { config, pkgs, lib, ... }@args:
|
|
||||||
import ./module.nix (args // { self = self; system = pkgs.system; });
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
-74
@@ -1,74 +0,0 @@
|
|||||||
{config, pkgs, lib, self, system, ... }:
|
|
||||||
let
|
|
||||||
cfg = config.services.gatekeeper;
|
|
||||||
in
|
|
||||||
{
|
|
||||||
options = {
|
|
||||||
services.gatekeeper = {
|
|
||||||
enable = lib.mkEnableOption "Enable the gatekeeper api service.";
|
|
||||||
envFile = lib.mkOption {
|
|
||||||
type = lib.types.nullOr lib.types.path;
|
|
||||||
description = "The path to a .env file with all the other options";
|
|
||||||
};
|
|
||||||
db = lib.mkOption {
|
|
||||||
type = lib.types.path;
|
|
||||||
description = "Where to save the database.";
|
|
||||||
default = "/var/lib/gatekeeper";
|
|
||||||
};
|
|
||||||
mock = lib.mkOption {
|
|
||||||
type = lib.types.str;
|
|
||||||
default = "False";
|
|
||||||
description = "Mock the doorcontroller. Has to be a string!";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
config = lib.mkIf cfg.enable {
|
|
||||||
users.groups.gatekeeper = {};
|
|
||||||
users.groups.gpio = {};
|
|
||||||
users.users.gatekeeper = {
|
|
||||||
description = "gatekeeper user";
|
|
||||||
group = "gatekeeper";
|
|
||||||
extraGroups = ["gpio"];
|
|
||||||
isSystemUser = true;
|
|
||||||
};
|
|
||||||
services.udev.extraRules = lib.mkBefore ''
|
|
||||||
KERNEL=="gpiomem", GROUP="gpio", MODE="0660"
|
|
||||||
SUBSYSTEM=="gpio", KERNEL=="gpiochip*", ACTION=="add", PROGRAM="${pkgs.bash}/bin/bash -c '${pkgs.coreutils}/bin/chgrp gpio /dev/%k && chmod 660 /dev/%k && ${pkgs.coreutils}/bin/chgrp -R gpio /sys/class/gpio && ${pkgs.coreutils}/bin/chmod -R g=u /sys/class/gpio'"
|
|
||||||
SUBSYSTEM=="gpio", ACTION=="add", PROGRAM="${pkgs.bash}/bin/bash -c '${pkgs.coreutils}/bin/chgrp -R gpio /sys%p && ${pkgs.coreutils}/bin/chmod -R g=u /sys%p'"
|
|
||||||
'';
|
|
||||||
|
|
||||||
boot.kernelParams = [
|
|
||||||
"iomem=relaxed" # for pigpiod
|
|
||||||
"strict-devmem=0"
|
|
||||||
];
|
|
||||||
|
|
||||||
services.pcscd = {
|
|
||||||
enable = true;
|
|
||||||
plugins = [ pkgs.acsccid ];
|
|
||||||
};
|
|
||||||
networking.firewall.allowedTCPPorts = [ 8000 ];
|
|
||||||
systemd.services.gatekeeper = {
|
|
||||||
description = "Runs the gatekeeper api";
|
|
||||||
script = ''
|
|
||||||
export LD_LIBRARY_PATH="${lib.getLib pkgs.pcsclite}/lib''${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
|
|
||||||
exec ${self.packages.${system}.default}/bin/uvicorn --host 0.0.0.0 --port 8000 --app-dir ${self} app.main:app
|
|
||||||
'';
|
|
||||||
after = [ "network.target" ];
|
|
||||||
wantedBy = ["multi-user.target"];
|
|
||||||
|
|
||||||
serviceConfig = {
|
|
||||||
User = "gatekeeper";
|
|
||||||
Restart = "on-failure";
|
|
||||||
RestartSec = "20";
|
|
||||||
StateDirectory = "gatekeeper";
|
|
||||||
WorkingDirectory = "/var/lib/gatekeeper";
|
|
||||||
EnvironmentFile = cfg.envFile;
|
|
||||||
};
|
|
||||||
environment = {
|
|
||||||
SQLALCHEMY_DATABASE_URL = "sqlite:///${cfg.db}/gatekeeper.db";
|
|
||||||
ALEMBIC_CONFIG = "${self}/alembic.ini";
|
|
||||||
MOCK = cfg.mock;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
+1
-37
@@ -9,21 +9,9 @@ dependencies = [
|
|||||||
"sqlmodel>=0.0.38",
|
"sqlmodel>=0.0.38",
|
||||||
"poetry>=2.3.4",
|
"poetry>=2.3.4",
|
||||||
"python-desfire",
|
"python-desfire",
|
||||||
|
"paho-mqtt>=2.1.0",
|
||||||
"pyjwt[crypto]>=2.12.1",
|
"pyjwt[crypto]>=2.12.1",
|
||||||
"pwdlib[argon2]>=0.3.0",
|
"pwdlib[argon2]>=0.3.0",
|
||||||
"requests>=2.33.1",
|
|
||||||
"setuptools>=82.0.1",
|
|
||||||
"pyscard>=2.3.1",
|
|
||||||
"alembic>=1.18.5",
|
|
||||||
"pydantic-settings>=2.13.1",
|
|
||||||
"paho-mqtt>=2.1.0",
|
|
||||||
]
|
|
||||||
[dependency-groups]
|
|
||||||
dev = [
|
|
||||||
"ruff>=0.16.0",
|
|
||||||
"pytest>=9.0.3",
|
|
||||||
"pytest-cov>=7.1.0",
|
|
||||||
"jedi-language-server>=0.47.0",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[tool.uv.sources]
|
[tool.uv.sources]
|
||||||
@@ -31,27 +19,3 @@ python-desfire = { git = "https://github.com/waza-ari/python-desfire" }
|
|||||||
|
|
||||||
[tool.uv.extra-build-dependencies]
|
[tool.uv.extra-build-dependencies]
|
||||||
python-desfire = ["poetry"]
|
python-desfire = ["poetry"]
|
||||||
"pyscard" = ["setuptools"]
|
|
||||||
"lgpio" = ["setuptools"]
|
|
||||||
|
|
||||||
[tool.setuptools]
|
|
||||||
py-modules = ["app"]
|
|
||||||
|
|
||||||
[tool.ruff]
|
|
||||||
exclude = ["alembic"]
|
|
||||||
[tool.ruff.lint]
|
|
||||||
select = [
|
|
||||||
# pycodestyle
|
|
||||||
"E",
|
|
||||||
# Pyflakes
|
|
||||||
"F",
|
|
||||||
# pyupgrade
|
|
||||||
"UP",
|
|
||||||
# flake8-bugbear
|
|
||||||
"B",
|
|
||||||
# flake8-simplify
|
|
||||||
"SIM",
|
|
||||||
# isort
|
|
||||||
"I",
|
|
||||||
]
|
|
||||||
ignore = ["B008"]
|
|
||||||
|
|||||||
@@ -1,137 +0,0 @@
|
|||||||
import os
|
|
||||||
from datetime import time
|
|
||||||
|
|
||||||
import pytest
|
|
||||||
from fastapi.testclient import TestClient
|
|
||||||
from sqlalchemy.pool import StaticPool
|
|
||||||
from sqlmodel import Session, SQLModel, create_engine
|
|
||||||
|
|
||||||
os.environ["SECRET_KEY"] = "ff" * 16
|
|
||||||
|
|
||||||
from app.main import app
|
|
||||||
from app.model.models import (
|
|
||||||
AccessAuthorizationDB,
|
|
||||||
Card,
|
|
||||||
GroupDB,
|
|
||||||
Timetable,
|
|
||||||
UserDB,
|
|
||||||
)
|
|
||||||
from app.services.database import get_session
|
|
||||||
|
|
||||||
# Use in-memory SQLite for testing
|
|
||||||
TEST_SQLALCHEMY_DATABASE_URL = "sqlite://"
|
|
||||||
|
|
||||||
engine = create_engine(
|
|
||||||
TEST_SQLALCHEMY_DATABASE_URL,
|
|
||||||
connect_args={"check_same_thread": False},
|
|
||||||
poolclass=StaticPool,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="function")
|
|
||||||
def db_session():
|
|
||||||
"""Create a fresh database session for each test."""
|
|
||||||
SQLModel.metadata.create_all(engine)
|
|
||||||
with Session(engine) as session:
|
|
||||||
yield session
|
|
||||||
SQLModel.metadata.drop_all(engine)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="function")
|
|
||||||
def client(db_session):
|
|
||||||
"""Create a test client with a database session override."""
|
|
||||||
|
|
||||||
def override_get_session():
|
|
||||||
yield db_session
|
|
||||||
|
|
||||||
app.dependency_overrides[get_session] = override_get_session
|
|
||||||
with TestClient(app) as test_client:
|
|
||||||
yield test_client
|
|
||||||
app.dependency_overrides.clear()
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def admin_user(db_session):
|
|
||||||
"""Create an admin user for testing."""
|
|
||||||
from app.services.auth import get_password_hash
|
|
||||||
|
|
||||||
admin = UserDB(
|
|
||||||
name="admin", passwordhash=get_password_hash("admin123"), is_admin=True
|
|
||||||
)
|
|
||||||
db_session.add(admin)
|
|
||||||
db_session.commit()
|
|
||||||
db_session.refresh(admin)
|
|
||||||
return admin
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def regular_user(db_session):
|
|
||||||
"""Create a regular user for testing."""
|
|
||||||
from app.services.auth import get_password_hash
|
|
||||||
|
|
||||||
user = UserDB(
|
|
||||||
name="user", passwordhash=get_password_hash("user123"), is_admin=False
|
|
||||||
)
|
|
||||||
db_session.add(user)
|
|
||||||
db_session.commit()
|
|
||||||
db_session.refresh(user)
|
|
||||||
return user
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def auth_headers(client, admin_user):
|
|
||||||
"""Get authentication headers for admin user."""
|
|
||||||
response = client.post(
|
|
||||||
"/api/v1/token", data={"username": admin_user.name, "password": "admin123"}
|
|
||||||
)
|
|
||||||
token = response.json()["access_token"]
|
|
||||||
return {"Authorization": f"Bearer {token}"}
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def user_auth_headers(client, regular_user):
|
|
||||||
"""Get authentication headers for regular user."""
|
|
||||||
response = client.post(
|
|
||||||
"/api/v1/token", data={"username": regular_user.name, "password": "user123"}
|
|
||||||
)
|
|
||||||
token = response.json()["access_token"]
|
|
||||||
return {"Authorization": f"Bearer {token}"}
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def test_group(db_session):
|
|
||||||
"""Create a test group."""
|
|
||||||
group = GroupDB(name="Test Group")
|
|
||||||
db_session.add(group)
|
|
||||||
db_session.commit()
|
|
||||||
db_session.refresh(group)
|
|
||||||
return group
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def test_card(db_session, test_group):
|
|
||||||
"""Create a test card."""
|
|
||||||
card = Card(
|
|
||||||
key="test-key-123",
|
|
||||||
group_id=test_group.id,
|
|
||||||
enabled=True,
|
|
||||||
name="test_card",
|
|
||||||
card_serial="00:00:00:00:00:00:00",
|
|
||||||
)
|
|
||||||
db_session.add(card)
|
|
||||||
db_session.commit()
|
|
||||||
db_session.refresh(card)
|
|
||||||
return card
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def test_aa_tt(db_session):
|
|
||||||
"""Create a test access authorization with timetable."""
|
|
||||||
tt = Timetable(weekday=1, starttime=time(1, 0, 0, 0), duration=50)
|
|
||||||
aa = AccessAuthorizationDB(
|
|
||||||
name="Test AA", is_active=True, type="timetable", timetables=[tt]
|
|
||||||
)
|
|
||||||
db_session.add(aa)
|
|
||||||
db_session.commit()
|
|
||||||
db_session.refresh(aa)
|
|
||||||
return aa
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
def test_app_startup(client):
|
|
||||||
"""Test that the application starts up correctly."""
|
|
||||||
response = client.get("/")
|
|
||||||
# Application should respond (even if it's a 404)
|
|
||||||
assert response.status_code in [404, 200]
|
|
||||||
|
|
||||||
|
|
||||||
def test_router_includes():
|
|
||||||
"""Test that all routers are included in the app."""
|
|
||||||
from app.main import app
|
|
||||||
|
|
||||||
routes = [route.path for route in app.routes]
|
|
||||||
|
|
||||||
# Check that router prefixes are present
|
|
||||||
assert any("/users" in route for route in routes)
|
|
||||||
assert any("/cards" in route for route in routes)
|
|
||||||
assert any("/groups" in route for route in routes)
|
|
||||||
assert any("/aa" in route for route in routes)
|
|
||||||
assert any("/token" in route for route in routes)
|
|
||||||
@@ -1,102 +0,0 @@
|
|||||||
import datetime
|
|
||||||
|
|
||||||
from app.model.models import (
|
|
||||||
AaGroupLink,
|
|
||||||
AccessAuthorizationBase,
|
|
||||||
AccessAuthorizationCreate,
|
|
||||||
Card,
|
|
||||||
GroupBase,
|
|
||||||
GroupCreate,
|
|
||||||
TimetableCreate,
|
|
||||||
Token,
|
|
||||||
TokenData,
|
|
||||||
UserBase,
|
|
||||||
UserCreate,
|
|
||||||
UserUpdate,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_user_models():
|
|
||||||
"""Test user model creation and validation."""
|
|
||||||
# Test UserBase
|
|
||||||
user_base = UserBase(name="Test User", email="test@example.com", is_admin=False)
|
|
||||||
assert user_base.name == "Test User"
|
|
||||||
assert user_base.email == "test@example.com"
|
|
||||||
assert user_base.is_admin is False
|
|
||||||
|
|
||||||
# Test UserCreate
|
|
||||||
user_create = UserCreate(
|
|
||||||
name="New User", email="new@example.com", password="secret123"
|
|
||||||
)
|
|
||||||
assert user_create.password == "secret123"
|
|
||||||
|
|
||||||
# Test UserUpdate
|
|
||||||
user_update = UserUpdate(name="Updated Name")
|
|
||||||
assert user_update.name == "Updated Name"
|
|
||||||
assert user_update.email is None
|
|
||||||
|
|
||||||
|
|
||||||
def test_group_models():
|
|
||||||
"""Test group model creation and validation."""
|
|
||||||
# Test GroupBase
|
|
||||||
group_base = GroupBase(name="Test Group")
|
|
||||||
assert group_base.name == "Test Group"
|
|
||||||
|
|
||||||
# Test GroupCreate
|
|
||||||
group_create = GroupCreate(name="New Group")
|
|
||||||
assert group_create.name == "New Group"
|
|
||||||
|
|
||||||
|
|
||||||
def test_access_authorization_models():
|
|
||||||
"""Test access authorization model creation and validation."""
|
|
||||||
# Test AccessAuthorizationBase
|
|
||||||
aa_base = AccessAuthorizationBase(name="Test AA", is_active=True, type="timetable")
|
|
||||||
assert aa_base.name == "Test AA"
|
|
||||||
assert aa_base.is_active is True
|
|
||||||
|
|
||||||
# Test AccessAuthorizationCreate with timetables
|
|
||||||
timetable_create = TimetableCreate(weekday=1, starttime="08:00", duration=60)
|
|
||||||
aa_create = AccessAuthorizationCreate(
|
|
||||||
name="New AA", is_active=False, type="timetable", timetables=[timetable_create]
|
|
||||||
)
|
|
||||||
assert aa_create.name == "New AA"
|
|
||||||
assert aa_create.is_active is False
|
|
||||||
assert len(aa_create.timetables) == 1
|
|
||||||
|
|
||||||
|
|
||||||
def test_card_model():
|
|
||||||
"""Test card model creation and validation."""
|
|
||||||
card = Card(key="test-key", group_id=1)
|
|
||||||
assert card.key == "test-key"
|
|
||||||
assert card.group_id == 1
|
|
||||||
|
|
||||||
|
|
||||||
def test_timetable_models():
|
|
||||||
"""Test timetable model creation and validation."""
|
|
||||||
# Test TimetableBase with valid values
|
|
||||||
timetable = TimetableCreate(weekday=1, starttime="09:00", duration=120)
|
|
||||||
assert timetable.weekday == 1
|
|
||||||
assert timetable.starttime == datetime.time(9, 0)
|
|
||||||
assert timetable.duration == 120
|
|
||||||
|
|
||||||
# Test boundary values
|
|
||||||
max_duration = TimetableCreate(weekday=6, starttime="23:59", duration=1439)
|
|
||||||
assert max_duration.duration == 1439
|
|
||||||
assert max_duration.weekday == 6
|
|
||||||
|
|
||||||
|
|
||||||
def test_token_models():
|
|
||||||
"""Test token model creation and validation."""
|
|
||||||
token = Token(access_token="test-token", token_type="bearer")
|
|
||||||
assert token.access_token == "test-token"
|
|
||||||
assert token.token_type == "bearer"
|
|
||||||
|
|
||||||
token_data = TokenData(username="testuser")
|
|
||||||
assert token_data.username == "testuser"
|
|
||||||
|
|
||||||
|
|
||||||
def test_aa_group_link_model():
|
|
||||||
"""Test many-to-many relationship link model."""
|
|
||||||
link = AaGroupLink(group_id=1, accessauth_id=2)
|
|
||||||
assert link.group_id == 1
|
|
||||||
assert link.accessauth_id == 2
|
|
||||||
@@ -1,226 +0,0 @@
|
|||||||
def test_create_access_auth_tt(client, auth_headers):
|
|
||||||
"""Test creating a new access authorization."""
|
|
||||||
aa_data = {
|
|
||||||
"name": "New tt_AA",
|
|
||||||
"type": "timetable",
|
|
||||||
"is_active": True,
|
|
||||||
"timetables": [
|
|
||||||
{"weekday": 1, "starttime": "08:00", "duration": 60},
|
|
||||||
{"weekday": 2, "starttime": "09:00", "duration": 90},
|
|
||||||
],
|
|
||||||
}
|
|
||||||
|
|
||||||
response = client.post("/api/v1/aa/", json=aa_data, headers=auth_headers)
|
|
||||||
assert response.status_code == 200
|
|
||||||
|
|
||||||
data = response.json()
|
|
||||||
assert data["name"] == "New tt_AA"
|
|
||||||
assert data["is_active"] is True
|
|
||||||
assert data["type"] == "timetable"
|
|
||||||
assert "id" in data
|
|
||||||
assert len(data["timetables"]) == 2
|
|
||||||
|
|
||||||
|
|
||||||
def test_create_access_auth_os(client, auth_headers):
|
|
||||||
"""Test creating a new access authorization with oneshot type."""
|
|
||||||
aa_data = {
|
|
||||||
"name": "New os_AA",
|
|
||||||
"type": "oneshot",
|
|
||||||
"is_active": True,
|
|
||||||
"oneshot": {"uses": 1, "ends_at": "2029-07-27"},
|
|
||||||
}
|
|
||||||
|
|
||||||
response = client.post("/api/v1/aa/", json=aa_data, headers=auth_headers)
|
|
||||||
assert response.status_code == 200
|
|
||||||
|
|
||||||
data = response.json()
|
|
||||||
assert data["name"] == "New os_AA"
|
|
||||||
assert data["type"] == "oneshot"
|
|
||||||
assert data["is_active"] is True
|
|
||||||
assert "id" in data
|
|
||||||
assert data["oneshot"]["uses"] == 1
|
|
||||||
|
|
||||||
|
|
||||||
def test_create_wrong_aa_type(client, auth_headers):
|
|
||||||
"""Test creating a new access authorization with oneshot type."""
|
|
||||||
aa_data = {
|
|
||||||
"name": "New AA",
|
|
||||||
"type": "wrong",
|
|
||||||
"is_active": True,
|
|
||||||
}
|
|
||||||
|
|
||||||
response = client.post("/api/v1/aa/", json=aa_data, headers=auth_headers)
|
|
||||||
assert response.status_code == 422
|
|
||||||
|
|
||||||
|
|
||||||
def test_get_all_access_auths(client, auth_headers, test_aa_tt):
|
|
||||||
"""Test retrieving all access authorizations."""
|
|
||||||
response = client.get("/api/v1/aa/", headers=auth_headers)
|
|
||||||
assert response.status_code == 200
|
|
||||||
|
|
||||||
aa_list = response.json()
|
|
||||||
assert len(aa_list) >= 1
|
|
||||||
|
|
||||||
aa_names = [aa["name"] for aa in aa_list]
|
|
||||||
assert test_aa_tt.name in aa_names
|
|
||||||
|
|
||||||
|
|
||||||
def test_get_access_auth_by_id(client, auth_headers, test_aa_tt):
|
|
||||||
"""Test retrieving a specific access authorization by ID."""
|
|
||||||
response = client.get(f"/api/v1/aa/{test_aa_tt.id}", headers=auth_headers)
|
|
||||||
assert response.status_code == 200
|
|
||||||
|
|
||||||
data = response.json()
|
|
||||||
assert data["id"] == test_aa_tt.id
|
|
||||||
assert data["name"] == test_aa_tt.name
|
|
||||||
|
|
||||||
|
|
||||||
def test_get_nonexistent_access_auth(client, auth_headers):
|
|
||||||
"""Test retrieving a non-existent access authorization."""
|
|
||||||
response = client.get("/api/v1/aa/99999", headers=auth_headers)
|
|
||||||
assert response.status_code == 404
|
|
||||||
|
|
||||||
|
|
||||||
def test_assign_access_auth_to_group(client, auth_headers, test_group, test_aa_tt):
|
|
||||||
"""Test assigning an access authorization to a group."""
|
|
||||||
response = client.put(
|
|
||||||
f"/api/v1/aa/assign/{test_group.id}/{test_aa_tt.id}", headers=auth_headers
|
|
||||||
)
|
|
||||||
assert response.status_code == 200
|
|
||||||
|
|
||||||
data = response.json()
|
|
||||||
assert data["id"] == test_group.id
|
|
||||||
# The AA should now be in the group's accessauths
|
|
||||||
# Note: The response model might not include the full relationship
|
|
||||||
|
|
||||||
|
|
||||||
def test_assign_already_assigned_access_auth(
|
|
||||||
client, auth_headers, test_group, test_aa_tt
|
|
||||||
):
|
|
||||||
"""Test assigning an already assigned access authorization."""
|
|
||||||
# First assignment
|
|
||||||
client.put(
|
|
||||||
f"/api/v1/aa/assign/{test_group.id}/{test_aa_tt.id}", headers=auth_headers
|
|
||||||
)
|
|
||||||
|
|
||||||
# Second assignment should indicate it's already assigned
|
|
||||||
response = client.put(
|
|
||||||
f"/api/v1/aa/assign/{test_group.id}/{test_aa_tt.id}", headers=auth_headers
|
|
||||||
)
|
|
||||||
# According to the code, this returns 409 with "already assigned" message
|
|
||||||
assert response.status_code == 409
|
|
||||||
assert "already assigned" in response.json()["detail"].lower()
|
|
||||||
|
|
||||||
|
|
||||||
def test_unassign_access_auth_from_group(client, auth_headers, test_group, test_aa_tt):
|
|
||||||
"""Test unassigning an access authorization from a group."""
|
|
||||||
# First assign
|
|
||||||
client.put(
|
|
||||||
f"/api/v1/aa/assign/{test_group.id}/{test_aa_tt.id}", headers=auth_headers
|
|
||||||
)
|
|
||||||
|
|
||||||
# Then unassign
|
|
||||||
response = client.put(
|
|
||||||
f"/api/v1/aa/unassign/{test_group.id}/{test_aa_tt.id}", headers=auth_headers
|
|
||||||
)
|
|
||||||
assert response.status_code == 200
|
|
||||||
|
|
||||||
|
|
||||||
def test_unassign_nonexistent_assignment(client, auth_headers, test_group, test_aa_tt):
|
|
||||||
"""Test unassigning a non-existent assignment."""
|
|
||||||
response = client.put(
|
|
||||||
f"/api/v1/aa/unassign/{test_group.id}/{test_aa_tt.id}", headers=auth_headers
|
|
||||||
)
|
|
||||||
assert response.status_code == 404
|
|
||||||
|
|
||||||
|
|
||||||
def test_assign_to_nonexistent_group(client, auth_headers, test_aa_tt):
|
|
||||||
"""Test assigning an AA to a non-existent group."""
|
|
||||||
response = client.put(
|
|
||||||
f"/api/v1/aa/assign/99999/{test_aa_tt.id}", headers=auth_headers
|
|
||||||
)
|
|
||||||
assert response.status_code == 404
|
|
||||||
|
|
||||||
|
|
||||||
def test_assign_nonexistent_aa(client, auth_headers, test_group):
|
|
||||||
"""Test assigning a non-existent AA to a group."""
|
|
||||||
response = client.put(
|
|
||||||
f"/api/v1/aa/assign/{test_group.id}/99999", headers=auth_headers
|
|
||||||
)
|
|
||||||
assert response.status_code == 404
|
|
||||||
|
|
||||||
|
|
||||||
def test_update_access_auth(client, auth_headers, test_aa_tt):
|
|
||||||
"""Test updating an access authorization."""
|
|
||||||
update_data = {"name": "Updated AA", "is_active": False}
|
|
||||||
|
|
||||||
response = client.patch(
|
|
||||||
f"/api/v1/aa/{test_aa_tt.id}", json=update_data, headers=auth_headers
|
|
||||||
)
|
|
||||||
assert response.status_code == 200
|
|
||||||
|
|
||||||
data = response.json()
|
|
||||||
assert data["name"] == "Updated AA"
|
|
||||||
assert data["is_active"] is False
|
|
||||||
|
|
||||||
|
|
||||||
def test_update_access_auth_with_timetables(client, auth_headers, test_aa_tt):
|
|
||||||
"""Test updating an access authorization with new timetables."""
|
|
||||||
update_data = {
|
|
||||||
"timetables": [{"weekday": 5, "starttime": "10:00", "duration": 120}]
|
|
||||||
}
|
|
||||||
|
|
||||||
response = client.patch(
|
|
||||||
f"/api/v1/aa/{test_aa_tt.id}", json=update_data, headers=auth_headers
|
|
||||||
)
|
|
||||||
assert response.status_code == 200
|
|
||||||
jresponse = response.json()
|
|
||||||
assert len(jresponse["timetables"]) == 1
|
|
||||||
assert jresponse["timetables"][0]["weekday"] == 5
|
|
||||||
assert jresponse["timetables"][0]["starttime"] == "10:00:00"
|
|
||||||
assert jresponse["timetables"][0]["duration"] == 120
|
|
||||||
|
|
||||||
|
|
||||||
def test_update_nonexistent_access_auth(client, auth_headers):
|
|
||||||
"""Test updating a non-existent access authorization."""
|
|
||||||
update_data = {"name": "Updated"}
|
|
||||||
response = client.patch("/api/v1/aa/99999", json=update_data, headers=auth_headers)
|
|
||||||
assert response.status_code == 404
|
|
||||||
|
|
||||||
|
|
||||||
def test_delete_access_auth(client, auth_headers, test_aa_tt):
|
|
||||||
"""Test deleting an access authorization."""
|
|
||||||
response = client.delete(f"/api/v1/aa/{test_aa_tt.id}", headers=auth_headers)
|
|
||||||
assert response.status_code == 200
|
|
||||||
assert "deleted successfully" in response.json()["message"].lower()
|
|
||||||
|
|
||||||
# Verify AA is deleted
|
|
||||||
response = client.get(f"/api/v1/aa/{test_aa_tt.id}", headers=auth_headers)
|
|
||||||
assert response.status_code == 404
|
|
||||||
|
|
||||||
|
|
||||||
def test_delete_nonexistent_access_auth(client, auth_headers):
|
|
||||||
"""Test deleting a non-existent access authorization."""
|
|
||||||
response = client.delete("/api/v1/aa/99999", headers=auth_headers)
|
|
||||||
assert response.status_code == 404
|
|
||||||
|
|
||||||
|
|
||||||
def test_aa_tt_operations_by_non_admin(client, test_aa_tt, user_auth_headers):
|
|
||||||
"""Test that non-admin users cannot perform AA operations."""
|
|
||||||
# Try to create an AA
|
|
||||||
response = client.post(
|
|
||||||
"/api/v1/aa/",
|
|
||||||
json={"name": "test", "is_active": True, "timetables": []},
|
|
||||||
headers=user_auth_headers,
|
|
||||||
)
|
|
||||||
assert response.status_code == 403
|
|
||||||
|
|
||||||
# Try to get all AAs
|
|
||||||
response = client.get("/api/v1/aa/", headers=user_auth_headers)
|
|
||||||
assert response.status_code == 403
|
|
||||||
|
|
||||||
# Try to assign AA
|
|
||||||
response = client.put(
|
|
||||||
f"/api/v1/aa/assign/1/{test_aa_tt.id}", headers=user_auth_headers
|
|
||||||
)
|
|
||||||
assert response.status_code == 403
|
|
||||||
@@ -1,202 +0,0 @@
|
|||||||
from datetime import timedelta
|
|
||||||
|
|
||||||
import pytest
|
|
||||||
from fastapi import HTTPException, status
|
|
||||||
|
|
||||||
from app.model.models import UserDB
|
|
||||||
from app.services.auth import (
|
|
||||||
auth_is_admin,
|
|
||||||
authenticate_user,
|
|
||||||
create_access_token,
|
|
||||||
create_first_user,
|
|
||||||
get_current_user,
|
|
||||||
get_password_hash,
|
|
||||||
get_user,
|
|
||||||
verify_password,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_password_hashing():
|
|
||||||
"""Test password hashing and verification."""
|
|
||||||
password = "test_password_123"
|
|
||||||
|
|
||||||
# Hash password
|
|
||||||
hashed = get_password_hash(password)
|
|
||||||
assert hashed != password
|
|
||||||
assert len(hashed) > 0
|
|
||||||
|
|
||||||
# Verify correct password
|
|
||||||
assert verify_password(password, hashed) is True
|
|
||||||
|
|
||||||
# Verify incorrect password
|
|
||||||
assert verify_password("wrong_password", hashed) is False
|
|
||||||
|
|
||||||
|
|
||||||
def test_get_user(db_session):
|
|
||||||
"""Test get_user function."""
|
|
||||||
from app.services.auth import get_password_hash
|
|
||||||
|
|
||||||
# Create a user
|
|
||||||
user = UserDB(name="testuser", passwordhash=get_password_hash("password"))
|
|
||||||
db_session.add(user)
|
|
||||||
db_session.commit()
|
|
||||||
|
|
||||||
# Get existing user
|
|
||||||
retrieved_user = get_user(db_session, "testuser")
|
|
||||||
assert retrieved_user is not None
|
|
||||||
assert retrieved_user.name == "testuser"
|
|
||||||
|
|
||||||
# Try to get non-existent user
|
|
||||||
retrieved_user = get_user(db_session, "nonexistent")
|
|
||||||
assert retrieved_user is None
|
|
||||||
|
|
||||||
|
|
||||||
def test_authenticate_user(db_session):
|
|
||||||
"""Test user authentication."""
|
|
||||||
from app.services.auth import get_password_hash
|
|
||||||
|
|
||||||
# Create a user
|
|
||||||
user = UserDB(name="authuser", passwordhash=get_password_hash("correctpass"))
|
|
||||||
db_session.add(user)
|
|
||||||
db_session.commit()
|
|
||||||
|
|
||||||
# Authenticate with correct credentials
|
|
||||||
authenticated = authenticate_user(db_session, "authuser", "correctpass")
|
|
||||||
assert authenticated is not False
|
|
||||||
assert authenticated.name == "authuser"
|
|
||||||
|
|
||||||
# Authenticate with wrong password
|
|
||||||
authenticated = authenticate_user(db_session, "authuser", "wrongpass")
|
|
||||||
assert authenticated is False
|
|
||||||
|
|
||||||
# Authenticate non-existent user
|
|
||||||
authenticated = authenticate_user(db_session, "nonexistent", "password")
|
|
||||||
assert authenticated is False
|
|
||||||
|
|
||||||
|
|
||||||
def test_create_access_token():
|
|
||||||
"""Test JWT token creation."""
|
|
||||||
data = {"sub": "testuser"}
|
|
||||||
|
|
||||||
# Create token with default expiration
|
|
||||||
token = create_access_token(data)
|
|
||||||
assert isinstance(token, str)
|
|
||||||
assert len(token) > 0
|
|
||||||
|
|
||||||
# Create token with custom expiration
|
|
||||||
custom_expire = timedelta(hours=1)
|
|
||||||
token = create_access_token(data, expires_delta=custom_expire)
|
|
||||||
assert isinstance(token, str)
|
|
||||||
|
|
||||||
|
|
||||||
def test_get_current_user(db_session, admin_user):
|
|
||||||
"""Test getting current user from token."""
|
|
||||||
from app.services.auth import create_access_token
|
|
||||||
|
|
||||||
# Create token for admin user
|
|
||||||
token = create_access_token(data={"sub": admin_user.name})
|
|
||||||
|
|
||||||
# Get user from token
|
|
||||||
user = get_current_user(token=token, db=db_session)
|
|
||||||
assert user is not None
|
|
||||||
assert user.name == admin_user.name
|
|
||||||
assert user.id == admin_user.id
|
|
||||||
|
|
||||||
# Test invalid token
|
|
||||||
with pytest.raises(HTTPException) as exc_info:
|
|
||||||
get_current_user(token="invalid_token")
|
|
||||||
assert exc_info.value.status_code == status.HTTP_401_UNAUTHORIZED
|
|
||||||
|
|
||||||
# Test expired token (create token with past expiration)
|
|
||||||
past_expire = timedelta(minutes=-100)
|
|
||||||
expired_token = create_access_token(
|
|
||||||
data={"sub": admin_user.name}, expires_delta=past_expire
|
|
||||||
)
|
|
||||||
|
|
||||||
with pytest.raises(HTTPException) as exc_info:
|
|
||||||
get_current_user(token=expired_token)
|
|
||||||
assert exc_info.value.status_code == status.HTTP_401_UNAUTHORIZED
|
|
||||||
|
|
||||||
|
|
||||||
def test_auth_is_admin(db_session, admin_user, regular_user):
|
|
||||||
"""Test admin authorization check."""
|
|
||||||
from app.services.auth import create_access_token
|
|
||||||
|
|
||||||
# Create token for admin user
|
|
||||||
admin_token = create_access_token(data={"sub": admin_user.name})
|
|
||||||
|
|
||||||
# Admin should pass
|
|
||||||
result = auth_is_admin(token=admin_token, db=db_session)
|
|
||||||
assert result is True
|
|
||||||
|
|
||||||
# Create token for regular user
|
|
||||||
user_token = create_access_token(data={"sub": regular_user.name})
|
|
||||||
|
|
||||||
# Regular user should fail
|
|
||||||
with pytest.raises(HTTPException) as exc_info:
|
|
||||||
auth_is_admin(token=user_token, db=db_session)
|
|
||||||
assert exc_info.value.status_code == status.HTTP_403_FORBIDDEN
|
|
||||||
|
|
||||||
|
|
||||||
def test_create_first_user(db_session):
|
|
||||||
"""Test automatic creation of first admin user."""
|
|
||||||
# Clear any existing users
|
|
||||||
from sqlmodel import select
|
|
||||||
|
|
||||||
db_session.exec(select(UserDB)).all()
|
|
||||||
for user in db_session.exec(select(UserDB)).all():
|
|
||||||
db_session.delete(user)
|
|
||||||
db_session.commit()
|
|
||||||
|
|
||||||
# Create first user
|
|
||||||
result = create_first_user(db=db_session)
|
|
||||||
assert result is not None
|
|
||||||
assert result.name == "admin"
|
|
||||||
assert result.is_admin is True
|
|
||||||
|
|
||||||
# Verify user exists in database
|
|
||||||
user = db_session.exec(select(UserDB).where(UserDB.name == "admin")).first()
|
|
||||||
assert user is not None
|
|
||||||
assert user.is_admin is True
|
|
||||||
|
|
||||||
# Test that it doesn't create another admin if one exists
|
|
||||||
second_result = create_first_user(db=db_session)
|
|
||||||
assert second_result is None # Should print "Admin user already exists"
|
|
||||||
|
|
||||||
|
|
||||||
def test_token_endpoint(client, admin_user):
|
|
||||||
"""Test the token endpoint for login."""
|
|
||||||
# Test successful login
|
|
||||||
response = client.post(
|
|
||||||
"/api/v1/token", data={"username": admin_user.name, "password": "admin123"}
|
|
||||||
)
|
|
||||||
assert response.status_code == 200
|
|
||||||
data = response.json()
|
|
||||||
assert "access_token" in data
|
|
||||||
assert data["token_type"] == "bearer"
|
|
||||||
|
|
||||||
# Test failed login with wrong password
|
|
||||||
response = client.post(
|
|
||||||
"/api/v1/token", data={"username": admin_user.name, "password": "wrongpassword"}
|
|
||||||
)
|
|
||||||
assert response.status_code == 401
|
|
||||||
|
|
||||||
# Test failed login with non-existent user
|
|
||||||
response = client.post(
|
|
||||||
"/api/v1/token", data={"username": "nonexistent", "password": "password"}
|
|
||||||
)
|
|
||||||
assert response.status_code == 401
|
|
||||||
|
|
||||||
|
|
||||||
def test_test_login_endpoint(client, admin_user, auth_headers):
|
|
||||||
"""Test the test login endpoint."""
|
|
||||||
# Test with valid token
|
|
||||||
response = client.get("/api/v1/test/login", headers=auth_headers)
|
|
||||||
assert response.status_code == 200
|
|
||||||
data = response.json()
|
|
||||||
assert data["name"] == admin_user.name
|
|
||||||
assert data["is_admin"] is True
|
|
||||||
|
|
||||||
# Test without token
|
|
||||||
response = client.get("/api/v1/test/login")
|
|
||||||
assert response.status_code == 401
|
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
def test_get_cards_for_group(client, auth_headers, test_group, test_card):
|
|
||||||
"""Test getting all cards for a group."""
|
|
||||||
response = client.get(f"/api/v1/cards/{test_group.id}", headers=auth_headers)
|
|
||||||
assert response.status_code == 200
|
|
||||||
|
|
||||||
cards = response.json()
|
|
||||||
assert len(cards) >= 1
|
|
||||||
assert any(card["id"] == test_card.id for card in cards)
|
|
||||||
|
|
||||||
|
|
||||||
def test_get_cards_for_nonexistent_group(client, auth_headers):
|
|
||||||
"""Test getting cards for a non-existent group."""
|
|
||||||
response = client.get("/api/v1/cards/99999", headers=auth_headers)
|
|
||||||
assert response.status_code == 200
|
|
||||||
|
|
||||||
cards = response.json()
|
|
||||||
assert len(cards) == 0 # Empty list for non-existent group
|
|
||||||
|
|
||||||
|
|
||||||
def test_card_operations_by_non_admin(client, test_group, user_auth_headers):
|
|
||||||
"""Test that non-admin users cannot perform card operations."""
|
|
||||||
# Try to add a card
|
|
||||||
response = client.post("/api/v1/cards/", headers=user_auth_headers)
|
|
||||||
assert response.status_code == 403
|
|
||||||
|
|
||||||
# Try to get cards
|
|
||||||
response = client.get(f"/api/v1/cards/{test_group.id}", headers=user_auth_headers)
|
|
||||||
assert response.status_code == 403
|
|
||||||
|
|
||||||
|
|
||||||
def test_update_card(client, auth_headers, test_group, test_card):
|
|
||||||
"""Test Patching a card entity"""
|
|
||||||
update_data = {"name": "changed_name", "enabled": "False"}
|
|
||||||
|
|
||||||
response = client.patch(
|
|
||||||
f"/api/v1/cards/{test_card.id}", json=update_data, headers=auth_headers
|
|
||||||
)
|
|
||||||
assert response.status_code == 200
|
|
||||||
|
|
||||||
data = response.json()
|
|
||||||
assert data["name"] == "changed_name"
|
|
||||||
assert data["enabled"] == False # noqa: E712
|
|
||||||
assert data["group_id"] == test_card.group_id
|
|
||||||
|
|
||||||
|
|
||||||
def test_update_wrong_card(client, auth_headers, test_group, test_card):
|
|
||||||
"""Test Patching a card entity"""
|
|
||||||
|
|
||||||
response = client.patch("/api/v1/cards/9999", json={}, headers=auth_headers)
|
|
||||||
assert response.status_code == 404
|
|
||||||
assert "Card not found" in response.json()["detail"]
|
|
||||||
|
|
||||||
|
|
||||||
def test_update_card_with_wrong_group(client, auth_headers, test_group, test_card):
|
|
||||||
"""Test Patching a card entity with wrong group"""
|
|
||||||
update_data = {"group_id": "9999"}
|
|
||||||
|
|
||||||
response = client.patch(
|
|
||||||
f"/api/v1/cards/{test_card.id}", json=update_data, headers=auth_headers
|
|
||||||
)
|
|
||||||
assert response.status_code == 404
|
|
||||||
assert "GroupID not found" in response.json()["detail"]
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
from sqlmodel import Session
|
|
||||||
|
|
||||||
from app.model.models import UserDB
|
|
||||||
from app.services.database import add_and_refresh, create_db_and_tables
|
|
||||||
|
|
||||||
|
|
||||||
def test_create_db_and_tables():
|
|
||||||
"""Test database and tables creation."""
|
|
||||||
# This is primarily an integration test
|
|
||||||
from sqlalchemy import inspect
|
|
||||||
|
|
||||||
from app.services.database import get_engine
|
|
||||||
|
|
||||||
create_db_and_tables()
|
|
||||||
inspector = inspect(get_engine())
|
|
||||||
|
|
||||||
# Check that tables exist
|
|
||||||
tables = inspector.get_table_names()
|
|
||||||
assert "userdb" in tables
|
|
||||||
assert "groupdb" in tables
|
|
||||||
assert "card" in tables
|
|
||||||
assert "accessauthorizationdb" in tables
|
|
||||||
assert "timetable" in tables
|
|
||||||
assert "aagrouplink" in tables
|
|
||||||
|
|
||||||
|
|
||||||
def test_get_session(db_session):
|
|
||||||
"""Test database session generator."""
|
|
||||||
# Test that we can get a session
|
|
||||||
assert isinstance(db_session, Session)
|
|
||||||
|
|
||||||
# Test that session works
|
|
||||||
user = UserDB(name="Test_User", passwordhash="hash")
|
|
||||||
db_session.add(user)
|
|
||||||
db_session.commit()
|
|
||||||
|
|
||||||
retrieved_user = db_session.get(UserDB, user.id)
|
|
||||||
assert retrieved_user is not None
|
|
||||||
assert retrieved_user.name == "Test_User"
|
|
||||||
|
|
||||||
|
|
||||||
def test_add_and_refresh(db_session):
|
|
||||||
"""Test add_and_refresh helper function."""
|
|
||||||
user = UserDB(name="Test User", passwordhash="hashed")
|
|
||||||
|
|
||||||
# Add user
|
|
||||||
result = add_and_refresh(db_session, user)
|
|
||||||
|
|
||||||
# Assert that user is now in database with ID
|
|
||||||
assert result.id is not None
|
|
||||||
assert result.name == "Test User"
|
|
||||||
|
|
||||||
# Verify in database
|
|
||||||
db_user = db_session.get(UserDB, result.id)
|
|
||||||
assert db_user is not None
|
|
||||||
assert db_user.name == "Test User"
|
|
||||||
@@ -1,219 +0,0 @@
|
|||||||
import datetime
|
|
||||||
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
from app.model.models import (
|
|
||||||
AccessAuthorizationDB,
|
|
||||||
Card,
|
|
||||||
GroupDB,
|
|
||||||
OneShotAccess,
|
|
||||||
Timetable,
|
|
||||||
)
|
|
||||||
from app.services.door import checkAccess
|
|
||||||
|
|
||||||
|
|
||||||
def test_check_access_with_valid_timetable(db_session):
|
|
||||||
# Setup: create card with valid access
|
|
||||||
group = GroupDB(name="Test Group")
|
|
||||||
db_session.add(group)
|
|
||||||
db_session.commit()
|
|
||||||
|
|
||||||
card = Card(
|
|
||||||
key="test-key-123",
|
|
||||||
group_id=group.id,
|
|
||||||
enabled=True,
|
|
||||||
name="test_card",
|
|
||||||
card_serial="00:00:00:00:00:00:00",
|
|
||||||
)
|
|
||||||
db_session.add(card)
|
|
||||||
|
|
||||||
timetable = Timetable(
|
|
||||||
weekday=datetime.datetime.weekday(datetime.date.today()),
|
|
||||||
starttime=datetime.datetime.now().time(),
|
|
||||||
duration=120, # 2 hours
|
|
||||||
)
|
|
||||||
db_session.add(timetable)
|
|
||||||
|
|
||||||
aa = AccessAuthorizationDB(name="Test AA", is_active=True, type="timetable")
|
|
||||||
db_session.add(aa)
|
|
||||||
aa.timetables = [timetable]
|
|
||||||
group.accessauths = [aa]
|
|
||||||
|
|
||||||
db_session.commit()
|
|
||||||
|
|
||||||
# Test: access should be granted within time window
|
|
||||||
assert checkAccess("test-key-123", db_session)
|
|
||||||
|
|
||||||
|
|
||||||
def test_check_access_outside_hours(db_session):
|
|
||||||
# Test when current time is outside valid hours
|
|
||||||
group = GroupDB(name="Test Group")
|
|
||||||
db_session.add(group)
|
|
||||||
db_session.commit()
|
|
||||||
|
|
||||||
card = Card(
|
|
||||||
key="test-key-123",
|
|
||||||
group_id=group.id,
|
|
||||||
enabled=True,
|
|
||||||
name="test_card",
|
|
||||||
card_serial="00:00:00:00:00:00:00",
|
|
||||||
)
|
|
||||||
db_session.add(card)
|
|
||||||
|
|
||||||
timetable = Timetable(
|
|
||||||
weekday=datetime.datetime.weekday(datetime.date.today()),
|
|
||||||
starttime=datetime.time(1, 0),
|
|
||||||
duration=1, # 2 hours
|
|
||||||
)
|
|
||||||
db_session.add(timetable)
|
|
||||||
|
|
||||||
aa = AccessAuthorizationDB(name="Test AA", is_active=True, type="timetable")
|
|
||||||
db_session.add(aa)
|
|
||||||
aa.timetables = [timetable]
|
|
||||||
group.accessauths = [aa]
|
|
||||||
|
|
||||||
db_session.commit()
|
|
||||||
assert not checkAccess("test-key-123", db_session)
|
|
||||||
|
|
||||||
|
|
||||||
def test_check_access_with_valid_oneshot(db_session):
|
|
||||||
# Setup: create card with valid access
|
|
||||||
group = GroupDB(name="Test Group")
|
|
||||||
db_session.add(group)
|
|
||||||
db_session.commit()
|
|
||||||
|
|
||||||
card = Card(
|
|
||||||
key="test-key-123",
|
|
||||||
group_id=group.id,
|
|
||||||
enabled=True,
|
|
||||||
name="test_card",
|
|
||||||
card_serial="00:00:00:00:00:00:00",
|
|
||||||
)
|
|
||||||
db_session.add(card)
|
|
||||||
|
|
||||||
oneshot = OneShotAccess(
|
|
||||||
uses=1, ends_at=datetime.datetime.now() + datetime.timedelta(days=1)
|
|
||||||
)
|
|
||||||
db_session.add(oneshot)
|
|
||||||
|
|
||||||
aa = AccessAuthorizationDB(name="Test AA", is_active=True, type="oneshot")
|
|
||||||
db_session.add(aa)
|
|
||||||
aa.oneshot = oneshot
|
|
||||||
group.accessauths = [aa]
|
|
||||||
|
|
||||||
db_session.commit()
|
|
||||||
|
|
||||||
# Test: access should be granted within time window
|
|
||||||
assert checkAccess("test-key-123", db_session)
|
|
||||||
assert aa.oneshot.uses == 0
|
|
||||||
|
|
||||||
|
|
||||||
def test_check_access_invalid_card(db_session):
|
|
||||||
# Should raise exception for non-existent card
|
|
||||||
with pytest.raises(Exception):
|
|
||||||
checkAccess("non-existent-key", db_session)
|
|
||||||
|
|
||||||
def test_check_access_with_inactive_aa(db_session):
|
|
||||||
# Setup: create card with valid access
|
|
||||||
group = GroupDB(name="Test Group")
|
|
||||||
db_session.add(group)
|
|
||||||
db_session.commit()
|
|
||||||
|
|
||||||
card = Card(
|
|
||||||
key="test-key-123",
|
|
||||||
group_id=group.id,
|
|
||||||
enabled=True,
|
|
||||||
name="test_card",
|
|
||||||
card_serial="00:00:00:00:00:00:00",
|
|
||||||
)
|
|
||||||
db_session.add(card)
|
|
||||||
|
|
||||||
timetable = Timetable(
|
|
||||||
weekday=datetime.datetime.weekday(datetime.date.today()),
|
|
||||||
starttime=datetime.datetime.now().time(),
|
|
||||||
duration=120, # 2 hours
|
|
||||||
)
|
|
||||||
db_session.add(timetable)
|
|
||||||
|
|
||||||
aa = AccessAuthorizationDB(name="Test AA", is_active=False, type="timetable")
|
|
||||||
db_session.add(aa)
|
|
||||||
aa.timetables = [timetable]
|
|
||||||
group.accessauths = [aa]
|
|
||||||
|
|
||||||
db_session.commit()
|
|
||||||
|
|
||||||
assert checkAccess("test-key-123", db_session) == False
|
|
||||||
|
|
||||||
def test_check_access_with_inactive_card(db_session):
|
|
||||||
# Setup: create card with valid access
|
|
||||||
group = GroupDB(name="Test Group")
|
|
||||||
db_session.add(group)
|
|
||||||
db_session.commit()
|
|
||||||
|
|
||||||
card = Card(
|
|
||||||
key="test-key-123",
|
|
||||||
group_id=group.id,
|
|
||||||
enabled=False,
|
|
||||||
name="test_card",
|
|
||||||
card_serial="00:00:00:00:00:00:00",
|
|
||||||
)
|
|
||||||
db_session.add(card)
|
|
||||||
|
|
||||||
timetable = Timetable(
|
|
||||||
weekday=datetime.datetime.weekday(datetime.date.today()),
|
|
||||||
starttime=datetime.datetime.now().time(),
|
|
||||||
duration=120, # 2 hours
|
|
||||||
)
|
|
||||||
db_session.add(timetable)
|
|
||||||
|
|
||||||
aa = AccessAuthorizationDB(name="Test AA", is_active=True, type="timetable")
|
|
||||||
db_session.add(aa)
|
|
||||||
aa.timetables = [timetable]
|
|
||||||
group.accessauths = [aa]
|
|
||||||
|
|
||||||
db_session.commit()
|
|
||||||
|
|
||||||
assert checkAccess("test-key-123", db_session) == False
|
|
||||||
|
|
||||||
def test_regression_check_access_issue_28(db_session):
|
|
||||||
# Having a active aa after a inactive/invalid one denies access
|
|
||||||
group = GroupDB(name="Test Group")
|
|
||||||
db_session.add(group)
|
|
||||||
db_session.commit()
|
|
||||||
|
|
||||||
card = Card(
|
|
||||||
key="test-key-123",
|
|
||||||
group_id=group.id,
|
|
||||||
enabled=True,
|
|
||||||
name="test_card",
|
|
||||||
card_serial="00:00:00:00:00:00:00",
|
|
||||||
)
|
|
||||||
db_session.add(card)
|
|
||||||
|
|
||||||
#Creating timetable with inactive AA
|
|
||||||
timetable1 = Timetable(
|
|
||||||
weekday=datetime.datetime.weekday(datetime.date.today()),
|
|
||||||
starttime=datetime.datetime.now().time(),
|
|
||||||
duration=120, # 2 hours
|
|
||||||
)
|
|
||||||
db_session.add(timetable1)
|
|
||||||
aa1 = AccessAuthorizationDB(name="First AA", is_active=False, type="timetable")
|
|
||||||
db_session.add(aa1)
|
|
||||||
aa1.timetables = [timetable1]
|
|
||||||
|
|
||||||
#Creating timetable with active AA
|
|
||||||
timetable2 = Timetable(
|
|
||||||
weekday=datetime.datetime.weekday(datetime.date.today()),
|
|
||||||
starttime=datetime.datetime.now().time(),
|
|
||||||
duration=120, # 2 hours
|
|
||||||
)
|
|
||||||
db_session.add(timetable2)
|
|
||||||
aa2 = AccessAuthorizationDB(name="Second AA", is_active=True, type="timetable")
|
|
||||||
db_session.add(aa2)
|
|
||||||
aa2.timetables = [timetable2]
|
|
||||||
|
|
||||||
group.accessauths = [aa1, aa2]
|
|
||||||
|
|
||||||
db_session.commit()
|
|
||||||
|
|
||||||
assert checkAccess("test-key-123", db_session) == True
|
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
def test_create_group(client, auth_headers):
|
|
||||||
"""Test creating a new group."""
|
|
||||||
group_data = {"name": "New Test Group"}
|
|
||||||
|
|
||||||
response = client.post("/api/v1/groups/", json=group_data, headers=auth_headers)
|
|
||||||
assert response.status_code == 200
|
|
||||||
|
|
||||||
data = response.json()
|
|
||||||
assert data["name"] == "New Test Group"
|
|
||||||
assert "id" in data
|
|
||||||
|
|
||||||
|
|
||||||
def test_create_duplicate_group(client, auth_headers, test_group):
|
|
||||||
"""Test creating a group with a duplicate name."""
|
|
||||||
group_data = {"name": test_group.name}
|
|
||||||
|
|
||||||
response = client.post("/api/v1/groups/", json=group_data, headers=auth_headers)
|
|
||||||
# This should fail due to unique constraint
|
|
||||||
assert response.status_code == 409 # Validation error
|
|
||||||
|
|
||||||
|
|
||||||
def test_get_groups(client, auth_headers, test_group):
|
|
||||||
"""Test retrieving all groups."""
|
|
||||||
response = client.get("/api/v1/groups/", headers=auth_headers)
|
|
||||||
assert response.status_code == 200
|
|
||||||
|
|
||||||
groups = response.json()
|
|
||||||
assert len(groups) >= 1
|
|
||||||
|
|
||||||
group_names = [group["name"] for group in groups]
|
|
||||||
assert test_group.name in group_names
|
|
||||||
|
|
||||||
|
|
||||||
def test_delete_group(client, auth_headers, test_group):
|
|
||||||
"""Test deleting a group."""
|
|
||||||
response = client.delete(f"/api/v1/groups/{test_group.id}", headers=auth_headers)
|
|
||||||
assert response.status_code == 200
|
|
||||||
assert "deleted successfully" in response.json()["message"].lower()
|
|
||||||
|
|
||||||
# Verify group is deleted
|
|
||||||
response = client.get("/api/v1/groups/", headers=auth_headers)
|
|
||||||
groups = response.json()
|
|
||||||
assert not any(group["id"] == test_group.id for group in groups)
|
|
||||||
|
|
||||||
|
|
||||||
def test_delete_nonexistent_group(client, auth_headers):
|
|
||||||
"""Test deleting a non-existent group."""
|
|
||||||
response = client.delete("/api/v1/groups/99999", headers=auth_headers)
|
|
||||||
assert response.status_code == 404
|
|
||||||
|
|
||||||
|
|
||||||
def test_group_operations_by_non_admin(client, user_auth_headers):
|
|
||||||
"""Test that non-admin users cannot perform group operations."""
|
|
||||||
# Try to create a group
|
|
||||||
response = client.post(
|
|
||||||
"/api/v1/groups/", json={"name": "test"}, headers=user_auth_headers
|
|
||||||
)
|
|
||||||
assert response.status_code == 403
|
|
||||||
|
|
||||||
# Try to get groups
|
|
||||||
response = client.get("/api/v1/groups/", headers=user_auth_headers)
|
|
||||||
assert response.status_code == 403
|
|
||||||
@@ -1,150 +0,0 @@
|
|||||||
def test_create_user(client, auth_headers):
|
|
||||||
"""Test creating a new user."""
|
|
||||||
user_data = {
|
|
||||||
"name": "newuser",
|
|
||||||
"email": "newuser@example.com",
|
|
||||||
"is_admin": False,
|
|
||||||
"password": "newpassword123",
|
|
||||||
}
|
|
||||||
|
|
||||||
response = client.post("/api/v1/users/", json=user_data, headers=auth_headers)
|
|
||||||
assert response.status_code == 200
|
|
||||||
|
|
||||||
data = response.json()
|
|
||||||
assert data["name"] == "newuser"
|
|
||||||
assert data["email"] == "newuser@example.com"
|
|
||||||
assert data["is_admin"] is False
|
|
||||||
assert "id" in data
|
|
||||||
assert "passwordhash" not in data # Password hash should not be in response
|
|
||||||
|
|
||||||
|
|
||||||
def test_create_user_unauthorized(client):
|
|
||||||
"""Test creating a user without admin credentials."""
|
|
||||||
user_data = {
|
|
||||||
"name": "unauthorized_user",
|
|
||||||
"email": "unauthorized@example.com",
|
|
||||||
"password": "password123",
|
|
||||||
}
|
|
||||||
|
|
||||||
response = client.post("/api/v1/users/", json=user_data)
|
|
||||||
assert response.status_code == 401
|
|
||||||
|
|
||||||
|
|
||||||
def test_get_users(client, auth_headers, admin_user, regular_user):
|
|
||||||
"""Test retrieving all users."""
|
|
||||||
response = client.get("/api/v1/users/", headers=auth_headers)
|
|
||||||
assert response.status_code == 200
|
|
||||||
|
|
||||||
users = response.json()
|
|
||||||
assert len(users) >= 2 # At least admin_user and regular_user
|
|
||||||
|
|
||||||
user_names = [user["name"] for user in users]
|
|
||||||
assert admin_user.name in user_names
|
|
||||||
assert regular_user.name in user_names
|
|
||||||
|
|
||||||
|
|
||||||
def test_get_user_by_id(client, auth_headers, regular_user):
|
|
||||||
"""Test retrieving a specific user by ID."""
|
|
||||||
response = client.get(f"/api/v1/users/{regular_user.id}", headers=auth_headers)
|
|
||||||
assert response.status_code == 200
|
|
||||||
|
|
||||||
data = response.json()
|
|
||||||
assert data["id"] == regular_user.id
|
|
||||||
assert data["name"] == regular_user.name
|
|
||||||
|
|
||||||
|
|
||||||
def test_get_current_user(client, auth_headers, admin_user):
|
|
||||||
"""Test getting the special url current"""
|
|
||||||
response = client.get("/api/v1/users/current", headers=auth_headers)
|
|
||||||
assert response.status_code == 200
|
|
||||||
|
|
||||||
data = response.json()
|
|
||||||
assert data["id"] == admin_user.id
|
|
||||||
assert data["name"] == admin_user.name
|
|
||||||
assert data["is_admin"] == admin_user.is_admin
|
|
||||||
|
|
||||||
|
|
||||||
def test_get_nonexistent_user(client, auth_headers):
|
|
||||||
"""Test retrieving a non-existent user."""
|
|
||||||
response = client.get("/api/v1/users/99999", headers=auth_headers)
|
|
||||||
assert response.status_code == 404
|
|
||||||
assert "not found" in response.json()["detail"].lower()
|
|
||||||
|
|
||||||
|
|
||||||
def test_update_user(client, auth_headers, regular_user):
|
|
||||||
"""Test updating a user."""
|
|
||||||
update_data = {"name": "updated_name", "email": "updated@example.com"}
|
|
||||||
|
|
||||||
response = client.patch(
|
|
||||||
f"/api/v1/users/{regular_user.id}", json=update_data, headers=auth_headers
|
|
||||||
)
|
|
||||||
assert response.status_code == 200
|
|
||||||
|
|
||||||
data = response.json()
|
|
||||||
assert data["name"] == "updated_name"
|
|
||||||
assert data["email"] == "updated@example.com"
|
|
||||||
# Unchanged fields should remain the same
|
|
||||||
assert data["is_admin"] == regular_user.is_admin
|
|
||||||
|
|
||||||
|
|
||||||
def test_update_user_password(client, auth_headers, regular_user):
|
|
||||||
"""Test updating a user's password."""
|
|
||||||
update_data = {"password": "new_password_456"}
|
|
||||||
|
|
||||||
response = client.patch(
|
|
||||||
f"/api/v1/users/{regular_user.id}", json=update_data, headers=auth_headers
|
|
||||||
)
|
|
||||||
assert response.status_code == 200
|
|
||||||
|
|
||||||
# Verify password can be used for login
|
|
||||||
login_response = client.post(
|
|
||||||
"/api/v1/token",
|
|
||||||
data={"username": regular_user.name, "password": "new_password_456"},
|
|
||||||
)
|
|
||||||
assert login_response.status_code == 200
|
|
||||||
|
|
||||||
|
|
||||||
def test_update_nonexistent_user(client, auth_headers):
|
|
||||||
"""Test updating a non-existent user."""
|
|
||||||
update_data = {"name": "updated"}
|
|
||||||
response = client.patch(
|
|
||||||
"/api/v1/users/99999", json=update_data, headers=auth_headers
|
|
||||||
)
|
|
||||||
assert response.status_code == 404
|
|
||||||
|
|
||||||
|
|
||||||
def test_delete_user(client, auth_headers, regular_user):
|
|
||||||
"""Test deleting a user."""
|
|
||||||
response = client.delete(f"/api/v1/users/{regular_user.id}", headers=auth_headers)
|
|
||||||
assert response.status_code == 200
|
|
||||||
assert "deleted successfully" in response.json()["message"].lower()
|
|
||||||
|
|
||||||
# Verify user is deleted
|
|
||||||
response = client.get(f"/api/v1/users/{regular_user.id}", headers=auth_headers)
|
|
||||||
assert response.status_code == 404
|
|
||||||
|
|
||||||
|
|
||||||
def test_delete_nonexistent_user(client, auth_headers):
|
|
||||||
"""Test deleting a non-existent user."""
|
|
||||||
response = client.delete("/api/v1/users/99999", headers=auth_headers)
|
|
||||||
assert response.status_code == 404
|
|
||||||
|
|
||||||
|
|
||||||
def test_user_operations_by_non_admin(client, user_auth_headers):
|
|
||||||
"""Test that non-admin users cannot perform admin operations."""
|
|
||||||
# Try to create a user
|
|
||||||
response = client.post(
|
|
||||||
"/api/v1/users/",
|
|
||||||
json={"name": "test", "password": "pass"},
|
|
||||||
headers=user_auth_headers,
|
|
||||||
)
|
|
||||||
assert response.status_code == 403
|
|
||||||
|
|
||||||
# Try to get users
|
|
||||||
response = client.get("/api/v1/users/", headers=user_auth_headers)
|
|
||||||
assert response.status_code == 403
|
|
||||||
|
|
||||||
# Try to delete the admin user (if ID is known)
|
|
||||||
# This would require knowing the admin user ID
|
|
||||||
# response = client.delete(f"/api/v1/users/{admin_id}", headers=user_auth_headers)
|
|
||||||
# assert response.status_code == 403
|
|
||||||
@@ -6,20 +6,6 @@ resolution-markers = [
|
|||||||
"python_full_version < '3.14'",
|
"python_full_version < '3.14'",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "alembic"
|
|
||||||
version = "1.18.5"
|
|
||||||
source = { registry = "https://pypi.org/simple" }
|
|
||||||
dependencies = [
|
|
||||||
{ name = "mako" },
|
|
||||||
{ name = "sqlalchemy" },
|
|
||||||
{ name = "typing-extensions" },
|
|
||||||
]
|
|
||||||
sdist = { url = "https://files.pythonhosted.org/packages/1a/cc/ac0bed8e562e7407fe55c3ba85a4dce86e6dbd8730887bd1e406a6c5c18a/alembic-1.18.5.tar.gz", hash = "sha256:1554982221dd17e9a749b53902407578eb305e453f71999e8c7f0a48389fff8e", size = 2060480, upload-time = "2026-06-25T15:20:54.888Z" }
|
|
||||||
wheels = [
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/96/78/5fe6dc3a3a5b2f5a2a4faef8bfe336d5fa049a38884ab3172e0098160c01/alembic-1.18.5-py3-none-any.whl", hash = "sha256:06d8ba9d04558022f5395e9317de03d270f3dced49cee01f89fe7a13c26f14bc", size = 264664, upload-time = "2026-06-25T15:20:56.673Z" },
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "annotated-doc"
|
name = "annotated-doc"
|
||||||
version = "0.0.4"
|
version = "0.0.4"
|
||||||
@@ -93,15 +79,6 @@ wheels = [
|
|||||||
{ url = "https://files.pythonhosted.org/packages/42/b9/f8d6fa329ab25128b7e98fd83a3cb34d9db5b059a9847eddb840a0af45dd/argon2_cffi_bindings-25.1.0-cp39-abi3-win_arm64.whl", hash = "sha256:b0fdbcf513833809c882823f98dc2f931cf659d9a1429616ac3adebb49f5db94", size = 27149, upload-time = "2025-07-30T10:01:59.329Z" },
|
{ url = "https://files.pythonhosted.org/packages/42/b9/f8d6fa329ab25128b7e98fd83a3cb34d9db5b059a9847eddb840a0af45dd/argon2_cffi_bindings-25.1.0-cp39-abi3-win_arm64.whl", hash = "sha256:b0fdbcf513833809c882823f98dc2f931cf659d9a1429616ac3adebb49f5db94", size = 27149, upload-time = "2025-07-30T10:01:59.329Z" },
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "attrs"
|
|
||||||
version = "26.1.0"
|
|
||||||
source = { registry = "https://pypi.org/simple" }
|
|
||||||
sdist = { url = "https://files.pythonhosted.org/packages/9a/8e/82a0fe20a541c03148528be8cac2408564a6c9a0cc7e9171802bc1d26985/attrs-26.1.0.tar.gz", hash = "sha256:d03ceb89cb322a8fd706d4fb91940737b6642aa36998fe130a9bc96c985eff32", size = 952055, upload-time = "2026-03-19T14:22:25.026Z" }
|
|
||||||
wheels = [
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/64/b4/17d4b0b2a2dc85a6df63d1157e028ed19f90d4cd97c36717afef2bc2f395/attrs-26.1.0-py3-none-any.whl", hash = "sha256:c647aa4a12dfbad9333ca4e71fe62ddc36f4e63b2d260a37a8b83d2f043ac309", size = 67548, upload-time = "2026-03-19T14:22:23.645Z" },
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "build"
|
name = "build"
|
||||||
version = "1.4.3"
|
version = "1.4.3"
|
||||||
@@ -134,19 +111,6 @@ filecache = [
|
|||||||
{ name = "filelock" },
|
{ name = "filelock" },
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cattrs"
|
|
||||||
version = "26.1.0"
|
|
||||||
source = { registry = "https://pypi.org/simple" }
|
|
||||||
dependencies = [
|
|
||||||
{ name = "attrs" },
|
|
||||||
{ name = "typing-extensions" },
|
|
||||||
]
|
|
||||||
sdist = { url = "https://files.pythonhosted.org/packages/a0/ec/ba18945e7d6e55a58364d9fb2e46049c1c2998b3d805f19b703f14e81057/cattrs-26.1.0.tar.gz", hash = "sha256:fa239e0f0ec0715ba34852ce813986dfed1e12117e209b816ab87401271cdd40", size = 495672, upload-time = "2026-02-18T22:15:19.406Z" }
|
|
||||||
wheels = [
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/80/56/60547f7801b97c67e97491dc3d9ade9fbccbd0325058fd3dfcb2f5d98d90/cattrs-26.1.0-py3-none-any.whl", hash = "sha256:d1e0804c42639494d469d08d4f26d6b9de9b8ab26b446db7b5f8c2e97f7c3096", size = 73054, upload-time = "2026-02-18T22:15:17.958Z" },
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "certifi"
|
name = "certifi"
|
||||||
version = "2026.2.25"
|
version = "2026.2.25"
|
||||||
@@ -292,75 +256,6 @@ wheels = [
|
|||||||
{ url = "https://files.pythonhosted.org/packages/d1/d6/3965ed04c63042e047cb6a3e6ed1a63a35087b6a609aa3a15ed8ac56c221/colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6", size = 25335, upload-time = "2022-10-25T02:36:20.889Z" },
|
{ url = "https://files.pythonhosted.org/packages/d1/d6/3965ed04c63042e047cb6a3e6ed1a63a35087b6a609aa3a15ed8ac56c221/colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6", size = 25335, upload-time = "2022-10-25T02:36:20.889Z" },
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "coverage"
|
|
||||||
version = "7.14.0"
|
|
||||||
source = { registry = "https://pypi.org/simple" }
|
|
||||||
sdist = { url = "https://files.pythonhosted.org/packages/23/7f/d0720730a397a999ffc0fd3f5bebef347338e3a47b727da66fbb228e2ff2/coverage-7.14.0.tar.gz", hash = "sha256:057a6af2f160a85384cde4ab36f0d2777bae1057bae255f95413cdd382aa5c74", size = 919489, upload-time = "2026-05-10T18:02:31.397Z" }
|
|
||||||
wheels = [
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/6b/76/b7c66ee3c66e1b0f9d894c8125983aa0c03fb2336f2fd16559f9c966157f/coverage-7.14.0-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:f2bbb8254370eb4c628ff3d6fa8a7f74ddc40565394d4f7ab791d1fe568e37ef", size = 219990, upload-time = "2026-05-10T18:00:38.887Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/b3/af/e567cbad5ba69c013a50146dfa886dc7193361fda77521f51274ff620e1b/coverage-7.14.0-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:23b81107f46d3f21d0cbce30664fcec0f5d9f585638a67081750f99738f6bf66", size = 220365, upload-time = "2026-05-10T18:00:40.864Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/44/6f/9ad575d505b4d805b254febc8a5b338a2efe278f8786e56ff1cb8413f9c3/coverage-7.14.0-cp313-cp313-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.whl", hash = "sha256:22a7e06a5f11a757cdfe79018e9095f9f69ae283c5cd8123774c788deec8717b", size = 251363, upload-time = "2026-05-10T18:00:42.489Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/6f/5f/b5370068b2f57787454592ed7dcd1002f0f1703b7db1fa30f6a325a4ca6e/coverage-7.14.0-cp313-cp313-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl", hash = "sha256:9d1aa57a1dc8e05bdc42e81c5d671d849577aeedf279f4c449d6d286f9ed88ca", size = 253961, upload-time = "2026-05-10T18:00:44.079Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/29/1e/51adf17738976e8f2b85ddef7b7aa12a0838b056c92f175941d8862767c1/coverage-7.14.0-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:90c1a51bcfddf645b3bb7ec333d9e94393a8e94f55642380fa8a9a5a9e636cb7", size = 255193, upload-time = "2026-05-10T18:00:45.623Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/9e/7b/5bfd7ac1df3b881c2ac7a5cbc99c7609e6296c402f5ef587cd81c6f355b3/coverage-7.14.0-cp313-cp313-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:a841fae2fadcae4f438d43b6ccc4aac2ad609f47cdb6cfdce60cbb3fe5ca7bc2", size = 257326, upload-time = "2026-05-10T18:00:47.173Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/7d/38/1d37d316b174fad3843a1d76dbdfe4398771c9ecd0515935dd9ece9cd627/coverage-7.14.0-cp313-cp313-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:c79d2319cabef1fe8e86df73371126931550804738f78ad7d31e3aad85a67367", size = 251582, upload-time = "2026-05-10T18:00:49.152Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/34/46/746704f95980ba220214e1a41e18cec5aea80a898eaa53c51bf2d645ff36/coverage-7.14.0-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:1b23b0c6f0b1db6ad769b7050c8b641c0bf215ded26c1816955b17b7f26edfa9", size = 253325, upload-time = "2026-05-10T18:00:51.252Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/e1/b9/bbe87206d9687b192352f893797825b5f5b15ecd3aa9c68fbff0c074d77b/coverage-7.14.0-cp313-cp313-musllinux_1_2_i686.whl", hash = "sha256:55d3089079ce181a4566b1065ab28d2575eb76d8ac8f81f4fcda2bf037fee087", size = 251291, upload-time = "2026-05-10T18:00:52.816Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/46/57/b8cdb12ac0d73ef0243218bd5e22c9df8f92edab8018213a86aec67c5324/coverage-7.14.0-cp313-cp313-musllinux_1_2_ppc64le.whl", hash = "sha256:49c005cba1e2f9677fb2845dcdf9a2e72a52a17d63e8231aaaae35d9f50215ef", size = 255448, upload-time = "2026-05-10T18:00:54.548Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/1f/d4/5002019538b2036ce3c84340f54d2fd5100d55b0a6b0894eee56128d03c7/coverage-7.14.0-cp313-cp313-musllinux_1_2_riscv64.whl", hash = "sha256:9117377b823daa28aa8635fbb08cda1cd6be3d7143257345459559aeef852d52", size = 251110, upload-time = "2026-05-10T18:00:56.122Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/37/53/20c5009477660f084e6ed60bc02a91894b8e234e617e86ecfd9aaf78e27b/coverage-7.14.0-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:7b79d646cf46d5cf9a9f40281d4441df5849e445726e369006d2b117710b33fe", size = 252885, upload-time = "2026-05-10T18:00:57.967Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/ae/ab/3cf6427ac9c1f1db747dbb1ce71dde47984876d4c2cfd018a3fef0a78d4d/coverage-7.14.0-cp313-cp313-win32.whl", hash = "sha256:fb609b3658479e33f9516d46f1a89dbb9b6c261366e3a11844a96ec487533dae", size = 222539, upload-time = "2026-05-10T18:00:59.581Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/8f/b8/9228523e80321c2cb4880d1f589bc0171f2f71432c35118ad04dc01decce/coverage-7.14.0-cp313-cp313-win_amd64.whl", hash = "sha256:0773d8329cf32b6fd222e4b52622c61fe8d503eb966cfc8d3c3c10c96266d50e", size = 223344, upload-time = "2026-05-10T18:01:01.531Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/a3/99/118daa192f95e3a6cb2740100fbf8797cda1734b4134ef0b5d501a7fa8f3/coverage-7.14.0-cp313-cp313-win_arm64.whl", hash = "sha256:b4e26a0f1b696faf283bffe5b8569e44e336c582439df5d53281ab89ee0cba96", size = 221966, upload-time = "2026-05-10T18:01:03.16Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/e6/f1/a46cc0c013be170216253184a32366d7cbdb9252feaec866b05c2d12a894/coverage-7.14.0-cp313-cp313t-macosx_10_13_x86_64.whl", hash = "sha256:953f521ca9445300397e65fda3dca58b2dbd68fee983777420b57ac3c77e9f90", size = 220679, upload-time = "2026-05-10T18:01:05.058Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/64/8c/9c30a3d311a34177fa432995be7fbfc64477d8bac5630bd38055b1c9b424/coverage-7.14.0-cp313-cp313t-macosx_11_0_arm64.whl", hash = "sha256:98af83fd65ae24b1fdd03aaead967a9f523bcd2f1aab2d4f3ffda65bb568a6f1", size = 221033, upload-time = "2026-05-10T18:01:07.002Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/9a/cd/3fb5e06c3badefd0c1b47e2044fdca67f8220a4ec2e7fcfb476aa0a67c6c/coverage-7.14.0-cp313-cp313t-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.whl", hash = "sha256:668b92e6958c4db7cf92e81caac328dfbbdbb215db2850ad28f0cbe1eea0bfbd", size = 262333, upload-time = "2026-05-10T18:01:08.903Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/a8/e6/fbc322325c7294d3e22c1ad6b79e45d0806b25228c8e5842aed6d8169aa7/coverage-7.14.0-cp313-cp313t-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl", hash = "sha256:9fbd898551762dea00d3fef2b1c4f99afd2c6a3ff952ea07d60a9bd5ed4f34bc", size = 264410, upload-time = "2026-05-10T18:01:10.531Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/08/92/c497b264bec1673c47cc77e26f760fcda4654cabf1f39546d1a23a3b8c35/coverage-7.14.0-cp313-cp313t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:68af363c07ecd8d4b7d4043d85cb376d7d227eceb54e5323ee45da73dbd3e426", size = 266836, upload-time = "2026-05-10T18:01:12.19Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/78/fc/045da320987f401af5d2815d351e8aa799aec859f60e29f445e3089eeedb/coverage-7.14.0-cp313-cp313t-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:6e57054a583da8ac55edf24117ea4c9133032cfc4cf72aa2d48c1e5d4b52f899", size = 267974, upload-time = "2026-05-10T18:01:13.926Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/1b/ae/227b1e379497fb7a4fc3286e620f80c8a1e7cec66d45695a01639eb1af65/coverage-7.14.0-cp313-cp313t-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:cc3499459bbcdd51a65b64c35ab7ed2764eaf3cba826e0df3f1d7fe2e102b70b", size = 261578, upload-time = "2026-05-10T18:01:15.564Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/a0/f5/3570342900f2acea31d33ff1590c5d8bac1a8e1a2e1c6d34a5d5e61de681/coverage-7.14.0-cp313-cp313t-musllinux_1_2_aarch64.whl", hash = "sha256:45899ec2138a4346ed34d601dedf5076fb74edf2d1dd9dc76a78e82397edee90", size = 264394, upload-time = "2026-05-10T18:01:17.607Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/16/29/de1bbc01c935b28f89b1dc3db85b011c055e843a8e5e3b83141c3f80af7f/coverage-7.14.0-cp313-cp313t-musllinux_1_2_i686.whl", hash = "sha256:8767486808c436f05b23ab98eb963fb29185e32a9357a166971685cb3459900f", size = 262022, upload-time = "2026-05-10T18:01:19.304Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/35/95/f53890b0bf2fc10ab168e05d38869215e73ca24c4cb521c3bb0eb62fe16b/coverage-7.14.0-cp313-cp313t-musllinux_1_2_ppc64le.whl", hash = "sha256:a3b5ddfd6aa7ddad53ee3edb231e88a2151507a43229b7d71b953916deca127d", size = 265732, upload-time = "2026-05-10T18:01:21.494Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/ed/ea/c919e259081dd2bdf0e43b87209709ba7ec2e4117c2a7f5185379c43463c/coverage-7.14.0-cp313-cp313t-musllinux_1_2_riscv64.whl", hash = "sha256:63df0fe568e698e1045792399f8ab6da3a6c2dce3182813fb92afa2641087b47", size = 260921, upload-time = "2026-05-10T18:01:23.533Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/1a/2c/c2831889705a81dc5d1c6ca12e4d8e9b95dfc146d153488a6c0ea685d28e/coverage-7.14.0-cp313-cp313t-musllinux_1_2_x86_64.whl", hash = "sha256:827d6397dbd95144939b18f89edf31f63e1f99633e8d5f32f22ba8bdda567477", size = 263109, upload-time = "2026-05-10T18:01:25.165Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/5a/a9/2fcae5003cac3d63fe344d2166243c2756935f48420863c5272b240d550b/coverage-7.14.0-cp313-cp313t-win32.whl", hash = "sha256:7bf43e000d24012599b879791cff41589af90674722421ef11b11a5431920bab", size = 223212, upload-time = "2026-05-10T18:01:27.157Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/3f/bb/18e94d7b14b9b398164197114a587a04ab7c9fdbe1d237eef57311c5e883/coverage-7.14.0-cp313-cp313t-win_amd64.whl", hash = "sha256:3f5549365af25d770e06b1f8f5682d9a5637d06eb494db91c6fa75d3950cc917", size = 224272, upload-time = "2026-05-10T18:01:29.107Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/db/56/4f14fad782b035c81c4ffd09159e7103d42bb1d93ac8496d04b90a11b7da/coverage-7.14.0-cp313-cp313t-win_arm64.whl", hash = "sha256:6d160217ec6fe890f16ad3a9531761589443749e448f91986c972714fad361c8", size = 222530, upload-time = "2026-05-10T18:01:31.151Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/1c/18/b9a6586d73992807c26f9a5f274131be3d76b56b18a82b9392e2a25d2e45/coverage-7.14.0-cp314-cp314-macosx_10_15_x86_64.whl", hash = "sha256:9aed9fa983514ca032790f3fe0d1c0e42ca7e16b42432af1706b50a9a46bef5d", size = 220036, upload-time = "2026-05-10T18:01:33.057Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/f3/9b/4165a1d56ddc302a0e2d518fd9d412a4fd0b57562618c78c5f21c57194f5/coverage-7.14.0-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:ba3b8390db29296dbbf49e91b6fe08f990743a90c8f447ba4c2ffc29670dfa63", size = 220368, upload-time = "2026-05-10T18:01:34.705Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/69/aa/c12e52a5ba148d9995229d557e3be6e554fe469addc0e9241b2f0956d8ea/coverage-7.14.0-cp314-cp314-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.whl", hash = "sha256:3a5d8e876dfa2f102e970b183863d6dedd023d3c0eeca1fe7a9787bc5f28b212", size = 251417, upload-time = "2026-05-10T18:01:36.949Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/d7/51/ec641c26e6dca1b25a7d2035ba6ecb7c884ef1a100a9e42fbe4ce4405139/coverage-7.14.0-cp314-cp314-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl", hash = "sha256:5ebb8f4614a3787d567e610bbfdf96a4798dd69a1afb1bd8ad228d4111fe6ff3", size = 253924, upload-time = "2026-05-10T18:01:38.985Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/33/c4/59c3de0bd1b538824173fd518fed51c1ce740ca5ed68e74545983f4053a9/coverage-7.14.0-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:6b9bf47223dd8db3d4c4b2e443b02bace480d428f0822c3f991600448a176c97", size = 255269, upload-time = "2026-05-10T18:01:40.957Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/7b/a9/36dfa153a62040296f6e7febfdb20a5720622f6ef5a81a41e8237b9a5344/coverage-7.14.0-cp314-cp314-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:3485a836550b303d006d57cc06e3d5afaabc642c77050b7c985a97b13e3776b8", size = 257583, upload-time = "2026-05-10T18:01:42.607Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/26/7b/cc2c048d4114d9ab1c2409e9ee365e5ae10736df6dffcfc9444effa6c708/coverage-7.14.0-cp314-cp314-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:3e7e88110bae996d199d1693ca8ec3fd52441d426401ae963437598667b4c5eb", size = 251434, upload-time = "2026-05-10T18:01:44.537Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/ee/df/6770eaa576e604575e9a78055313250faef5faa84bd6f71a39fece519c43/coverage-7.14.0-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:15228a6800ce7bdf1b74800595e56db7138cecb338fdbf044806e10dcf182dfe", size = 253280, upload-time = "2026-05-10T18:01:46.175Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/ad/9e/1c0264514a3f98259a6d64765a397b2c8373e3ba59ee722a4802d3ec0c61/coverage-7.14.0-cp314-cp314-musllinux_1_2_i686.whl", hash = "sha256:9d26ac7f5398bafc5b57421ad994e8a4749e8a7a0e62d05ec7d53014d5963bfa", size = 251241, upload-time = "2026-05-10T18:01:48.732Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/64/16/4efdf3e3c4079cdbf0ece56a2fea872df9e8a3e15a13a0af4400e1075944/coverage-7.14.0-cp314-cp314-musllinux_1_2_ppc64le.whl", hash = "sha256:2fb73254ff43c911c967a899e1359bc5049b4b115d6e8fbdde4937d0a2246cd5", size = 255516, upload-time = "2026-05-10T18:01:50.819Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/93/69/b1de96346603881b3d1bc8d6447c83200e1c9700ffbaff926ba01ff5724c/coverage-7.14.0-cp314-cp314-musllinux_1_2_riscv64.whl", hash = "sha256:454a380af72c6adada298ed270d38c7a391288198dbfb8467f786f588751a90c", size = 251059, upload-time = "2026-05-10T18:01:52.773Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/a4/66/2881853e0363a5e0a724d1103e53650795367471b6afb234f8b49e713bc6/coverage-7.14.0-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:65c86fb646d2bd2972e96bd1a8b45817ed907cee68655d6295fe7ec031d04cca", size = 252716, upload-time = "2026-05-10T18:01:54.506Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/55/5c/0d3305d002c41dcde873dbe456491e663dc55152ca526b630b5c47efd62f/coverage-7.14.0-cp314-cp314-win32.whl", hash = "sha256:6a6516b02a6101398e19a3f44820f69bab2590697f7def4331f668b14adaf828", size = 222788, upload-time = "2026-05-10T18:01:56.487Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/f9/58/6e1b8f52fdc3184b47dc5037f5070d83a3d11042db1594b02d2a44d786c8/coverage-7.14.0-cp314-cp314-win_amd64.whl", hash = "sha256:45e0f79d8351fa76e256716df91eab12890d32678b9590df7ae1042e4bd4cf5d", size = 223600, upload-time = "2026-05-10T18:01:58.497Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/00/70/a18c408e674bc26281cadaedc7351f929bd2094e191e4b15271c30b084cc/coverage-7.14.0-cp314-cp314-win_arm64.whl", hash = "sha256:4b899594a8b2d81e5cc064a0d7f9cac2081fed91049456cae7676787e41549c9", size = 222168, upload-time = "2026-05-10T18:02:00.411Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/3d/89/2681f071d238b62aff8dfc2ab44fc24cfdb38d1c01f391a80522ff5d3a16/coverage-7.14.0-cp314-cp314t-macosx_10_15_x86_64.whl", hash = "sha256:f580f8c80acd94ac72e863efe2cab791d8c38d153e0b463b92dfa000d5c84cd1", size = 220766, upload-time = "2026-05-10T18:02:02.313Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/bd/c7/c987babafd9207ffa1995e1ef1f9b26762cf4963aa768a66b6f0501e4616/coverage-7.14.0-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:a2bd259c442cd43c49b30fbafc51776eb19ea396faf159d26a83e6a0a5f13b0c", size = 221035, upload-time = "2026-05-10T18:02:04.017Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/5a/e9/d6a5ac3b333088143d6fc877d398a9a674dc03124a2f776e131f03864823/coverage-7.14.0-cp314-cp314t-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.whl", hash = "sha256:a706b908dfa85538863504c624b237a3cc34232bf403c057414ebfdb3b4d9f84", size = 262405, upload-time = "2026-05-10T18:02:05.915Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/38/b1/e70838d29a7c08e22d44398a46db90815bbcbf28de06992bd9210d1a8d8e/coverage-7.14.0-cp314-cp314t-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl", hash = "sha256:7333cd944ee4393b9b3d3c1b598c936d4fc8d70573a4c7dacfec5590dd50e436", size = 264530, upload-time = "2026-05-10T18:02:07.582Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/6b/73/5c31ef97763288d03d9995152b96d5475b527c63d91c84b01caea894b83a/coverage-7.14.0-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:0f162bc9a15b82d947b02651b0c7e1609d6f7a8735ca330cfadec8481dd97d5a", size = 266932, upload-time = "2026-05-10T18:02:09.401Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/e1/76/dd56d80f29c5f05b4d76f7e7c6d47cafacae017189c75c5759d24f9ff0cc/coverage-7.14.0-cp314-cp314t-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:362cb78e01a5dc82009d88004cf60f2e6b6d6fcbfdec05b05af73b0abf40118f", size = 268062, upload-time = "2026-05-10T18:02:11.399Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/6e/c7/27ba85cd5b95614f159ff93ebff1901584a8d192e2e5e24c4943a7453f59/coverage-7.14.0-cp314-cp314t-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:acebd068fca5512c3a6fde9c045f901613478781a73f0e82b307b214daef23fb", size = 261504, upload-time = "2026-05-10T18:02:13.257Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/13/2e/e8149f60ab5d5684c6eee881bdf34b127115cddbb958b196768dd9d63473/coverage-7.14.0-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:29fe3da551dface75deb2ccbf87b6b66e2e7ef38f6d89050b428be94afff3490", size = 264398, upload-time = "2026-05-10T18:02:15.063Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/d9/7f/1261b025285323225f4b4abffa5a643649dfd67e25ddca7ebcbdea3b7cb3/coverage-7.14.0-cp314-cp314t-musllinux_1_2_i686.whl", hash = "sha256:b4cc4fce8672fffcb09b0eafc167b396b3ba53c4a7230f54b7aaffbf6c835fa9", size = 262000, upload-time = "2026-05-10T18:02:16.756Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/d3/dc/829c54f60b9d08389439c00f813c752781c496fc5788c78d8006db4b4f2b/coverage-7.14.0-cp314-cp314t-musllinux_1_2_ppc64le.whl", hash = "sha256:5d4a51aad8ba8bdcd2b8bd8f03d4aca19693fa2327a3470e4718a25b03481020", size = 265732, upload-time = "2026-05-10T18:02:18.817Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/ed/b0/70bd1419941652fa062689cba9c3eeafb8f5e6fbb890bce41c3bdda5dbd6/coverage-7.14.0-cp314-cp314t-musllinux_1_2_riscv64.whl", hash = "sha256:9f323af3e1e4f68b60b7b247e37b8515563a61375518fa59de1af48ba28a3db6", size = 260847, upload-time = "2026-05-10T18:02:20.528Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/f2/73/be40b2390656c654d35ea0015ea7ba3d945769cf80790ad5e0bb2d56d2ba/coverage-7.14.0-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:1a0abc7342ea9711c469dd8b821c6c311e6bc6aac1442e5fbd6b27fae0a8f3db", size = 263166, upload-time = "2026-05-10T18:02:22.337Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/29/55/4a643f712fcf7cf2881f8ec1e0ccb7b164aff3108f69b51801246c8799f2/coverage-7.14.0-cp314-cp314t-win32.whl", hash = "sha256:a9f864ef57b7172e2db87a096642dd51e179e085ab6b2c371c29e885f65c8fb2", size = 223573, upload-time = "2026-05-10T18:02:24.11Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/27/96/3acae5da0953be042c0b4dea6d6789d2f080701c77b88e44d5bd41b9219b/coverage-7.14.0-cp314-cp314t-win_amd64.whl", hash = "sha256:29943e552fdc08e082eb51400fb2f58e118a83b5542bd06531214e084399b644", size = 224680, upload-time = "2026-05-10T18:02:25.896Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/93/3d/6ab5d2dd8325d838737c6f8d83d62eb6230e0d70b87b51b57bbfd08fa767/coverage-7.14.0-cp314-cp314t-win_arm64.whl", hash = "sha256:742a73ea621953b012f2c4c2219b512180dd84489acf5b1596b0aafc55b9100b", size = 222703, upload-time = "2026-05-10T18:02:27.822Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/61/e8/cb8e80d6f9f55b99588625062822bf946cf03ed06315df4bd8397f5632a1/coverage-7.14.0-py3-none-any.whl", hash = "sha256:8de5b61163aee3d05c8a2beab6f47913df7981dad1baf82c414d99158c286ab1", size = 211764, upload-time = "2026-05-10T18:02:29.538Z" },
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "crashtest"
|
name = "crashtest"
|
||||||
version = "0.4.1"
|
version = "0.4.1"
|
||||||
@@ -441,19 +336,6 @@ wheels = [
|
|||||||
{ url = "https://files.pythonhosted.org/packages/ba/5a/18ad964b0086c6e62e2e7500f7edc89e3faa45033c71c1893d34eed2b2de/dnspython-2.8.0-py3-none-any.whl", hash = "sha256:01d9bbc4a2d76bf0db7c1f729812ded6d912bd318d3b1cf81d30c0f845dbf3af", size = 331094, upload-time = "2025-09-07T18:57:58.071Z" },
|
{ url = "https://files.pythonhosted.org/packages/ba/5a/18ad964b0086c6e62e2e7500f7edc89e3faa45033c71c1893d34eed2b2de/dnspython-2.8.0-py3-none-any.whl", hash = "sha256:01d9bbc4a2d76bf0db7c1f729812ded6d912bd318d3b1cf81d30c0f845dbf3af", size = 331094, upload-time = "2025-09-07T18:57:58.071Z" },
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "docstring-to-markdown"
|
|
||||||
version = "0.17"
|
|
||||||
source = { registry = "https://pypi.org/simple" }
|
|
||||||
dependencies = [
|
|
||||||
{ name = "importlib-metadata" },
|
|
||||||
{ name = "typing-extensions" },
|
|
||||||
]
|
|
||||||
sdist = { url = "https://files.pythonhosted.org/packages/52/d8/8abe80d62c5dce1075578031bcfde07e735bcf0afe2886dd48b470162ab4/docstring_to_markdown-0.17.tar.gz", hash = "sha256:df72a112294c7492487c9da2451cae0faeee06e86008245c188c5761c9590ca3", size = 32260, upload-time = "2025-05-02T15:09:07.932Z" }
|
|
||||||
wheels = [
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/56/7b/af3d0da15bed3a8665419bb3a630585756920f4ad67abfdfef26240ebcc0/docstring_to_markdown-0.17-py3-none-any.whl", hash = "sha256:fd7d5094aa83943bf5f9e1a13701866b7c452eac19765380dead666e36d3711c", size = 23479, upload-time = "2025-05-02T15:09:06.676Z" },
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "dulwich"
|
name = "dulwich"
|
||||||
version = "1.1.0"
|
version = "1.1.0"
|
||||||
@@ -657,54 +539,26 @@ name = "gatekeeper"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = { virtual = "." }
|
source = { virtual = "." }
|
||||||
dependencies = [
|
dependencies = [
|
||||||
{ name = "alembic" },
|
|
||||||
{ name = "fastapi", extra = ["standard"] },
|
{ name = "fastapi", extra = ["standard"] },
|
||||||
{ name = "lgpio", marker = "platform_machine == 'aarch64' and sys_platform == 'linux'" },
|
|
||||||
{ name = "paho-mqtt" },
|
{ name = "paho-mqtt" },
|
||||||
{ name = "poetry" },
|
{ name = "poetry" },
|
||||||
{ name = "pwdlib", extra = ["argon2"] },
|
{ name = "pwdlib", extra = ["argon2"] },
|
||||||
{ name = "pydantic-settings" },
|
|
||||||
{ name = "pyjwt", extra = ["crypto"] },
|
{ name = "pyjwt", extra = ["crypto"] },
|
||||||
{ name = "pyscard" },
|
|
||||||
{ name = "python-desfire" },
|
{ name = "python-desfire" },
|
||||||
{ name = "requests" },
|
|
||||||
{ name = "setuptools" },
|
|
||||||
{ name = "sqlmodel" },
|
{ name = "sqlmodel" },
|
||||||
]
|
]
|
||||||
|
|
||||||
[package.dev-dependencies]
|
|
||||||
dev = [
|
|
||||||
{ name = "jedi-language-server" },
|
|
||||||
{ name = "pytest" },
|
|
||||||
{ name = "pytest-cov" },
|
|
||||||
{ name = "ruff" },
|
|
||||||
]
|
|
||||||
|
|
||||||
[package.metadata]
|
[package.metadata]
|
||||||
requires-dist = [
|
requires-dist = [
|
||||||
{ name = "alembic", specifier = ">=1.18.5" },
|
|
||||||
{ name = "fastapi", extras = ["standard"], specifier = ">=0.135.3" },
|
{ name = "fastapi", extras = ["standard"], specifier = ">=0.135.3" },
|
||||||
{ name = "lgpio", marker = "platform_machine == 'aarch64' and sys_platform == 'linux'", specifier = ">=0.2.2.0" },
|
|
||||||
{ name = "paho-mqtt", specifier = ">=2.1.0" },
|
{ name = "paho-mqtt", specifier = ">=2.1.0" },
|
||||||
{ name = "poetry", specifier = ">=2.3.4" },
|
{ name = "poetry", specifier = ">=2.3.4" },
|
||||||
{ name = "pwdlib", extras = ["argon2"], specifier = ">=0.3.0" },
|
{ name = "pwdlib", extras = ["argon2"], specifier = ">=0.3.0" },
|
||||||
{ name = "pydantic-settings", specifier = ">=2.13.1" },
|
|
||||||
{ name = "pyjwt", extras = ["crypto"], specifier = ">=2.12.1" },
|
{ name = "pyjwt", extras = ["crypto"], specifier = ">=2.12.1" },
|
||||||
{ name = "pyscard", specifier = ">=2.3.1" },
|
|
||||||
{ name = "python-desfire", git = "https://github.com/waza-ari/python-desfire" },
|
{ name = "python-desfire", git = "https://github.com/waza-ari/python-desfire" },
|
||||||
{ name = "requests", specifier = ">=2.33.1" },
|
|
||||||
{ name = "setuptools", specifier = ">=82.0.1" },
|
|
||||||
{ name = "sqlmodel", specifier = ">=0.0.38" },
|
{ name = "sqlmodel", specifier = ">=0.0.38" },
|
||||||
]
|
]
|
||||||
|
|
||||||
[package.metadata.requires-dev]
|
|
||||||
dev = [
|
|
||||||
{ name = "jedi-language-server", specifier = ">=0.47.0" },
|
|
||||||
{ name = "pytest", specifier = ">=9.0.3" },
|
|
||||||
{ name = "pytest-cov", specifier = ">=7.1.0" },
|
|
||||||
{ name = "ruff", specifier = ">=0.16.0" },
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "greenlet"
|
name = "greenlet"
|
||||||
version = "3.4.0"
|
version = "3.4.0"
|
||||||
@@ -804,27 +658,6 @@ wheels = [
|
|||||||
{ url = "https://files.pythonhosted.org/packages/0e/61/66938bbb5fc52dbdf84594873d5b51fb1f7c7794e9c0f5bd885f30bc507b/idna-3.11-py3-none-any.whl", hash = "sha256:771a87f49d9defaf64091e6e6fe9c18d4833f140bd19464795bc32d966ca37ea", size = 71008, upload-time = "2025-10-12T14:55:18.883Z" },
|
{ url = "https://files.pythonhosted.org/packages/0e/61/66938bbb5fc52dbdf84594873d5b51fb1f7c7794e9c0f5bd885f30bc507b/idna-3.11-py3-none-any.whl", hash = "sha256:771a87f49d9defaf64091e6e6fe9c18d4833f140bd19464795bc32d966ca37ea", size = 71008, upload-time = "2025-10-12T14:55:18.883Z" },
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "importlib-metadata"
|
|
||||||
version = "9.0.0"
|
|
||||||
source = { registry = "https://pypi.org/simple" }
|
|
||||||
dependencies = [
|
|
||||||
{ name = "zipp" },
|
|
||||||
]
|
|
||||||
sdist = { url = "https://files.pythonhosted.org/packages/a9/01/15bb152d77b21318514a96f43af312635eb2500c96b55398d020c93d86ea/importlib_metadata-9.0.0.tar.gz", hash = "sha256:a4f57ab599e6a2e3016d7595cfd72eb4661a5106e787a95bcc90c7105b831efc", size = 56405, upload-time = "2026-03-20T06:42:56.999Z" }
|
|
||||||
wheels = [
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/38/3d/2d244233ac4f76e38533cfcb2991c9eb4c7bf688ae0a036d30725b8faafe/importlib_metadata-9.0.0-py3-none-any.whl", hash = "sha256:2d21d1cc5a017bd0559e36150c21c830ab1dc304dedd1b7ea85d20f45ef3edd7", size = 27789, upload-time = "2026-03-20T06:42:55.665Z" },
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "iniconfig"
|
|
||||||
version = "2.3.0"
|
|
||||||
source = { registry = "https://pypi.org/simple" }
|
|
||||||
sdist = { url = "https://files.pythonhosted.org/packages/72/34/14ca021ce8e5dfedc35312d08ba8bf51fdd999c576889fc2c24cb97f4f10/iniconfig-2.3.0.tar.gz", hash = "sha256:c76315c77db068650d49c5b56314774a7804df16fee4402c1f19d6d15d8c4730", size = 20503, upload-time = "2025-10-18T21:55:43.219Z" }
|
|
||||||
wheels = [
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/cb/b1/3846dd7f199d53cb17f49cba7e651e9ce294d8497c8c150530ed11865bb8/iniconfig-2.3.0-py3-none-any.whl", hash = "sha256:f631c04d2c48c52b84d0d0549c99ff3859c98df65b3101406327ecc7d53fbf12", size = 7484, upload-time = "2025-10-18T21:55:41.639Z" },
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "installer"
|
name = "installer"
|
||||||
version = "0.7.0"
|
version = "0.7.0"
|
||||||
@@ -867,34 +700,6 @@ wheels = [
|
|||||||
{ url = "https://files.pythonhosted.org/packages/fd/c4/813bb09f0985cb21e959f21f2464169eca882656849adf727ac7bb7e1767/jaraco_functools-4.4.0-py3-none-any.whl", hash = "sha256:9eec1e36f45c818d9bf307c8948eb03b2b56cd44087b3cdc989abca1f20b9176", size = 10481, upload-time = "2025-12-21T09:29:42.27Z" },
|
{ url = "https://files.pythonhosted.org/packages/fd/c4/813bb09f0985cb21e959f21f2464169eca882656849adf727ac7bb7e1767/jaraco_functools-4.4.0-py3-none-any.whl", hash = "sha256:9eec1e36f45c818d9bf307c8948eb03b2b56cd44087b3cdc989abca1f20b9176", size = 10481, upload-time = "2025-12-21T09:29:42.27Z" },
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "jedi"
|
|
||||||
version = "0.20.0"
|
|
||||||
source = { registry = "https://pypi.org/simple" }
|
|
||||||
dependencies = [
|
|
||||||
{ name = "parso" },
|
|
||||||
]
|
|
||||||
sdist = { url = "https://files.pythonhosted.org/packages/46/b7/a3635f6a2d7cf5b5dd98064fc1d5fbbafcb25477bcea204a3a92145d158b/jedi-0.20.0.tar.gz", hash = "sha256:c3f4ccbd276696f4b19c54618d4fb18f9fc24b0aef02acf704b23f487daa1011", size = 3119416, upload-time = "2026-05-01T23:38:47.814Z" }
|
|
||||||
wheels = [
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/9a/93/242e2eab5fe682ffcb8b0084bde703a41d51e17ee0f3a31ff0d9d813620a/jedi-0.20.0-py2.py3-none-any.whl", hash = "sha256:7bdd9c2634f56713299976f4cbd59cb3fa92165cc5e05ea811fb253480728b67", size = 4884812, upload-time = "2026-05-01T23:38:43.919Z" },
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "jedi-language-server"
|
|
||||||
version = "0.47.0"
|
|
||||||
source = { registry = "https://pypi.org/simple" }
|
|
||||||
dependencies = [
|
|
||||||
{ name = "cattrs" },
|
|
||||||
{ name = "docstring-to-markdown" },
|
|
||||||
{ name = "jedi" },
|
|
||||||
{ name = "lsprotocol" },
|
|
||||||
{ name = "pygls" },
|
|
||||||
]
|
|
||||||
sdist = { url = "https://files.pythonhosted.org/packages/f5/00/0cc9fc9996f79f1935a39236f300e6b2399aed34b8170248c5108e38e652/jedi_language_server-0.47.0.tar.gz", hash = "sha256:43d9b89d07b504470544b80d76739449856a2be6565571cb362ee0681f6f0b86", size = 91714, upload-time = "2026-05-31T14:02:43.312Z" }
|
|
||||||
wheels = [
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/05/e1/ad4afa632b4ea58f422391d11e86b5100b5578879af6bf04bf5aaf4beede/jedi_language_server-0.47.0-py3-none-any.whl", hash = "sha256:0e00d5af41c1a966c9ec73221e81b1af3b8c0243d29477e5441c661d5b61ec3e", size = 33844, upload-time = "2026-05-31T14:02:42.161Z" },
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "jeepney"
|
name = "jeepney"
|
||||||
version = "0.9.0"
|
version = "0.9.0"
|
||||||
@@ -933,37 +738,6 @@ wheels = [
|
|||||||
{ url = "https://files.pythonhosted.org/packages/81/db/e655086b7f3a705df045bf0933bdd9c2f79bb3c97bfef1384598bb79a217/keyring-25.7.0-py3-none-any.whl", hash = "sha256:be4a0b195f149690c166e850609a477c532ddbfbaed96a404d4e43f8d5e2689f", size = 39160, upload-time = "2025-11-16T16:26:08.402Z" },
|
{ url = "https://files.pythonhosted.org/packages/81/db/e655086b7f3a705df045bf0933bdd9c2f79bb3c97bfef1384598bb79a217/keyring-25.7.0-py3-none-any.whl", hash = "sha256:be4a0b195f149690c166e850609a477c532ddbfbaed96a404d4e43f8d5e2689f", size = 39160, upload-time = "2025-11-16T16:26:08.402Z" },
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "lgpio"
|
|
||||||
version = "0.2.2.0"
|
|
||||||
source = { registry = "https://pypi.org/simple" }
|
|
||||||
sdist = { url = "https://files.pythonhosted.org/packages/56/33/26ec2e8049eaa2f077bf23a12dc61ca559fbfa7bea0516bf263d657ae275/lgpio-0.2.2.0.tar.gz", hash = "sha256:11372e653b200f76a0b3ef8a23a0735c85ec678a9f8550b9893151ed0f863fff", size = 90087, upload-time = "2024-03-29T21:59:55.901Z" }
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "lsprotocol"
|
|
||||||
version = "2025.0.0"
|
|
||||||
source = { registry = "https://pypi.org/simple" }
|
|
||||||
dependencies = [
|
|
||||||
{ name = "attrs" },
|
|
||||||
{ name = "cattrs" },
|
|
||||||
]
|
|
||||||
sdist = { url = "https://files.pythonhosted.org/packages/e9/26/67b84e6ec1402f0e6764ef3d2a0aaf9a79522cc1d37738f4e5bb0b21521a/lsprotocol-2025.0.0.tar.gz", hash = "sha256:e879da2b9301e82cfc3e60d805630487ac2f7ab17492f4f5ba5aaba94fe56c29", size = 74896, upload-time = "2025-06-17T21:30:18.156Z" }
|
|
||||||
wheels = [
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/7b/f0/92f2d609d6642b5f30cb50a885d2bf1483301c69d5786286500d15651ef2/lsprotocol-2025.0.0-py3-none-any.whl", hash = "sha256:f9d78f25221f2a60eaa4a96d3b4ffae011b107537facee61d3da3313880995c7", size = 76250, upload-time = "2025-06-17T21:30:19.455Z" },
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "mako"
|
|
||||||
version = "1.3.12"
|
|
||||||
source = { registry = "https://pypi.org/simple" }
|
|
||||||
dependencies = [
|
|
||||||
{ name = "markupsafe" },
|
|
||||||
]
|
|
||||||
sdist = { url = "https://files.pythonhosted.org/packages/00/62/791b31e69ae182791ec67f04850f2f062716bbd205483d63a215f3e062d3/mako-1.3.12.tar.gz", hash = "sha256:9f778e93289bd410bb35daadeb4fc66d95a746f0b75777b942088b7fd7af550a", size = 400219, upload-time = "2026-04-28T19:01:08.512Z" }
|
|
||||||
wheels = [
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/bc/b1/a0ec7a5a9db730a08daef1fdfb8090435b82465abbf758a596f0ea88727e/mako-1.3.12-py3-none-any.whl", hash = "sha256:8f61569480282dbf557145ce441e4ba888be453c30989f879f0d652e39f53ea9", size = 78521, upload-time = "2026-04-28T19:01:10.393Z" },
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "markdown-it-py"
|
name = "markdown-it-py"
|
||||||
version = "4.0.0"
|
version = "4.0.0"
|
||||||
@@ -1099,15 +873,6 @@ wheels = [
|
|||||||
{ url = "https://files.pythonhosted.org/packages/c4/cb/00451c3cf31790287768bb12c6bec834f5d292eaf3022afc88e14b8afc94/paho_mqtt-2.1.0-py3-none-any.whl", hash = "sha256:6db9ba9b34ed5bc6b6e3812718c7e06e2fd7444540df2455d2c51bd58808feee", size = 67219, upload-time = "2024-04-29T19:52:48.345Z" },
|
{ url = "https://files.pythonhosted.org/packages/c4/cb/00451c3cf31790287768bb12c6bec834f5d292eaf3022afc88e14b8afc94/paho_mqtt-2.1.0-py3-none-any.whl", hash = "sha256:6db9ba9b34ed5bc6b6e3812718c7e06e2fd7444540df2455d2c51bd58808feee", size = 67219, upload-time = "2024-04-29T19:52:48.345Z" },
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "parso"
|
|
||||||
version = "0.8.7"
|
|
||||||
source = { registry = "https://pypi.org/simple" }
|
|
||||||
sdist = { url = "https://files.pythonhosted.org/packages/30/4b/90c937815137d43ce71ba043cd3566221e9df6b9c805f24b5d138c9d40a7/parso-0.8.7.tar.gz", hash = "sha256:eaaac4c9fdd5e9e8852dc778d2d7405897ec510f2a298071453e5e3a07914bb1", size = 401824, upload-time = "2026-05-01T23:13:02.138Z" }
|
|
||||||
wheels = [
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/99/5d/8268b644392ee874ee82a635cd0df1773de230bde356c38de28e298392cc/parso-0.8.7-py2.py3-none-any.whl", hash = "sha256:a8926eb2a1b915486941fdbd31e86a4baf88fe8c210f25f2f35ecec5b574ca1c", size = 107025, upload-time = "2026-05-01T23:12:58.867Z" },
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pbs-installer"
|
name = "pbs-installer"
|
||||||
version = "2026.4.7"
|
version = "2026.4.7"
|
||||||
@@ -1143,15 +908,6 @@ wheels = [
|
|||||||
{ url = "https://files.pythonhosted.org/packages/75/a6/a0a304dc33b49145b21f4808d763822111e67d1c3a32b524a1baf947b6e1/platformdirs-4.9.6-py3-none-any.whl", hash = "sha256:e61adb1d5e5cb3441b4b7710bea7e4c12250ca49439228cc1021c00dcfac0917", size = 21348, upload-time = "2026-04-09T00:04:09.463Z" },
|
{ url = "https://files.pythonhosted.org/packages/75/a6/a0a304dc33b49145b21f4808d763822111e67d1c3a32b524a1baf947b6e1/platformdirs-4.9.6-py3-none-any.whl", hash = "sha256:e61adb1d5e5cb3441b4b7710bea7e4c12250ca49439228cc1021c00dcfac0917", size = 21348, upload-time = "2026-04-09T00:04:09.463Z" },
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "pluggy"
|
|
||||||
version = "1.6.0"
|
|
||||||
source = { registry = "https://pypi.org/simple" }
|
|
||||||
sdist = { url = "https://files.pythonhosted.org/packages/f9/e2/3e91f31a7d2b083fe6ef3fa267035b518369d9511ffab804f839851d2779/pluggy-1.6.0.tar.gz", hash = "sha256:7dcc130b76258d33b90f61b658791dede3486c3e6bfb003ee5c9bfb396dd22f3", size = 69412, upload-time = "2025-05-15T12:30:07.975Z" }
|
|
||||||
wheels = [
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/54/20/4d324d65cc6d9205fabedc306948156824eb9f0ee1633355a8f7ec5c66bf/pluggy-1.6.0-py3-none-any.whl", hash = "sha256:e920276dd6813095e9377c0bc5566d94c932c33b27a3e3945d8389c374dd4746", size = 20538, upload-time = "2025-05-15T12:30:06.134Z" },
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "poetry"
|
name = "poetry"
|
||||||
version = "2.3.4"
|
version = "2.3.4"
|
||||||
@@ -1349,20 +1105,6 @@ wheels = [
|
|||||||
{ url = "https://files.pythonhosted.org/packages/00/4b/ccc026168948fec4f7555b9164c724cf4125eac006e176541483d2c959be/pydantic_settings-2.13.1-py3-none-any.whl", hash = "sha256:d56fd801823dbeae7f0975e1f8c8e25c258eb75d278ea7abb5d9cebb01b56237", size = 58929, upload-time = "2026-02-19T13:45:06.034Z" },
|
{ url = "https://files.pythonhosted.org/packages/00/4b/ccc026168948fec4f7555b9164c724cf4125eac006e176541483d2c959be/pydantic_settings-2.13.1-py3-none-any.whl", hash = "sha256:d56fd801823dbeae7f0975e1f8c8e25c258eb75d278ea7abb5d9cebb01b56237", size = 58929, upload-time = "2026-02-19T13:45:06.034Z" },
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "pygls"
|
|
||||||
version = "2.1.1"
|
|
||||||
source = { registry = "https://pypi.org/simple" }
|
|
||||||
dependencies = [
|
|
||||||
{ name = "attrs" },
|
|
||||||
{ name = "cattrs" },
|
|
||||||
{ name = "lsprotocol" },
|
|
||||||
]
|
|
||||||
sdist = { url = "https://files.pythonhosted.org/packages/da/2e/7bbe061d175c0baddde8fc9edb908a4c31ba5d9165b8c68e3439c3a9f138/pygls-2.1.1.tar.gz", hash = "sha256:1da03ba9053201bb337dcdd8d121df70feb2a91e1a0dcc74de5da79755b1a201", size = 55091, upload-time = "2026-03-25T11:19:10.541Z" }
|
|
||||||
wheels = [
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/fd/1a/208293b6c350f5abea6941d5606080d4a492644052504f5312e5de30a902/pygls-2.1.1-py3-none-any.whl", hash = "sha256:510a6dea2476177230c7d851125e5948efdf3fdb9ebfd8543fc434972f8faed4", size = 68975, upload-time = "2026-03-25T11:19:11.374Z" },
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pygments"
|
name = "pygments"
|
||||||
version = "2.20.0"
|
version = "2.20.0"
|
||||||
@@ -1395,49 +1137,6 @@ wheels = [
|
|||||||
{ url = "https://files.pythonhosted.org/packages/bd/24/12818598c362d7f300f18e74db45963dbcb85150324092410c8b49405e42/pyproject_hooks-1.2.0-py3-none-any.whl", hash = "sha256:9e5c6bfa8dcc30091c74b0cf803c81fdd29d94f01992a7707bc97babb1141913", size = 10216, upload-time = "2024-09-29T09:24:11.978Z" },
|
{ url = "https://files.pythonhosted.org/packages/bd/24/12818598c362d7f300f18e74db45963dbcb85150324092410c8b49405e42/pyproject_hooks-1.2.0-py3-none-any.whl", hash = "sha256:9e5c6bfa8dcc30091c74b0cf803c81fdd29d94f01992a7707bc97babb1141913", size = 10216, upload-time = "2024-09-29T09:24:11.978Z" },
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "pyscard"
|
|
||||||
version = "2.3.1"
|
|
||||||
source = { registry = "https://pypi.org/simple" }
|
|
||||||
sdist = { url = "https://files.pythonhosted.org/packages/93/c9/65c68738a94b44b67b3c5e68a815890bbd225f2ae11ef1ace9b61fa9d5f3/pyscard-2.3.1.tar.gz", hash = "sha256:a24356f57a0a950740b6e54f51f819edd5296ee8892a6625b0da04724e9e6c13", size = 160650, upload-time = "2025-10-29T15:49:08.353Z" }
|
|
||||||
wheels = [
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/08/e2/d8f967fe6fee82c02ee35d736e8707d65ed1e37fa7635f3bdca96bdcd2ff/pyscard-2.3.1-cp313-cp313-macosx_10_13_universal2.whl", hash = "sha256:c11a596407e18cdcf16a4ccd8cdeaa55846d4f7ec2eefc529483e201f6906658", size = 170956, upload-time = "2025-10-29T15:53:32.072Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/ca/a1/508fc5733e2ce01a71c6abc94dae543311cf9d0962e309b0a78b4cb4031a/pyscard-2.3.1-cp313-cp313-macosx_15_0_x86_64.whl", hash = "sha256:72b1ab922fad5e050144ec72762e36741271b09d2389cda9b976b61ee0564e71", size = 138809, upload-time = "2025-10-29T15:49:06.528Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/18/a4/5481cd54f882ea61bfc334667f1e5126ac51124a464297dbe24592288b14/pyscard-2.3.1-cp313-cp313-win32.whl", hash = "sha256:a0b59d1961ff9fb15d980ad64edae13e4512b7e641ea8959e86133f34091aa5c", size = 139294, upload-time = "2025-10-29T15:53:35.805Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/8c/2b/c98e7bcf45958905d1bfdab59fe5acd67fe9ff0ad78145c4783886c38c84/pyscard-2.3.1-cp313-cp313-win_amd64.whl", hash = "sha256:df2b256bc719b701807114bdd179f7b303f309a954d5689188b088adfc33ead2", size = 145501, upload-time = "2025-10-29T15:53:33.549Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/93/a6/74cca0ec3c08f35c1a7468a8508d0e3989e63298d3a4b1f928542719aebc/pyscard-2.3.1-cp313-cp313-win_arm64.whl", hash = "sha256:f58b46cd78455a29a0abceabff21b37da81a385a737b29e6dd5e25acb7e3f3da", size = 140758, upload-time = "2025-10-29T15:53:34.542Z" },
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "pytest"
|
|
||||||
version = "9.0.3"
|
|
||||||
source = { registry = "https://pypi.org/simple" }
|
|
||||||
dependencies = [
|
|
||||||
{ name = "colorama", marker = "sys_platform == 'win32'" },
|
|
||||||
{ name = "iniconfig" },
|
|
||||||
{ name = "packaging" },
|
|
||||||
{ name = "pluggy" },
|
|
||||||
{ name = "pygments" },
|
|
||||||
]
|
|
||||||
sdist = { url = "https://files.pythonhosted.org/packages/7d/0d/549bd94f1a0a402dc8cf64563a117c0f3765662e2e668477624baeec44d5/pytest-9.0.3.tar.gz", hash = "sha256:b86ada508af81d19edeb213c681b1d48246c1a91d304c6c81a427674c17eb91c", size = 1572165, upload-time = "2026-04-07T17:16:18.027Z" }
|
|
||||||
wheels = [
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/d4/24/a372aaf5c9b7208e7112038812994107bc65a84cd00e0354a88c2c77a617/pytest-9.0.3-py3-none-any.whl", hash = "sha256:2c5efc453d45394fdd706ade797c0a81091eccd1d6e4bccfcd476e2b8e0ab5d9", size = 375249, upload-time = "2026-04-07T17:16:16.13Z" },
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "pytest-cov"
|
|
||||||
version = "7.1.0"
|
|
||||||
source = { registry = "https://pypi.org/simple" }
|
|
||||||
dependencies = [
|
|
||||||
{ name = "coverage" },
|
|
||||||
{ name = "pluggy" },
|
|
||||||
{ name = "pytest" },
|
|
||||||
]
|
|
||||||
sdist = { url = "https://files.pythonhosted.org/packages/b1/51/a849f96e117386044471c8ec2bd6cfebacda285da9525c9106aeb28da671/pytest_cov-7.1.0.tar.gz", hash = "sha256:30674f2b5f6351aa09702a9c8c364f6a01c27aae0c1366ae8016160d1efc56b2", size = 55592, upload-time = "2026-03-21T20:11:16.284Z" }
|
|
||||||
wheels = [
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/9d/7a/d968e294073affff457b041c2be9868a40c1c71f4a35fcc1e45e5493067b/pytest_cov-7.1.0-py3-none-any.whl", hash = "sha256:a0461110b7865f9a271aa1b51e516c9a95de9d696734a2f71e3e78f46e1d4678", size = 22876, upload-time = "2026-03-21T20:11:14.438Z" },
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "python-desfire"
|
name = "python-desfire"
|
||||||
version = "0.1.6"
|
version = "0.1.6"
|
||||||
@@ -1681,31 +1380,6 @@ wheels = [
|
|||||||
{ url = "https://files.pythonhosted.org/packages/79/62/b88e5879512c55b8ee979c666ee6902adc4ed05007226de266410ae27965/rignore-0.7.6-cp314-cp314t-win_arm64.whl", hash = "sha256:b83adabeb3e8cf662cabe1931b83e165b88c526fa6af6b3aa90429686e474896", size = 656035, upload-time = "2025-11-05T21:41:31.13Z" },
|
{ url = "https://files.pythonhosted.org/packages/79/62/b88e5879512c55b8ee979c666ee6902adc4ed05007226de266410ae27965/rignore-0.7.6-cp314-cp314t-win_arm64.whl", hash = "sha256:b83adabeb3e8cf662cabe1931b83e165b88c526fa6af6b3aa90429686e474896", size = 656035, upload-time = "2025-11-05T21:41:31.13Z" },
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "ruff"
|
|
||||||
version = "0.16.0"
|
|
||||||
source = { registry = "https://pypi.org/simple" }
|
|
||||||
sdist = { url = "https://files.pythonhosted.org/packages/4d/94/1e5e4967626faf12fa56999cd6222dff6992ceb086ad7945756baf70c7a7/ruff-0.16.0.tar.gz", hash = "sha256:e460aafd5495ec89efaa6ced2e4a9a581116451e1c88b9d37ef497e0f8e93982", size = 4790557, upload-time = "2026-07-23T19:11:30.981Z" }
|
|
||||||
wheels = [
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/4b/81/1c8818fee7ce1a04cd7d1b3172e0a8f8e4f1dc4feb7fc390e16daa8af323/ruff-0.16.0-py3-none-linux_armv6l.whl", hash = "sha256:e5115729eb08c585e5121978ba5d5b60caeae394ce21b9fb5e6cd33a1c6c9b1e", size = 10754633, upload-time = "2026-07-23T19:10:46.415Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/23/df/beaf59c09d68db84304d555f188b276a77132a5d5b0b67a5c762aa143628/ruff-0.16.0-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:3c954b1d580bfa035b41654f7858cc7e71d5fc3ac5b723dd62bd9133830ed522", size = 10969164, upload-time = "2026-07-23T19:10:50.271Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/42/ce/741cd197496a1abbf51352710fd15ed995d2a2be87189c1da26a450d6e83/ruff-0.16.0-py3-none-macosx_11_0_arm64.whl", hash = "sha256:e01c21d10eb1b29f47b7454e1f4056db9a3f0260c646aa88457c610291db9f81", size = 10488846, upload-time = "2026-07-23T19:10:52.639Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/52/2a/a2db8e88cade358f5cdcb05674a917751074109315d014eb6352d9a893f7/ruff-0.16.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:6e364e5ed22ed8dc05082fd78e35308618260907ac2d3c1d637b2e682415b6c9", size = 10889729, upload-time = "2026-07-23T19:10:54.89Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/42/65/62a771694ebd63029dc953e27dbad40e1588bd4860ff9fe881018fddaa49/ruff-0.16.0-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:d327b8fc113a1d4421a04f3839d3752057c8dd1ee320223a6f3f52d04ada462a", size = 10568275, upload-time = "2026-07-23T19:10:56.993Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/3f/e2/ced249fe8af5f086c5c58cc21cc3356d50f32f7401c5df87050c999620a7/ruff-0.16.0-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:a9b50c55e263103586b3dcf5f73d479eb8cb5fdb6098fec59a62891dab653717", size = 11385112, upload-time = "2026-07-23T19:10:59.615Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/87/0b/05154977a8fd69eeb6c103271f55403bfd8711f5c0f8ed07489d95a504e7/ruff-0.16.0-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:0ff4a79ce3ec0172f3241943835de1c4cb4e2dcd07f0f8c2d02603dbbbee4b17", size = 12207008, upload-time = "2026-07-23T19:11:02.154Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/fb/29/98225831a3a1eab0e02f4acc6ca6559a98611dcc68b6965ff4b7234627c1/ruff-0.16.0-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:e95c448fca1fb2a18372a9440926c5a6ee789639bb975c72e7ae6d0b04218ab4", size = 11650842, upload-time = "2026-07-23T19:11:04.557Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/91/66/6bd3cf90500653d55dc0ffc8507aa8300bd49d0214b2e8cb4d3fef2943ba/ruff-0.16.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:4f11a8d11010301d0a398a2fdef67691feca7294da6aef55e2150e8fa2cd520b", size = 11400718, upload-time = "2026-07-23T19:11:09.233Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/8e/a2/a54eb4eae05d66364050a5d3b8a9c5ef88196531b3cbe7109d873f87f819/ruff-0.16.0-py3-none-manylinux_2_31_riscv64.whl", hash = "sha256:48044c678e9cb8698246c99b14aaccfa6601dea7379eb48a6f8f73f7a6d86cd0", size = 11426177, upload-time = "2026-07-23T19:11:11.994Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/1a/be/16e3eea4b2a478a496919f5e36f17c4559e54620bd3bbac5d6affa068006/ruff-0.16.0-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:7aa0959bad8eb8bef50340154fc9b58678dae31fa4293afa38b44b6e552c0213", size = 10856126, upload-time = "2026-07-23T19:11:14.221Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/a2/84/252eb8b868a16eec7257c14f504f77537e734b2d69c762e639e588e304a3/ruff-0.16.0-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:28ea2b7df8ebf7f9da6b7d47b230ab48f387c0a29be3b474c4d0740e197bb9af", size = 10571208, upload-time = "2026-07-23T19:11:16.378Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/21/09/817a482f542f7570cbb4554b26e896610c7114f539b1d9e2d2145bf6bef6/ruff-0.16.0-py3-none-musllinux_1_2_i686.whl", hash = "sha256:33a3dfac8c35f81498dea9181bccc2f4c4bc8f1521a1dd9406e77643e0f0fb09", size = 11063329, upload-time = "2026-07-23T19:11:19.173Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/2e/23/9403c180ca1cb9b1f7335f5c3e5305c09d49ea5b345196682a36028bde4a/ruff-0.16.0-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:a5237a0bda500d30d81b8e07a6973a5cbc772864cbf746ae2f4e8a2e01c9f4ed", size = 11489751, upload-time = "2026-07-23T19:11:21.74Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/b2/1d/1b2ef7bcde851c78d7f17f1cca13fd6dc695fc4b3d6197941e72cae5b132/ruff-0.16.0-py3-none-win32.whl", hash = "sha256:7fab76fa065c873f41ff744347c6e77bcc3dfec4bcc754dc26b63d23c0f7f5fb", size = 10785885, upload-time = "2026-07-23T19:11:23.947Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/b2/a3/d5e4ef7a56be3f928ffb90b94c25ba7d3cb9c7fe0736aeaaedf361770712/ruff-0.16.0-py3-none-win_amd64.whl", hash = "sha256:429c117f022bf481fabd9d551e7a3952b24c65e6ef44337ea09d90bebef14472", size = 11923141, upload-time = "2026-07-23T19:11:26.409Z" },
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/cb/9a/8415f2657cbe200f41a4531ccededf135505a92d4a012229121f885b26f9/ruff-0.16.0-py3-none-win_arm64.whl", hash = "sha256:14296fedcd2705c77ab8235439278bbb38f285cf7da5528b00b3e330c3d4872d", size = 11273407, upload-time = "2026-07-23T19:11:28.705Z" },
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "secretstorage"
|
name = "secretstorage"
|
||||||
version = "3.5.0"
|
version = "3.5.0"
|
||||||
@@ -1732,15 +1406,6 @@ wheels = [
|
|||||||
{ url = "https://files.pythonhosted.org/packages/fa/eb/d875669993b762556ae8b2efd86219943b4c0864d22204d622a9aee3052b/sentry_sdk-2.58.0-py2.py3-none-any.whl", hash = "sha256:688d1c704ddecf382ea3326f21a67453d4caa95592d722b7c780a36a9d23109e", size = 460919, upload-time = "2026-04-13T17:23:24.675Z" },
|
{ url = "https://files.pythonhosted.org/packages/fa/eb/d875669993b762556ae8b2efd86219943b4c0864d22204d622a9aee3052b/sentry_sdk-2.58.0-py2.py3-none-any.whl", hash = "sha256:688d1c704ddecf382ea3326f21a67453d4caa95592d722b7c780a36a9d23109e", size = 460919, upload-time = "2026-04-13T17:23:24.675Z" },
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "setuptools"
|
|
||||||
version = "82.0.1"
|
|
||||||
source = { registry = "https://pypi.org/simple" }
|
|
||||||
sdist = { url = "https://files.pythonhosted.org/packages/4f/db/cfac1baf10650ab4d1c111714410d2fbb77ac5a616db26775db562c8fab2/setuptools-82.0.1.tar.gz", hash = "sha256:7d872682c5d01cfde07da7bccc7b65469d3dca203318515ada1de5eda35efbf9", size = 1152316, upload-time = "2026-03-09T12:47:17.221Z" }
|
|
||||||
wheels = [
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/9d/76/f789f7a86709c6b087c5a2f52f911838cad707cc613162401badc665acfe/setuptools-82.0.1-py3-none-any.whl", hash = "sha256:a59e362652f08dcd477c78bb6e7bd9d80a7995bc73ce773050228a348ce2e5bb", size = 1006223, upload-time = "2026-03-09T12:47:15.026Z" },
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "shellingham"
|
name = "shellingham"
|
||||||
version = "1.5.4"
|
version = "1.5.4"
|
||||||
@@ -2056,15 +1721,6 @@ wheels = [
|
|||||||
{ url = "https://files.pythonhosted.org/packages/fd/19/4b4e3e2ea5fa213ff4220e84450628fecde042b0961e7b4e6d845e555ade/xattr-1.3.0-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:1e6c216927b16fd4b72df655d5124b69b2a406cb3132b5231179021182f0f0d1", size = 19023, upload-time = "2025-10-13T22:16:34.395Z" },
|
{ url = "https://files.pythonhosted.org/packages/fd/19/4b4e3e2ea5fa213ff4220e84450628fecde042b0961e7b4e6d845e555ade/xattr-1.3.0-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:1e6c216927b16fd4b72df655d5124b69b2a406cb3132b5231179021182f0f0d1", size = 19023, upload-time = "2025-10-13T22:16:34.395Z" },
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "zipp"
|
|
||||||
version = "4.1.0"
|
|
||||||
source = { registry = "https://pypi.org/simple" }
|
|
||||||
sdist = { url = "https://files.pythonhosted.org/packages/b9/d8/eab98a517c14134c0b2eb4e2387bc5f457334293ec5d2dd3857ec2966802/zipp-4.1.0.tar.gz", hash = "sha256:4cb57381f544315db7688e976e922a2b18cdb513d21cc194eb42232ba2a3e602", size = 26214, upload-time = "2026-05-18T20:08:57.967Z" }
|
|
||||||
wheels = [
|
|
||||||
{ url = "https://files.pythonhosted.org/packages/3a/13/547360d81e6d88d58492968ffda9f9542854f11310ee556fef14260cc886/zipp-4.1.0-py3-none-any.whl", hash = "sha256:25ad4e16390cd314347dd8f1de67a2ac538ae658ed4ab9db16029c07c188e97f", size = 10238, upload-time = "2026-05-18T20:08:57.045Z" },
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zstandard"
|
name = "zstandard"
|
||||||
version = "0.25.0"
|
version = "0.25.0"
|
||||||
|
|||||||
Reference in New Issue
Block a user