hinbert-fastapi 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- app/__init__.py +8 -0
- app/api/__init__.py +1 -0
- app/api/deps/__init__.py +1 -0
- app/api/deps/auth.py +40 -0
- app/api/deps/pagination.py +8 -0
- app/api/v1/__init__.py +1 -0
- app/api/v1/endpoints/__init__.py +1 -0
- app/api/v1/endpoints/auth.py +255 -0
- app/api/v1/endpoints/dashboard.py +23 -0
- app/api/v1/endpoints/products.py +102 -0
- app/api/v1/endpoints/users.py +89 -0
- app/api/v1/routers/__init__.py +1 -0
- app/api/v1/routers/api_router.py +11 -0
- app/core/__init__.py +1 -0
- app/core/config/__init__.py +1 -0
- app/core/config/database.py +13 -0
- app/core/config/settings.py +83 -0
- app/core/exceptions/__init__.py +1 -0
- app/core/exceptions/base_exception.py +9 -0
- app/core/exceptions/custom_exceptions.py +17 -0
- app/core/middleware/__init__.py +1 -0
- app/core/middleware/cors.py +5 -0
- app/core/middleware/error_handler.py +23 -0
- app/core/middleware/logging.py +29 -0
- app/core/middleware/rate_limit.py +27 -0
- app/core/security/__init__.py +1 -0
- app/core/security/auth.py +8 -0
- app/core/security/jwt.py +33 -0
- app/core/security/oauth.py +8 -0
- app/core/security/password.py +18 -0
- app/core/security/totp.py +13 -0
- app/db/__init__.py +1 -0
- app/db/base.py +7 -0
- app/db/migrations/env.py +39 -0
- app/db/migrations/versions/97ed1bc05f4a_complete_product_and_totp_fields.py +49 -0
- app/db/migrations/versions/f8b632aa11da_initial_migration.py +113 -0
- app/db/session.py +11 -0
- app/main.py +50 -0
- app/models/__init__.py +10 -0
- app/models/domain/__init__.py +1 -0
- app/models/domain/base.py +20 -0
- app/models/domain/email_verification.py +24 -0
- app/models/domain/password_reset.py +24 -0
- app/models/domain/product.py +22 -0
- app/models/domain/refresh_token.py +24 -0
- app/models/domain/totp_secret.py +44 -0
- app/models/domain/user.py +34 -0
- app/models/schemas/__init__.py +1 -0
- app/models/schemas/auth.py +30 -0
- app/models/schemas/password.py +16 -0
- app/models/schemas/product.py +31 -0
- app/models/schemas/response.py +17 -0
- app/models/schemas/token.py +17 -0
- app/models/schemas/totp.py +16 -0
- app/models/schemas/user.py +37 -0
- app/repositories/__init__.py +1 -0
- app/repositories/base/__init__.py +1 -0
- app/repositories/base/base_repository.py +51 -0
- app/repositories/email_verification_repository.py +37 -0
- app/repositories/password_reset_repository.py +33 -0
- app/repositories/product_repository.py +40 -0
- app/repositories/refresh_token_repository.py +40 -0
- app/repositories/totp_secret_repository.py +23 -0
- app/repositories/user_repository.py +44 -0
- app/services/__init__.py +1 -0
- app/services/auth_service.py +32 -0
- app/services/base/__init__.py +1 -0
- app/services/base/base_service.py +21 -0
- app/services/email_service.py +32 -0
- app/services/product_service.py +24 -0
- app/services/social_auth_service.py +47 -0
- app/services/totp_service.py +13 -0
- app/services/user_service.py +27 -0
- app/tests/__init__.py +1 -0
- app/tests/conftest.py +36 -0
- app/tests/integration/test_auth_api.py +115 -0
- app/tests/integration/test_product_api.py +58 -0
- app/tests/integration/test_user_api.py +68 -0
- app/tests/unit/test_auth_service.py +48 -0
- app/tests/unit/test_product_service.py +33 -0
- app/tests/unit/test_user_service.py +32 -0
- app/utils/__init__.py +1 -0
- app/utils/date_utils.py +8 -0
- app/utils/file_utils.py +8 -0
- app/utils/logger.py +11 -0
- app/utils/validators.py +13 -0
- hinbert_fastapi-0.1.0.dist-info/METADATA +0 -0
- hinbert_fastapi-0.1.0.dist-info/RECORD +96 -0
- hinbert_fastapi-0.1.0.dist-info/WHEEL +5 -0
- hinbert_fastapi-0.1.0.dist-info/entry_points.txt +5 -0
- hinbert_fastapi-0.1.0.dist-info/licenses/LICENSE +21 -0
- hinbert_fastapi-0.1.0.dist-info/top_level.txt +2 -0
- scripts/__init__.py +1 -0
- scripts/create_admin.py +41 -0
- scripts/run_migrations.py +13 -0
- scripts/seed_data.py +44 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Hinbert Engineering
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
scripts/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Command-line entry points for administration, seeding, and migrations."""
|
scripts/create_admin.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"""Create an administrator through an interactive, non-echoed password prompt."""
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import asyncio
|
|
5
|
+
import getpass
|
|
6
|
+
|
|
7
|
+
from app.core.config.database import SessionLocal
|
|
8
|
+
from app.core.security.password import hash_password
|
|
9
|
+
from app.models.domain.user import User
|
|
10
|
+
from app.repositories.user_repository import create, get_by_email
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
async def create_admin(email: str, full_name: str, password: str) -> User:
|
|
14
|
+
"""Create an administrator or fail when the normalized email already exists."""
|
|
15
|
+
async with SessionLocal() as session:
|
|
16
|
+
if await get_by_email(session, email):
|
|
17
|
+
raise ValueError("A user with this email already exists")
|
|
18
|
+
return await create(
|
|
19
|
+
session,
|
|
20
|
+
User(
|
|
21
|
+
email=email.lower(),
|
|
22
|
+
full_name=full_name,
|
|
23
|
+
password_hash=hash_password(password),
|
|
24
|
+
is_admin=True,
|
|
25
|
+
is_verified=True,
|
|
26
|
+
),
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def main() -> None:
|
|
31
|
+
"""Parse CLI input and execute the asynchronous administrator workflow."""
|
|
32
|
+
parser = argparse.ArgumentParser(description="Create an Hinbert FastAPI administrator")
|
|
33
|
+
parser.add_argument("--email", required=True)
|
|
34
|
+
parser.add_argument("--full-name", required=True)
|
|
35
|
+
args = parser.parse_args()
|
|
36
|
+
password = getpass.getpass("Password: ")
|
|
37
|
+
asyncio.run(create_admin(args.email, args.full_name, password))
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
if __name__ == "__main__":
|
|
41
|
+
main()
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"""Run Alembic migrations from deployment automation."""
|
|
2
|
+
|
|
3
|
+
from alembic import command
|
|
4
|
+
from alembic.config import Config
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def main() -> None:
|
|
8
|
+
"""Upgrade the configured database to the latest revision."""
|
|
9
|
+
command.upgrade(Config("alembic.ini"), "head")
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
if __name__ == "__main__":
|
|
13
|
+
main()
|
scripts/seed_data.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"""Idempotently populate a development database with demo users and products."""
|
|
2
|
+
|
|
3
|
+
import asyncio
|
|
4
|
+
from decimal import Decimal
|
|
5
|
+
|
|
6
|
+
from sqlalchemy import select
|
|
7
|
+
|
|
8
|
+
from app.core.config.database import SessionLocal
|
|
9
|
+
from app.core.config.settings import get_settings
|
|
10
|
+
from app.core.security.password import hash_password
|
|
11
|
+
from app.models.domain.product import Product
|
|
12
|
+
from app.models.domain.user import User
|
|
13
|
+
from app.repositories.product_repository import ProductRepository
|
|
14
|
+
from app.repositories.user_repository import create as create_user
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
async def seed() -> None:
|
|
18
|
+
"""Create safe demo records only when the configured environment is development."""
|
|
19
|
+
if get_settings().environment != "development":
|
|
20
|
+
raise RuntimeError("Refusing to seed a non-development environment")
|
|
21
|
+
async with SessionLocal() as session:
|
|
22
|
+
if await session.scalar(select(User).where(User.email == "demo@example.com")) is None:
|
|
23
|
+
await create_user(
|
|
24
|
+
session,
|
|
25
|
+
User(
|
|
26
|
+
email="demo@example.com",
|
|
27
|
+
full_name="Demo User",
|
|
28
|
+
password_hash=hash_password("DemoPassword!123"),
|
|
29
|
+
is_verified=True,
|
|
30
|
+
),
|
|
31
|
+
)
|
|
32
|
+
if await session.scalar(select(Product).where(Product.name == "Demo Product")) is None:
|
|
33
|
+
await ProductRepository(session).create(
|
|
34
|
+
Product(name="Demo Product", description="Development-only sample", price=Decimal("19.99"))
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def main() -> None:
|
|
39
|
+
"""Run the asynchronous seed workflow."""
|
|
40
|
+
asyncio.run(seed())
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
if __name__ == "__main__":
|
|
44
|
+
main()
|