Compare commits

...

2 Commits

Author SHA1 Message Date
pablodanswer
b23c5a08a1 update drive 2024-10-10 17:52:21 -07:00
pablodanswer
63e45d3323 minor- gauth one click 2024-10-10 16:38:24 -07:00
11 changed files with 114 additions and 26 deletions

View File

@@ -135,7 +135,7 @@ POSTGRES_PASSWORD = urllib.parse.quote_plus(
os.environ.get("POSTGRES_PASSWORD") or "password"
)
POSTGRES_HOST = os.environ.get("POSTGRES_HOST") or "localhost"
POSTGRES_PORT = os.environ.get("POSTGRES_PORT") or "5432"
POSTGRES_PORT = os.environ.get("POSTGRES_PORT") or "5433"
POSTGRES_DB = os.environ.get("POSTGRES_DB") or "postgres"
POSTGRES_API_SERVER_POOL_SIZE = int(
@@ -423,7 +423,8 @@ AZURE_DALLE_API_BASE = os.environ.get("AZURE_DALLE_API_BASE")
AZURE_DALLE_DEPLOYMENT_NAME = os.environ.get("AZURE_DALLE_DEPLOYMENT_NAME")
MULTI_TENANT = os.environ.get("MULTI_TENANT", "").lower() == "true"
MULTI_TENANT = True
# os.environ.get("MULTI_TENANT", "").lower() == "true"
SECRET_JWT_KEY = os.environ.get("SECRET_JWT_KEY", "")

View File

@@ -70,6 +70,11 @@ KV_INSTANCE_DOMAIN_KEY = "instance_domain"
KV_ENTERPRISE_SETTINGS_KEY = "danswer_enterprise_settings"
KV_CUSTOM_ANALYTICS_SCRIPT_KEY = "__custom_analytics_script__"
# Cloud
KV_CLOUD_GOOGLE_DRIVE_CRED_KEY = "cloud_google_drive_app_credential"
KV_CLOUD_GOOGLE_DRIVE_SERVICE_ACCOUNT_KEY = "cloud_google_drive_service_account_key"
CELERY_VESPA_SYNC_BEAT_LOCK_TIMEOUT = 60
CELERY_PRIMARY_WORKER_LOCK_TIMEOUT = 120

View File

@@ -17,6 +17,7 @@ from danswer.auth.users import current_curator_or_admin_user
from danswer.auth.users import current_user
from danswer.background.celery.celery_utils import get_deletion_attempt_snapshot
from danswer.configs.app_configs import ENABLED_CONNECTOR_TYPES
from danswer.configs.app_configs import MULTI_TENANT
from danswer.configs.constants import DocumentSource
from danswer.configs.constants import FileOrigin
from danswer.connectors.gmail.connector_auth import delete_gmail_service_account_key
@@ -124,6 +125,12 @@ def check_google_app_gmail_credentials_exist(
def upsert_google_app_gmail_credentials(
app_credentials: GoogleAppCredentials, _: User = Depends(current_admin_user)
) -> StatusResponse:
if MULTI_TENANT:
raise HTTPException(
status_code=400,
detail="Modifying Google App Credentials is not supported in multi-tenant mode",
)
try:
upsert_google_app_gmail_cred(app_credentials)
except ValueError as e:
@@ -160,8 +167,15 @@ def check_google_app_credentials_exist(
@router.put("/admin/connector/google-drive/app-credential")
def upsert_google_app_credentials(
app_credentials: GoogleAppCredentials, _: User = Depends(current_admin_user)
app_credentials: GoogleAppCredentials,
_: User = Depends(current_admin_user),
) -> StatusResponse:
if MULTI_TENANT:
raise HTTPException(
status_code=400,
detail="Modifying Google App Credentials is not supported in multi-tenant mode",
)
try:
upsert_google_app_cred(app_credentials)
except ValueError as e:
@@ -202,6 +216,12 @@ def check_google_service_gmail_account_key_exist(
def upsert_google_service_gmail_account_key(
service_account_key: GoogleServiceAccountKey, _: User = Depends(current_admin_user)
) -> StatusResponse:
if MULTI_TENANT:
raise HTTPException(
status_code=400,
detail="Modifying Google App Credentials is not supported in multi-tenant mode",
)
try:
upsert_gmail_service_account_key(service_account_key)
except ValueError as e:
@@ -242,6 +262,12 @@ def check_google_service_account_key_exist(
def upsert_google_service_account_key(
service_account_key: GoogleServiceAccountKey, _: User = Depends(current_admin_user)
) -> StatusResponse:
if MULTI_TENANT:
raise HTTPException(
status_code=400,
detail="Modifying Google App Credentials is not supported in multi-tenant mode",
)
try:
upsert_service_account_key(service_account_key)
except ValueError as e:
@@ -275,6 +301,12 @@ def upsert_service_account_credential(
"""Special API which allows the creation of a credential for a service account.
Combines the input with the saved service account key to create an entry in the
`Credential` table."""
if MULTI_TENANT:
raise HTTPException(
status_code=400,
detail="Modifying Google App Credentials is not supported in multi-tenant mode",
)
try:
credential_base = build_service_account_creds(
DocumentSource.GOOGLE_DRIVE,
@@ -301,6 +333,12 @@ def upsert_gmail_service_account_credential(
"""Special API which allows the creation of a credential for a service account.
Combines the input with the saved service account key to create an entry in the
`Credential` table."""
if MULTI_TENANT:
raise HTTPException(
status_code=400,
detail="Modifying Google App Credentials is not supported in multi-tenant mode",
)
try:
credential_base = build_service_account_creds(
DocumentSource.GMAIL,
@@ -849,6 +887,10 @@ def gmail_auth(
def google_drive_auth(
response: Response, credential_id: str, _: User = Depends(current_user)
) -> AuthUrl:
print("request for authorizaiton")
print(credential_id)
print(type(credential_id))
print(MULTI_TENANT)
# set a cookie that we can read in the callback (used for `verify_csrf`)
response.set_cookie(
key=_GOOGLE_DRIVE_CREDENTIAL_ID_COOKIE_NAME,

View File

@@ -300,7 +300,7 @@ services:
- POSTGRES_USER=${POSTGRES_USER:-postgres}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-password}
ports:
- "5432:5432"
- "5433:5432"
volumes:
- db_volume:/var/lib/postgresql/data

View File

@@ -312,7 +312,7 @@ services:
- POSTGRES_USER=${POSTGRES_USER:-postgres}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-password}
ports:
- "5432:5432"
- "5433:5432"
volumes:
- db_volume:/var/lib/postgresql/data

View File

@@ -157,7 +157,7 @@ services:
- POSTGRES_USER=${POSTGRES_USER:-postgres}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-password}
ports:
- "5432"
- "5433"
volumes:
- db_volume:/var/lib/postgresql/data

View File

@@ -21,6 +21,8 @@ import CreateCredential from "@/components/credentials/actions/CreateCredential"
import ModifyCredential from "@/components/credentials/actions/ModifyCredential";
import { ConfigurableSources, ValidSources } from "@/lib/types";
import { Credential, credentialTemplates } from "@/lib/connectors/credentials";
import { CLOUD_ENABLED } from "@/lib/constants";
import {
ConnectionConfiguration,
connectorConfigs,

View File

@@ -6,7 +6,10 @@ import * as Yup from "yup";
import { useRouter } from "next/navigation";
import { adminDeleteCredential } from "@/lib/credential";
import { setupGoogleDriveOAuth } from "@/lib/googleDrive";
import { GOOGLE_DRIVE_AUTH_IS_ADMIN_COOKIE_NAME } from "@/lib/constants";
import {
CLOUD_ENABLED,
GOOGLE_DRIVE_AUTH_IS_ADMIN_COOKIE_NAME,
} from "@/lib/constants";
import Cookies from "js-cookie";
import { TextFormField } from "@/components/admin/connectors/Field";
import { Form, Formik } from "formik";
@@ -428,10 +431,11 @@ export const DriveOAuthSection = ({
return (
<div className="text-sm mb-4">
<p className="mb-2">
Next, you must provide credentials via OAuth. This gives us read
access to the docs you have access to in your google drive account.
{!CLOUD_ENABLED
? "Next, you must provide credentials via OAuth. This gives us read access to the docs you have access to in your google drive account."
: "Please authenticate with Google Drive. This gives us read access to the docs you have access to in your google drive account."}
</p>
<Button
<button
onClick={async () => {
const [authUrl, errorMsg] = await setupGoogleDriveOAuth({
isAdmin: true,
@@ -450,9 +454,20 @@ export const DriveOAuthSection = ({
type: "error",
});
}}
className="bg-blue-500 hover:bg-blue-600 text-white font-bold py-3 px-6 rounded-sm shadow-lg transform transition duration-300 ease-in-out pdrivefocus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-opacity-50"
>
Authenticate with Google Drive
</Button>
<div className="flex items-center justify-center">
<svg
className="w-6 h-6 mr-2"
fill="currentColor"
viewBox="0 0 24 24"
xmlns="http://www.w3.org/2000/svg"
>
<path d="M12 0C5.372 0 0 5.373 0 12s5.372 12 12 12c6.627 0 12-5.373 12-12S18.627 0 12 0zm.14 19.018c-3.868 0-7-3.14-7-7.018c0-3.878 3.132-7.018 7-7.018c1.89 0 3.47.697 4.682 1.829l-1.974 1.978v-.004c-.735-.702-1.667-1.062-2.708-1.062c-2.31 0-4.187 1.956-4.187 4.273c0 2.315 1.877 4.277 4.187 4.277c2.096 0 3.522-1.202 3.816-2.852H12.14v-2.737h6.585c.088.47.135.96.135 1.474c0 4.01-2.677 6.86-6.72 6.86z" />
</svg>
<span>Authenticate with Google Drive</span>
</div>
</button>
</div>
);
}

View File

@@ -20,6 +20,7 @@ import {
} from "@/lib/connectors/credentials";
import { GoogleDriveConfig } from "@/lib/connectors/connectors";
import { useUser } from "@/components/user/UserProvider";
import { CLOUD_ENABLED } from "@/lib/constants";
const GDriveMain = ({}: {}) => {
const { isLoadingUser, isAdmin } = useUser();
@@ -29,7 +30,7 @@ const GDriveMain = ({}: {}) => {
isLoading: isAppCredentialLoading,
error: isAppCredentialError,
} = useSWR<{ client_id: string }, FetchError>(
"/api/manage/admin/connector/google-drive/app-credential",
`/api/manage/admin/connector/google-drive/app-credential`,
errorHandlingFetcher
);
@@ -116,6 +117,26 @@ const GDriveMain = ({}: {}) => {
(connectorIndexingStatus) =>
connectorIndexingStatus.connector.source === "google_drive"
);
if (CLOUD_ENABLED) {
return (
<>
<Title className="mb-2 mt-6 ml-auto mr-auto">
Authenticate with Google Drive
</Title>
<DriveOAuthSection
setPopup={setPopup}
refreshCredentials={refreshCredentials}
googleDrivePublicCredential={googleDrivePublicCredential}
googleDriveServiceAccountCredential={
googleDriveServiceAccountCredential
}
appCredentialData={appCredentialData}
serviceAccountKeyData={serviceAccountKeyData}
connectorExists={googleDriveConnectorIndexingStatuses.length > 0}
/>
</>
);
}
return (
<>

View File

@@ -6,7 +6,10 @@ import * as Yup from "yup";
import { useRouter } from "next/navigation";
import { adminDeleteCredential } from "@/lib/credential";
import { setupGmailOAuth } from "@/lib/gmail";
import { GMAIL_AUTH_IS_ADMIN_COOKIE_NAME } from "@/lib/constants";
import {
CLOUD_ENABLED,
GMAIL_AUTH_IS_ADMIN_COOKIE_NAME,
} from "@/lib/constants";
import Cookies from "js-cookie";
import { TextFormField } from "@/components/admin/connectors/Field";
import { Form, Formik } from "formik";
@@ -424,8 +427,9 @@ export const GmailOAuthSection = ({
return (
<div className="text-sm mb-4">
<p className="mb-2">
Next, you must provide credentials via OAuth. This gives us read
access to the docs you have access to in your gmail account.
{!CLOUD_ENABLED
? "Next, you must provide credentials via OAuth. This gives us read access to the docs you have access to in your gmail account."
: "Please authenticate with Gmail. This gives us read access to the docs you have access to in your gmail account."}
</p>
<Button
onClick={async () => {

View File

@@ -15,18 +15,16 @@ export const Button = ({
fullWidth = false,
className = "",
}: Props) => {
const baseClasses =
"group relative py-2 px-4 text-sm font-medium rounded-md text-white focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-red-500";
const widthClasses = fullWidth ? "w-full" : "";
const colorClasses = disabled
? "bg-gray-400 cursor-not-allowed"
: "bg-red-600 hover:bg-red-700";
return (
<button
className={
"group relative " +
(fullWidth ? "w-full " : "") +
"py-1 px-2 border border-transparent text-sm " +
"font-medium rounded-md text-white " +
"focus:outline-none focus:ring-2 " +
"focus:ring-offset-2 focus:ring-red-500 mx-auto " +
(disabled ? "bg-gray-700 " : "bg-red-800 hover:bg-red-900 ") +
className
}
className={`${baseClasses} ${widthClasses} ${colorClasses} ${className}`}
onClick={onClick}
type={type}
disabled={disabled}