Skip to content

Commit

Permalink
tweak(platform): Disable docs endpoint when not local (Significant-Gr…
Browse files Browse the repository at this point in the history
…avitas#8265)

* disable docs endpoint

* add to .env.example

* use enum for app env

* lint
  • Loading branch information
aarushik93 authored Oct 8, 2024
1 parent 61f1d0c commit 2aed470
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 2 deletions.
2 changes: 2 additions & 0 deletions autogpt_platform/backend/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions autogpt_platform/backend/backend/server/rest_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ async def lifespan(self, _: FastAPI):
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=(
Expand All @@ -60,6 +61,7 @@ def run_service(self):
summary="AutoGPT Agent Server",
version="0.1",
lifespan=self.lifespan,
docs_url=docs_url,
)

if self._test_dependency_overrides:
Expand Down
1 change: 1 addition & 0 deletions autogpt_platform/backend/backend/server/ws_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions autogpt_platform/backend/backend/util/settings.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -15,6 +16,12 @@
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)

Expand Down Expand Up @@ -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")
Expand Down
4 changes: 3 additions & 1 deletion autogpt_platform/market/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ SENTRY_DSN=https://[email protected].

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
3 changes: 2 additions & 1 deletion autogpt_platform/market/market/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,15 @@ 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.",
summary="Maketplace API",
version="0.1",
lifespan=lifespan,
root_path="/api/v1/market",
docs_url=docs_url,
)

app.add_middleware(fastapi.middleware.gzip.GZipMiddleware, minimum_size=1000)
Expand Down

0 comments on commit 2aed470

Please sign in to comment.