Prefer default config for google sheets in cloud, don't use env vars for regular auth
This commit is contained in:
parent
a385fde601
commit
312c01a879
3 changed files with 22 additions and 5 deletions
|
@ -154,11 +154,27 @@ export async function getGoogleConfig(): Promise<
|
||||||
GoogleInnerConfig | undefined
|
GoogleInnerConfig | undefined
|
||||||
> {
|
> {
|
||||||
const config = await getGoogleConfigDoc()
|
const config = await getGoogleConfigDoc()
|
||||||
if (config) {
|
return config?.config
|
||||||
return config.config
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use google fallback configuration from env variables
|
export async function getGoogleDatasourceConfig(): Promise<GoogleInnerConfig | undefined> {
|
||||||
|
if (!env.SELF_HOSTED) {
|
||||||
|
// always use the env vars in cloud
|
||||||
|
return getDefaultGoogleConfig()
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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) {
|
if (environment.GOOGLE_CLIENT_ID && environment.GOOGLE_CLIENT_SECRET) {
|
||||||
return {
|
return {
|
||||||
clientID: environment.GOOGLE_CLIENT_ID!,
|
clientID: environment.GOOGLE_CLIENT_ID!,
|
||||||
|
|
|
@ -12,7 +12,8 @@ type Passport = {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchGoogleCreds() {
|
async function fetchGoogleCreds() {
|
||||||
const config = await configs.getGoogleConfig()
|
let config = await configs.getGoogleDatasourceConfig()
|
||||||
|
|
||||||
if (!config) {
|
if (!config) {
|
||||||
throw new Error("No google configuration found")
|
throw new Error("No google configuration found")
|
||||||
}
|
}
|
||||||
|
|
|
@ -172,7 +172,7 @@ class GoogleSheetsIntegration implements DatasourcePlus {
|
||||||
async connect() {
|
async connect() {
|
||||||
try {
|
try {
|
||||||
// Initialise oAuth client
|
// Initialise oAuth client
|
||||||
let googleConfig = await configs.getGoogleConfig()
|
let googleConfig = await configs.getGoogleDatasourceConfig()
|
||||||
if (!googleConfig) {
|
if (!googleConfig) {
|
||||||
throw new HTTPError("Google config not found", 400)
|
throw new HTTPError("Google config not found", 400)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue