Skip to content

Commit 2aed470

Browse files
authored
tweak(platform): Disable docs endpoint when not local (Significant-Gravitas#8265)
* disable docs endpoint * add to .env.example * use enum for app env * lint
1 parent 61f1d0c commit 2aed470

File tree

6 files changed

+22
-2
lines changed

6 files changed

+22
-2
lines changed

autogpt_platform/backend/.env.example

+2
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,5 @@ ENABLE_CLOUD_LOGGING=false
9898
ENABLE_FILE_LOGGING=false
9999
# Use to manually set the log directory
100100
# LOG_DIR=./logs
101+
102+
APP_ENV=local

autogpt_platform/backend/backend/server/rest_api.py

+2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ async def lifespan(self, _: FastAPI):
5151
await db.disconnect()
5252

5353
def run_service(self):
54+
docs_url = "/docs" if settings.config.app_env == "local" else None
5455
app = FastAPI(
5556
title="AutoGPT Agent Server",
5657
description=(
@@ -60,6 +61,7 @@ def run_service(self):
6061
summary="AutoGPT Agent Server",
6162
version="0.1",
6263
lifespan=self.lifespan,
64+
docs_url=docs_url,
6365
)
6466

6567
if self._test_dependency_overrides:

autogpt_platform/backend/backend/server/ws_api.py

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ async def lifespan(app: FastAPI):
2828
event_queue.close()
2929

3030

31+
docs_url = "/docs" if settings.config.app_env == "local" else None
3132
app = FastAPI(lifespan=lifespan)
3233
event_queue = RedisEventQueue()
3334
_connection_manager = None

autogpt_platform/backend/backend/util/settings.py

+12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import json
22
import os
3+
from enum import Enum
34
from typing import Any, Dict, Generic, List, Set, Tuple, Type, TypeVar
45

56
from pydantic import BaseModel, Field, PrivateAttr, field_validator
@@ -15,6 +16,12 @@
1516
T = TypeVar("T", bound=BaseSettings)
1617

1718

19+
class AppEnvironment(str, Enum):
20+
LOCAL = "local"
21+
DEVELOPMENT = "dev"
22+
PRODUCTION = "prod"
23+
24+
1825
class UpdateTrackingModel(BaseModel, Generic[T]):
1926
_updated_fields: Set[str] = PrivateAttr(default_factory=set)
2027

@@ -121,6 +128,11 @@ class Config(UpdateTrackingModel["Config"], BaseSettings):
121128
"This value is then used to generate redirect URLs for OAuth flows.",
122129
)
123130

131+
app_env: AppEnvironment = Field(
132+
default=AppEnvironment.LOCAL,
133+
description="The name of the app environment.",
134+
)
135+
124136
backend_cors_allow_origins: List[str] = Field(default_factory=list)
125137

126138
@field_validator("backend_cors_allow_origins")

autogpt_platform/market/.env.example

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ SENTRY_DSN=https://[email protected].
77

88
ENABLE_AUTH=true
99
SUPABASE_JWT_SECRET=our-super-secret-jwt-token-with-at-least-32-characters-long
10-
BACKEND_CORS_ALLOW_ORIGINS="http://localhost:3000,http://127.0.0.1:3000"
10+
BACKEND_CORS_ALLOW_ORIGINS="http://localhost:3000,http://127.0.0.1:3000"
11+
12+
APP_ENV=local

autogpt_platform/market/market/app.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,15 @@ async def lifespan(app: fastapi.FastAPI):
4949
yield
5050
await db_client.disconnect()
5151

52-
52+
docs_url = "/docs" if os.environ.get("APP_ENV") == "local" else None
5353
app = fastapi.FastAPI(
5454
title="Marketplace API",
5555
description="AutoGPT Marketplace API is a service that allows users to share AI agents.",
5656
summary="Maketplace API",
5757
version="0.1",
5858
lifespan=lifespan,
5959
root_path="/api/v1/market",
60+
docs_url=docs_url,
6061
)
6162

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

0 commit comments

Comments
 (0)