mirror of
https://github.com/creyD/apilog.git
synced 2026-04-13 03:40:30 +02:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| dafdf34f71 | |||
| e77fe115c6 | |||
| 6ab1eafe1d | |||
| 256e2adbf7 | |||
| 7c0d0da511 | |||
|
|
4f793585e5 | ||
|
|
98df462b61 | ||
| 6db2b3e14e | |||
| 22eaed8a75 | |||
|
|
4d0ecb2ee8 | ||
| 88e97faddb |
5
.github/workflows/ci.yml
vendored
5
.github/workflows/ci.yml
vendored
@@ -5,6 +5,7 @@ on:
|
|||||||
branches:
|
branches:
|
||||||
- dev
|
- dev
|
||||||
- master
|
- master
|
||||||
|
- renovate/**
|
||||||
paths-ignore:
|
paths-ignore:
|
||||||
- "**/.github/**"
|
- "**/.github/**"
|
||||||
- "**/.gitignore"
|
- "**/.gitignore"
|
||||||
@@ -13,6 +14,10 @@ on:
|
|||||||
- "**/CHANGELOG.md"
|
- "**/CHANGELOG.md"
|
||||||
- "**/docs/**"
|
- "**/docs/**"
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- dev
|
||||||
|
- master
|
||||||
|
|
||||||
env:
|
env:
|
||||||
REGISTRY: ghcr.io
|
REGISTRY: ghcr.io
|
||||||
|
|||||||
18
Dockerfile
18
Dockerfile
@@ -1,9 +1,15 @@
|
|||||||
FROM python:3.12-slim
|
FROM python:3.12-slim
|
||||||
ARG VERSION=unkown
|
ARG VERSION=unknown
|
||||||
|
|
||||||
|
# Create a non-root user and group
|
||||||
|
RUN groupadd -r appuser && useradd -r -g appuser appuser
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
|
# Change ownership of the application directory
|
||||||
|
RUN chown -R appuser:appuser /app
|
||||||
|
|
||||||
# Python setup
|
# Python setup
|
||||||
ENV PYTHONDONTWRITEBYTECODE=1
|
ENV PYTHONDONTWRITEBYTECODE=1
|
||||||
ENV PYTHONUNBUFFERED=1
|
ENV PYTHONUNBUFFERED=1
|
||||||
@@ -12,13 +18,19 @@ ENV ENV=DEV
|
|||||||
|
|
||||||
# Install dependencies
|
# Install dependencies
|
||||||
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
||||||
RUN pip install 'uvicorn[standard]'
|
|
||||||
|
# Switch to the non-root user
|
||||||
|
USER appuser
|
||||||
|
|
||||||
EXPOSE 9000
|
EXPOSE 9000
|
||||||
CMD ["uvicorn", "app.main:app", "--workers", "6" , "--host", "0.0.0.0", "--port", "9000"]
|
CMD ["uvicorn", "app.main:app", "--workers", "6" , "--host", "0.0.0.0", "--port", "9000"]
|
||||||
|
|
||||||
# Install curl
|
# Install curl
|
||||||
RUN apt-get update && apt-get install -y curl && apt-get clean
|
USER root
|
||||||
|
RUN apt-get update && apt-get install -y --no-install-recommends curl && apt-get clean
|
||||||
|
|
||||||
|
# Switch back to the non-root user
|
||||||
|
USER appuser
|
||||||
|
|
||||||
HEALTHCHECK --interval=30s --timeout=10s --retries=5 \
|
HEALTHCHECK --interval=30s --timeout=10s --retries=5 \
|
||||||
CMD curl --fail http://localhost:9000/openapi.json || exit 1
|
CMD curl --fail http://localhost:9000/openapi.json || exit 1
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ from uuid import UUID
|
|||||||
from pydantic.json_schema import SkipJsonSchema
|
from pydantic.json_schema import SkipJsonSchema
|
||||||
from fastapi_filters import FilterValues, create_filters
|
from fastapi_filters import FilterValues, create_filters
|
||||||
from fastapi_filters.ext.sqlalchemy import apply_filters
|
from fastapi_filters.ext.sqlalchemy import apply_filters
|
||||||
|
from app.models.entry import LogType, TransactionType
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
router = APIRouter(prefix="/log", tags=["logging"])
|
router = APIRouter(prefix="/log", tags=["logging"])
|
||||||
|
|
||||||
@@ -62,10 +64,6 @@ async def get_log(
|
|||||||
return LogOUT.model_validate(obj)
|
return LogOUT.model_validate(obj)
|
||||||
|
|
||||||
|
|
||||||
from app.models.entry import LogType, TransactionType
|
|
||||||
from datetime import datetime
|
|
||||||
|
|
||||||
|
|
||||||
@router.get("/")
|
@router.get("/")
|
||||||
async def get_logs(
|
async def get_logs(
|
||||||
search: str | SkipJsonSchema[None] = None,
|
search: str | SkipJsonSchema[None] = None,
|
||||||
@@ -94,3 +92,37 @@ async def get_logs(
|
|||||||
LogEntry.message.ilike(f"%{search}%") | LogEntry.author.ilike(f"%{search}%")
|
LogEntry.message.ilike(f"%{search}%") | LogEntry.author.ilike(f"%{search}%")
|
||||||
)
|
)
|
||||||
return paginate(db, order_by_query(the_select))
|
return paginate(db, order_by_query(the_select))
|
||||||
|
|
||||||
|
|
||||||
|
@router.delete("/", status_code=200, operation_id="log_delete_many")
|
||||||
|
async def delete_logs(
|
||||||
|
application: UUID,
|
||||||
|
environment: str | SkipJsonSchema[None] = None,
|
||||||
|
l_type: LogType | SkipJsonSchema[None] = None,
|
||||||
|
t_type: TransactionType | SkipJsonSchema[None] = None,
|
||||||
|
object_reference: str | SkipJsonSchema[None] = None,
|
||||||
|
author: str | SkipJsonSchema[None] = None,
|
||||||
|
sub: str = Security(verify),
|
||||||
|
db: Session = Depends(get_db),
|
||||||
|
) -> int:
|
||||||
|
filters = {
|
||||||
|
"application": application,
|
||||||
|
"created_by_id": sub,
|
||||||
|
}
|
||||||
|
|
||||||
|
if environment is not None:
|
||||||
|
filters["environment"] = environment
|
||||||
|
if l_type is not None:
|
||||||
|
filters["l_type"] = l_type
|
||||||
|
if t_type is not None:
|
||||||
|
filters["t_type"] = t_type
|
||||||
|
if object_reference is not None:
|
||||||
|
filters["object_reference"] = object_reference
|
||||||
|
if author is not None:
|
||||||
|
filters["author"] = author
|
||||||
|
|
||||||
|
query = db.query(LogEntry).filter_by(**filters)
|
||||||
|
the_impact = query.count()
|
||||||
|
query.delete(synchronize_session=False)
|
||||||
|
db.commit()
|
||||||
|
return the_impact
|
||||||
|
|||||||
@@ -239,3 +239,24 @@ class TestAPI:
|
|||||||
re = self.c.get("/log/?application=" + app_id + "&environment=prod")
|
re = self.c.get("/log/?application=" + app_id + "&environment=prod")
|
||||||
assert re["total"] == 2
|
assert re["total"] == 2
|
||||||
assert len(re["results"]) == 2
|
assert len(re["results"]) == 2
|
||||||
|
|
||||||
|
def test_logging_delete(self):
|
||||||
|
with log_examples(self) as app_id:
|
||||||
|
re = self.c.delete("/log/?application=" + str(app_id) + "&environment=prod", r_code=200)
|
||||||
|
assert re == 2
|
||||||
|
|
||||||
|
re = self.c.get("/log/?application=" + str(app_id) + "&environment=prod")
|
||||||
|
assert re["total"] == 0
|
||||||
|
|
||||||
|
re = self.c.get("/log/?application=" + str(app_id) + "&environment=dev")
|
||||||
|
assert re["total"] == 3
|
||||||
|
|
||||||
|
# clear complete application
|
||||||
|
re = self.c.get("/log/?application=" + str(app_id))
|
||||||
|
assert re["total"] == 3
|
||||||
|
|
||||||
|
re = self.c.delete("/log/?application=" + str(app_id), r_code=200)
|
||||||
|
assert re == 3
|
||||||
|
|
||||||
|
re = self.c.get("/log/?application=" + str(app_id))
|
||||||
|
assert re["total"] == 0
|
||||||
|
|||||||
12
renovate.json
Normal file
12
renovate.json
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||||
|
"extends": ["config:recommended", ":semanticCommitTypeAll(feat)"],
|
||||||
|
"packageRules": [
|
||||||
|
{
|
||||||
|
"automerge": true,
|
||||||
|
"description": "Automerge non-major updates",
|
||||||
|
"matchUpdateTypes": ["minor", "patch"],
|
||||||
|
"automergeType": "branch"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
annotated-types==0.7.0
|
annotated-types==0.7.0
|
||||||
anyio==4.6.0
|
anyio==4.6.2.post1
|
||||||
certifi==2024.8.30
|
certifi==2024.8.30
|
||||||
creyPY==1.2.5
|
creyPY==1.2.5
|
||||||
fastapi==0.115.0
|
fastapi==0.115.5
|
||||||
fastapi-pagination==0.12.31
|
fastapi-pagination==0.12.31
|
||||||
h11==0.14.0
|
h11==0.14.0
|
||||||
httpcore==1.0.6
|
httpcore==1.0.6
|
||||||
@@ -16,7 +16,7 @@ pydantic_core==2.23.4
|
|||||||
python-dotenv==1.0.1
|
python-dotenv==1.0.1
|
||||||
sniffio==1.3.1
|
sniffio==1.3.1
|
||||||
SQLAlchemy==2.0.35
|
SQLAlchemy==2.0.35
|
||||||
starlette==0.38.6
|
starlette==0.40.0
|
||||||
typing_extensions==4.12.2
|
typing_extensions==4.12.2
|
||||||
|
|
||||||
Mako==1.3.5 # Alembic
|
Mako==1.3.5 # Alembic
|
||||||
|
|||||||
Reference in New Issue
Block a user