tweak(platform): Disable docs endpoint when not local (#8265)

* disable docs endpoint

* add to .env.example

* use enum for app env

* lint
This commit is contained in:
Aarushi 2024-10-08 10:31:08 +01:00 committed by GitHub
parent 61f1d0cdb5
commit 2aed470d26
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 22 additions and 2 deletions

View File

@ -98,3 +98,5 @@ ENABLE_CLOUD_LOGGING=false
ENABLE_FILE_LOGGING=false
# Use to manually set the log directory
# LOG_DIR=./logs
APP_ENV=local

View File

@ -51,6 +51,7 @@ class AgentServer(AppService):
await db.disconnect()
def run_service(self):
docs_url = "/docs" if settings.config.app_env == "local" else None
app = FastAPI(
title="AutoGPT Agent Server",
description=(
@ -60,6 +61,7 @@ class AgentServer(AppService):
summary="AutoGPT Agent Server",
version="0.1",
lifespan=self.lifespan,
docs_url=docs_url,
)
if self._test_dependency_overrides:

View File

@ -28,6 +28,7 @@ async def lifespan(app: FastAPI):
event_queue.close()
docs_url = "/docs" if settings.config.app_env == "local" else None
app = FastAPI(lifespan=lifespan)
event_queue = RedisEventQueue()
_connection_manager = None

View File

@ -1,5 +1,6 @@
import json
import os
from enum import Enum
from typing import Any, Dict, Generic, List, Set, Tuple, Type, TypeVar
from pydantic import BaseModel, Field, PrivateAttr, field_validator
@ -15,6 +16,12 @@ from backend.util.data import get_config_path, get_data_path, get_secrets_path
T = TypeVar("T", bound=BaseSettings)
class AppEnvironment(str, Enum):
LOCAL = "local"
DEVELOPMENT = "dev"
PRODUCTION = "prod"
class UpdateTrackingModel(BaseModel, Generic[T]):
_updated_fields: Set[str] = PrivateAttr(default_factory=set)
@ -121,6 +128,11 @@ class Config(UpdateTrackingModel["Config"], BaseSettings):
"This value is then used to generate redirect URLs for OAuth flows.",
)
app_env: AppEnvironment = Field(
default=AppEnvironment.LOCAL,
description="The name of the app environment.",
)
backend_cors_allow_origins: List[str] = Field(default_factory=list)
@field_validator("backend_cors_allow_origins")

View File

@ -7,4 +7,6 @@ SENTRY_DSN=https://11d0640fef35640e0eb9f022eb7d7626@o4505260022104064.ingest.us.
ENABLE_AUTH=true
SUPABASE_JWT_SECRET=our-super-secret-jwt-token-with-at-least-32-characters-long
BACKEND_CORS_ALLOW_ORIGINS="http://localhost:3000,http://127.0.0.1:3000"
BACKEND_CORS_ALLOW_ORIGINS="http://localhost:3000,http://127.0.0.1:3000"
APP_ENV=local

View File

@ -49,7 +49,7 @@ async def lifespan(app: fastapi.FastAPI):
yield
await db_client.disconnect()
docs_url = "/docs" if os.environ.get("APP_ENV") == "local" else None
app = fastapi.FastAPI(
title="Marketplace API",
description="AutoGPT Marketplace API is a service that allows users to share AI agents.",
@ -57,6 +57,7 @@ app = fastapi.FastAPI(
version="0.1",
lifespan=lifespan,
root_path="/api/v1/market",
docs_url=docs_url,
)
app.add_middleware(fastapi.middleware.gzip.GZipMiddleware, minimum_size=1000)