diff --git a/backend/danswer/configs/app_configs.py b/backend/danswer/configs/app_configs.py index 2521a2a2704..3ba01300ced 100644 --- a/backend/danswer/configs/app_configs.py +++ b/backend/danswer/configs/app_configs.py @@ -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 diff --git a/backend/danswer/server/documents/connector.py b/backend/danswer/server/documents/connector.py index ada53b29ce0..034f5787fa1 100644 --- a/backend/danswer/server/documents/connector.py +++ b/backend/danswer/server/documents/connector.py @@ -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 @@ -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)) @@ -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( diff --git a/deployment/docker_compose/docker-compose.dev.yml b/deployment/docker_compose/docker-compose.dev.yml index 83ace479540..4cb7196f7d2 100644 --- a/deployment/docker_compose/docker-compose.dev.yml +++ b/deployment/docker_compose/docker-compose.dev.yml @@ -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:-} diff --git a/deployment/kubernetes/env-configmap.yaml b/deployment/kubernetes/env-configmap.yaml index e88e996a80f..75f44950d2e 100644 --- a/deployment/kubernetes/env-configmap.yaml +++ b/deployment/kubernetes/env-configmap.yaml @@ -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: ""