1
0
Fork 0
mirror of synced 2024-07-14 10:45:51 +12:00

Prefer default config for google sheets in cloud, don't use env vars for regular auth

This commit is contained in:
Rory Powell 2023-02-28 10:36:00 +00:00
parent a385fde601
commit 312c01a879
3 changed files with 22 additions and 5 deletions

View file

@ -154,11 +154,27 @@ export async function getGoogleConfig(): Promise<
GoogleInnerConfig | undefined
> {
const config = await getGoogleConfigDoc()
if (config) {
return config.config
return config?.config
}
export async function getGoogleDatasourceConfig(): Promise<GoogleInnerConfig | undefined> {
if (!env.SELF_HOSTED) {
// always use the env vars in cloud
return getDefaultGoogleConfig()
}
// Use google fallback configuration from env variables
// prefer the config in self-host
let config = await getGoogleConfig()
// fallback to env vars
if (!config || !config.activated) {
config = getDefaultGoogleConfig()
}
return config
}
export function getDefaultGoogleConfig(): GoogleInnerConfig | undefined {
if (environment.GOOGLE_CLIENT_ID && environment.GOOGLE_CLIENT_SECRET) {
return {
clientID: environment.GOOGLE_CLIENT_ID!,

View file

@ -12,7 +12,8 @@ type Passport = {
}
async function fetchGoogleCreds() {
const config = await configs.getGoogleConfig()
let config = await configs.getGoogleDatasourceConfig()
if (!config) {
throw new Error("No google configuration found")
}

View file

@ -172,7 +172,7 @@ class GoogleSheetsIntegration implements DatasourcePlus {
async connect() {
try {
// Initialise oAuth client
let googleConfig = await configs.getGoogleConfig()
let googleConfig = await configs.getGoogleDatasourceConfig()
if (!googleConfig) {
throw new HTTPError("Google config not found", 400)
}