chore: restructure project directory and update Dockerfile paths
Build and Push to Registry / build (push) Successful in 8s
Build and Push to Registry / build (push) Successful in 8s
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
from fastapi import APIRouter
|
||||
|
||||
router = APIRouter(
|
||||
prefix="/proxy",
|
||||
tags=["Proxy"]
|
||||
)
|
||||
|
||||
|
||||
@router.get("/")
|
||||
async def list_proxies():
|
||||
return
|
||||
|
||||
|
||||
@router.post("/")
|
||||
async def create_proxy():
|
||||
return
|
||||
|
||||
|
||||
@router.put("/{proxy_port}/")
|
||||
async def edit_proxy():
|
||||
return
|
||||
@@ -0,0 +1,11 @@
|
||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
|
||||
class Settings(BaseSettings):
|
||||
model_config = SettingsConfigDict(env_file=".env", env_file_encoding="utf-8", case_sensitive=False, extra="ignore")
|
||||
|
||||
MONGODB_URI: str
|
||||
MONGODB_DB_NAME: str
|
||||
REDIS_URL: str
|
||||
|
||||
|
||||
settings = Settings()
|
||||
@@ -0,0 +1,24 @@
|
||||
from motor.motor_asyncio import AsyncIOMotorClient, AsyncIOMotorDatabase
|
||||
|
||||
from core.config import settings
|
||||
|
||||
|
||||
class _MongoDB:
|
||||
client: AsyncIOMotorClient | None = None
|
||||
|
||||
def get_database(self) -> AsyncIOMotorDatabase:
|
||||
if self.client is None:
|
||||
raise RuntimeError("MongoDB client has not been initialized")
|
||||
return self.client[settings.MONGODB_DB_NAME]
|
||||
|
||||
mongodb = _MongoDB()
|
||||
|
||||
async def get_database() -> AsyncIOMotorDatabase:
|
||||
return mongodb.get_database()
|
||||
|
||||
|
||||
async def ensure_mongodb_available() -> None:
|
||||
client = mongodb.client
|
||||
if client is None:
|
||||
raise RuntimeError("MongoDB client has not been initialized")
|
||||
await client.admin.command("ping")
|
||||
@@ -0,0 +1,22 @@
|
||||
import redis.asyncio as aioredis
|
||||
|
||||
from core.config import settings
|
||||
|
||||
_redis_pool: aioredis.Redis | None = None
|
||||
|
||||
async def init_redis() -> None:
|
||||
global _redis_pool
|
||||
_redis_pool = aioredis.from_url(
|
||||
settings.REDIS_URL, encoding="utf-8", decode_responses=True
|
||||
)
|
||||
|
||||
|
||||
async def close_redis() -> None:
|
||||
if _redis_pool:
|
||||
await _redis_pool.aclose()
|
||||
|
||||
|
||||
async def get_redis() -> aioredis.Redis:
|
||||
if _redis_pool is None:
|
||||
raise RuntimeError("Redis pool has not been initialized")
|
||||
return _redis_pool
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
from fastapi import FastAPI
|
||||
|
||||
from api.proxy import router as proxy_router
|
||||
|
||||
app = FastAPI(
|
||||
title="thePlugAPI"
|
||||
)
|
||||
|
||||
app.include_router(proxy_router)
|
||||
|
||||
|
||||
@app.get("/")
|
||||
async def root():
|
||||
return {"Hello": "World!"}
|
||||
@@ -0,0 +1,8 @@
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from models.service import ServiceDocument
|
||||
|
||||
|
||||
class ProxyDocument(BaseModel):
|
||||
port: int = Field(..., description="Port number of the proxy")
|
||||
service: ServiceDocument = Field(..., description="Associated service details")
|
||||
@@ -0,0 +1,6 @@
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
class ServiceDocument(BaseModel):
|
||||
name: str = Field(..., description="Name of the service")
|
||||
port: int = Field(..., description="Port number of the service")
|
||||
category: str = Field(..., description="Category of the service (e.g., web, pwn, etc.)")
|
||||
@@ -0,0 +1,10 @@
|
||||
from utils.proxy.types import ServiceConfig
|
||||
|
||||
|
||||
async def create_proxy(
|
||||
port: int,
|
||||
name: str,
|
||||
service: ServiceConfig,
|
||||
code: str
|
||||
):
|
||||
return
|
||||
@@ -0,0 +1,6 @@
|
||||
from typing import TypedDict
|
||||
|
||||
|
||||
class ServiceConfig(TypedDict):
|
||||
address: str
|
||||
port: int
|
||||
Reference in New Issue
Block a user