mirror of
https://github.com/outbackdingo/step-ca-webui.git
synced 2026-01-27 10:20:25 +00:00
errors fixed, docs regenerated
This commit is contained in:
@@ -170,4 +170,5 @@ project_root/
|
||||
|
||||
# TODO
|
||||
- [ ] Adjust class diagram after finalizing the project
|
||||
- [ ] Prevent simultaneous actions calls
|
||||
- [ ] Prevent simultaneous actions calls
|
||||
- [ ] Add 'default' error values to the API spec (plaintext response)
|
||||
@@ -1,6 +1,3 @@
|
||||
import threading
|
||||
import uuid
|
||||
from contextlib import contextmanager
|
||||
from typing import List, Union
|
||||
|
||||
import uvicorn
|
||||
@@ -8,6 +5,7 @@ from fastapi import FastAPI, Query, HTTPException, Request
|
||||
from fastapi.responses import PlainTextResponse
|
||||
|
||||
from core.certificate_manager import CertificateManager
|
||||
from core.trace_id_handler import TraceIdHandler
|
||||
from shared.api_models import (
|
||||
Certificate,
|
||||
CertificateGenerateRequest,
|
||||
@@ -37,8 +35,7 @@ class APIServer:
|
||||
redoc_url="/redoc",
|
||||
servers=[
|
||||
{"url": f"http://localhost:{port}", "description": "Local development environment"},
|
||||
{"url": prod_url, "description": "Production environment"} if prod_url else None
|
||||
]
|
||||
] + [{"url": prod_url, "description": "Production environment"}] if prod_url else []
|
||||
)
|
||||
|
||||
self._setup_routes()
|
||||
@@ -116,7 +113,7 @@ class APIServer:
|
||||
revocationDate=cert["revocationDate"]
|
||||
)
|
||||
|
||||
@self._app.post("/logs/single", response_model=LogEntry)
|
||||
@self._app.get("/logs/single", response_model=LogEntry)
|
||||
async def get_log_entry(logId: int = Query(..., gt=0)):
|
||||
log_entry = self._logger.get_log_entry(logId)
|
||||
if not log_entry:
|
||||
@@ -156,20 +153,3 @@ class APIServer:
|
||||
traceId=log.trace_id,
|
||||
commandInfo=log.command_info
|
||||
)
|
||||
|
||||
|
||||
class TraceIdHandler:
|
||||
_thread_local = threading.local()
|
||||
|
||||
@staticmethod
|
||||
@contextmanager
|
||||
def logging_scope():
|
||||
TraceIdHandler._thread_local.trace_id = uuid.uuid4()
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
del TraceIdHandler._thread_local.trace_id
|
||||
|
||||
@staticmethod
|
||||
def get_current_trace_id() -> uuid.UUID | None:
|
||||
return getattr(TraceIdHandler._thread_local, 'trace_id', None)
|
||||
|
||||
@@ -5,5 +5,5 @@ from shared.logger import Logger
|
||||
if __name__ == "__main__":
|
||||
logger = Logger("step-ca-webui.log")
|
||||
certificate_manager = CertificateManager(logger)
|
||||
api_server = APIServer(certificate_manager, logger, "0.1.0", 5000)
|
||||
api_server = APIServer(certificate_manager, logger, "0.0.1", 5000)
|
||||
api_server.run()
|
||||
|
||||
20
core/trace_id_handler.py
Normal file
20
core/trace_id_handler.py
Normal file
@@ -0,0 +1,20 @@
|
||||
import threading
|
||||
import uuid
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
|
||||
class TraceIdHandler:
|
||||
_thread_local = threading.local()
|
||||
|
||||
@staticmethod
|
||||
@asynccontextmanager
|
||||
async def logging_scope():
|
||||
TraceIdHandler._thread_local.trace_id = uuid.uuid4()
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
del TraceIdHandler._thread_local.trace_id
|
||||
|
||||
@staticmethod
|
||||
def get_current_trace_id() -> uuid.UUID | None:
|
||||
return getattr(TraceIdHandler._thread_local, 'trace_id', None)
|
||||
@@ -1,8 +1,8 @@
|
||||
openapi: 3.1.0
|
||||
info:
|
||||
title: FastAPI
|
||||
version: 0.1.0
|
||||
|
||||
title: Step-CA Management API
|
||||
description: API for managing step-ca Certificate Authority
|
||||
version: 0.0.1
|
||||
paths:
|
||||
/certificates:
|
||||
get:
|
||||
@@ -33,13 +33,6 @@ paths:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/HTTPValidationError'
|
||||
'default':
|
||||
description: Error
|
||||
content:
|
||||
text/plain:
|
||||
schema:
|
||||
type: string
|
||||
|
||||
/certificates/generate:
|
||||
post:
|
||||
summary: Generate Certificate
|
||||
@@ -211,16 +204,16 @@ components:
|
||||
status:
|
||||
type: string
|
||||
title: Status
|
||||
expiration_date:
|
||||
expirationDate:
|
||||
type: string
|
||||
format: date-time
|
||||
title: Expiration Date
|
||||
title: Expirationdate
|
||||
type: object
|
||||
required:
|
||||
- id
|
||||
- name
|
||||
- status
|
||||
- expiration_date
|
||||
- expirationDate
|
||||
title: Certificate
|
||||
CertificateGenerateRequest:
|
||||
properties:
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
from typing import List, Optional
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ from datetime import datetime
|
||||
from typing import Dict, List, Optional
|
||||
from uuid import UUID
|
||||
|
||||
from core.api_server import TraceIdHandler
|
||||
from core.trace_id_handler import TraceIdHandler
|
||||
from .models import LogEntry, LogSeverity, CommandInfo
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user