Skip to content

Commit

Permalink
Disabled Connectors List (#1376)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuhongsun96 authored Apr 25, 2024
1 parent d2774f8 commit 66d9569
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
4 changes: 4 additions & 0 deletions backend/danswer/configs/app_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@
#####
POLL_CONNECTOR_OFFSET = 30 # Minutes overlap between poll windows

# View the list here:
# https://github.com/danswer-ai/danswer/blob/main/backend/danswer/connectors/factory.py
DISABLED_CONNECTOR_TYPES = os.environ.get("DISABLED_CONNECTOR_TYPES") or ""

# Some calls to get information on expert users are quite costly especially with rate limiting
# Since experts are not used in the actual user experience, currently it is turned off
# for some connectors
Expand Down
21 changes: 19 additions & 2 deletions backend/danswer/server/documents/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from danswer.auth.users import current_admin_user
from danswer.auth.users import current_user
from danswer.background.celery.celery_utils import get_deletion_status
from danswer.configs.app_configs import DISABLED_CONNECTOR_TYPES
from danswer.configs.constants import DocumentSource
from danswer.connectors.gmail.connector_auth import delete_gmail_service_account_key
from danswer.connectors.gmail.connector_auth import delete_google_app_gmail_cred
Expand Down Expand Up @@ -437,14 +438,25 @@ def get_connector_indexing_status(
return indexing_statuses


def _validate_connector_allowed(source: DocumentSource) -> None:
invalid_connectors = DISABLED_CONNECTOR_TYPES.replace("_", "").split(",")
for connector_type in invalid_connectors:
if source.value.lower().replace("_", "") == connector_type:
raise ValueError(
"This connector type has been disabled by your system admin. "
"Please contact them to get it enabled if you wish to use it."
)


@router.post("/admin/connector")
def create_connector_from_model(
connector_info: ConnectorBase,
connector_data: ConnectorBase,
_: User = Depends(current_admin_user),
db_session: Session = Depends(get_session),
) -> ObjectCreationIdResponse:
try:
return create_connector(connector_info, db_session)
_validate_connector_allowed(connector_data.source)
return create_connector(connector_data, db_session)
except ValueError as e:
raise HTTPException(status_code=400, detail=str(e))

Expand All @@ -456,6 +468,11 @@ def update_connector_from_model(
_: User = Depends(current_admin_user),
db_session: Session = Depends(get_session),
) -> ConnectorSnapshot | StatusResponse[int]:
try:
_validate_connector_allowed(connector_data.source)
except ValueError as e:
raise HTTPException(status_code=400, detail=str(e))

updated_connector = update_connector(connector_id, connector_data, db_session)
if updated_connector is None:
raise HTTPException(
Expand Down
1 change: 1 addition & 0 deletions deployment/docker_compose/docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ services:
- INDEXING_MODEL_SERVER_HOST=${INDEXING_MODEL_SERVER_HOST:-indexing_model_server}
# Indexing Configs
- NUM_INDEXING_WORKERS=${NUM_INDEXING_WORKERS:-}
- DISABLED_CONNECTOR_TYPES=${DISABLED_CONNECTOR_TYPES:-}
- DISABLE_INDEX_UPDATE_ON_SWAP=${DISABLE_INDEX_UPDATE_ON_SWAP:-}
- DASK_JOB_CLIENT_ENABLED=${DASK_JOB_CLIENT_ENABLED:-}
- CONTINUE_ON_CONNECTOR_FAILURE=${CONTINUE_ON_CONNECTOR_FAILURE:-}
Expand Down
1 change: 1 addition & 0 deletions deployment/kubernetes/env-configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ data:
MIN_THREADS_ML_MODELS: ""
# Indexing Configs
NUM_INDEXING_WORKERS: ""
DISABLED_CONNECTOR_TYPES: ""
DISABLE_INDEX_UPDATE_ON_SWAP: ""
DASK_JOB_CLIENT_ENABLED: ""
CONTINUE_ON_CONNECTOR_FAILURE: ""
Expand Down

0 comments on commit 66d9569

Please sign in to comment.