fixing google sheets bug, respect google configuration hierarchy
This commit is contained in:
parent
dc940d33db
commit
aed9bfc728
|
@ -110,6 +110,10 @@ spec:
|
||||||
value: {{ .Values.globals.cookieDomain | quote }}
|
value: {{ .Values.globals.cookieDomain | quote }}
|
||||||
- name: HTTP_MIGRATIONS
|
- name: HTTP_MIGRATIONS
|
||||||
value: {{ .Values.globals.httpMigrations | quote }}
|
value: {{ .Values.globals.httpMigrations | quote }}
|
||||||
|
- name: GOOGLE_CLIENT_ID
|
||||||
|
value: {{ .Values.globals.google.clientId | quote }}
|
||||||
|
- name: GOOGLE_CLIENT_SECRET
|
||||||
|
value: {{ .Values.globals.google.secret | quote }}
|
||||||
image: budibase/apps:{{ .Values.globals.appVersion }}
|
image: budibase/apps:{{ .Values.globals.appVersion }}
|
||||||
imagePullPolicy: Always
|
imagePullPolicy: Always
|
||||||
name: bbapps
|
name: bbapps
|
||||||
|
|
|
@ -7,26 +7,18 @@ const environment = require("../../../environment")
|
||||||
const { getGlobalDB } = require("../../../tenancy")
|
const { getGlobalDB } = require("../../../tenancy")
|
||||||
|
|
||||||
async function fetchGoogleCreds() {
|
async function fetchGoogleCreds() {
|
||||||
let config
|
|
||||||
|
|
||||||
// try and get the config from the tenant
|
// try and get the config from the tenant
|
||||||
const db = getGlobalDB()
|
const db = getGlobalDB()
|
||||||
const googleConfig = await getScopedConfig(db, {
|
const googleConfig = await getScopedConfig(db, {
|
||||||
type: Configs.GOOGLE,
|
type: Configs.GOOGLE,
|
||||||
})
|
})
|
||||||
if (googleConfig.clientID && googleConfig.clientSecret) {
|
// or fall back to env variables
|
||||||
config = googleConfig
|
const config = googleConfig || {
|
||||||
}
|
|
||||||
|
|
||||||
// fall back to env variables
|
|
||||||
if (!config) {
|
|
||||||
config = {
|
|
||||||
clientID: environment.GOOGLE_CLIENT_ID,
|
clientID: environment.GOOGLE_CLIENT_ID,
|
||||||
clientSecret: environment.GOOGLE_CLIENT_SECRET,
|
clientSecret: environment.GOOGLE_CLIENT_SECRET,
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return googleConfig
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
async function preAuth(passport, ctx, next) {
|
async function preAuth(passport, ctx, next) {
|
||||||
|
|
|
@ -51,7 +51,10 @@ exports.strategyFactory = async function (
|
||||||
)
|
)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
throw new Error("Error constructing google authentication strategy", err)
|
throw new Error(
|
||||||
|
`Error constructing google authentication strategy: ${err}`,
|
||||||
|
err
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// expose for testing
|
// expose for testing
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
import ArrayRenderer from "components/common/renderers/ArrayRenderer.svelte"
|
import ArrayRenderer from "components/common/renderers/ArrayRenderer.svelte"
|
||||||
import ConfirmDialog from "components/common/ConfirmDialog.svelte"
|
import ConfirmDialog from "components/common/ConfirmDialog.svelte"
|
||||||
import { goto } from "@roxi/routify"
|
import { goto } from "@roxi/routify"
|
||||||
|
import GoogleButton from "../_components/GoogleButton.svelte"
|
||||||
|
|
||||||
export let datasource
|
export let datasource
|
||||||
export let save
|
export let save
|
||||||
|
@ -160,6 +161,11 @@
|
||||||
Fetch tables
|
Fetch tables
|
||||||
</Button>
|
</Button>
|
||||||
<Button cta icon="Add" on:click={createNewTable}>New table</Button>
|
<Button cta icon="Add" on:click={createNewTable}>New table</Button>
|
||||||
|
{#if integration.auth}
|
||||||
|
{#if integration.auth.type === "google"}
|
||||||
|
<GoogleButton {datasource} />
|
||||||
|
{/if}
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<Body>
|
<Body>
|
||||||
|
|
|
@ -1,8 +1,24 @@
|
||||||
|
const { cloneDeep } = require("lodash")
|
||||||
const { definitions } = require("../../integrations")
|
const { definitions } = require("../../integrations")
|
||||||
|
const { getTenantId } = require("@budibase/backend-core/tenancy")
|
||||||
|
const { SourceNames } = require("../../definitions/datasource")
|
||||||
|
const googlesheets = require("../../integrations/googlesheets")
|
||||||
|
const env = require("../../environment")
|
||||||
|
|
||||||
exports.fetch = async function (ctx) {
|
exports.fetch = async function (ctx) {
|
||||||
ctx.status = 200
|
ctx.status = 200
|
||||||
ctx.body = definitions
|
const defs = cloneDeep(definitions)
|
||||||
|
|
||||||
|
// for google sheets integration google verification
|
||||||
|
if (env.EXCLUDE_QUOTAS_TENANTS) {
|
||||||
|
const excludedTenants = env.EXCLUDE_QUOTAS_TENANTS.split(",")
|
||||||
|
const tenantId = getTenantId()
|
||||||
|
if (excludedTenants.includes(tenantId)) {
|
||||||
|
defs[SourceNames.GOOGLE_SHEETS] = googlesheets.schema
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.body = defs
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.find = async function (ctx) {
|
exports.find = async function (ctx) {
|
||||||
|
|
|
@ -46,6 +46,8 @@ module.exports = {
|
||||||
MULTI_TENANCY: process.env.MULTI_TENANCY,
|
MULTI_TENANCY: process.env.MULTI_TENANCY,
|
||||||
HTTP_MIGRATIONS: process.env.HTTP_MIGRATIONS,
|
HTTP_MIGRATIONS: process.env.HTTP_MIGRATIONS,
|
||||||
API_REQ_LIMIT_PER_SEC: process.env.API_REQ_LIMIT_PER_SEC,
|
API_REQ_LIMIT_PER_SEC: process.env.API_REQ_LIMIT_PER_SEC,
|
||||||
|
GOOGLE_CLIENT_ID: process.env.GOOGLE_CLIENT_ID,
|
||||||
|
GOOGLE_CLIENT_SECRET: process.env.GOOGLE_CLIENT_SECRET,
|
||||||
// environment
|
// environment
|
||||||
NODE_ENV: process.env.NODE_ENV,
|
NODE_ENV: process.env.NODE_ENV,
|
||||||
JEST_WORKER_ID: process.env.JEST_WORKER_ID,
|
JEST_WORKER_ID: process.env.JEST_WORKER_ID,
|
||||||
|
|
|
@ -10,6 +10,7 @@ import { Table, TableSchema } from "../definitions/common"
|
||||||
import { buildExternalTableId } from "./utils"
|
import { buildExternalTableId } from "./utils"
|
||||||
import { DataSourceOperation, FieldTypes } from "../constants"
|
import { DataSourceOperation, FieldTypes } from "../constants"
|
||||||
import { GoogleSpreadsheet } from "google-spreadsheet"
|
import { GoogleSpreadsheet } from "google-spreadsheet"
|
||||||
|
import env from "../environment"
|
||||||
|
|
||||||
module GoogleSheetsModule {
|
module GoogleSheetsModule {
|
||||||
const { getGlobalDB } = require("@budibase/backend-core/tenancy")
|
const { getGlobalDB } = require("@budibase/backend-core/tenancy")
|
||||||
|
@ -138,13 +139,27 @@ module GoogleSheetsModule {
|
||||||
try {
|
try {
|
||||||
// Initialise oAuth client
|
// Initialise oAuth client
|
||||||
const db = getGlobalDB()
|
const db = getGlobalDB()
|
||||||
const googleConfig = await getScopedConfig(db, {
|
let googleConfig = await getScopedConfig(db, {
|
||||||
type: Configs.GOOGLE,
|
type: Configs.GOOGLE,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if (!googleConfig) {
|
||||||
|
googleConfig = {
|
||||||
|
clientID: env.GOOGLE_CLIENT_ID,
|
||||||
|
clientSecret: env.GOOGLE_CLIENT_SECRET,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const oauthClient = new OAuth2Client({
|
const oauthClient = new OAuth2Client({
|
||||||
clientId: googleConfig.clientID,
|
clientId: googleConfig.clientID,
|
||||||
clientSecret: googleConfig.clientSecret,
|
clientSecret: googleConfig.clientSecret,
|
||||||
})
|
})
|
||||||
|
oauthClient.on("tokens", tokens => {
|
||||||
|
oauthClient.setCredentials({
|
||||||
|
refresh_token: googleConfig.refreshToken,
|
||||||
|
access_token: tokens.access_token,
|
||||||
|
})
|
||||||
|
})
|
||||||
oauthClient.credentials.access_token = this.config.auth.accessToken
|
oauthClient.credentials.access_token = this.config.auth.accessToken
|
||||||
oauthClient.credentials.refresh_token = this.config.auth.refreshToken
|
oauthClient.credentials.refresh_token = this.config.auth.refreshToken
|
||||||
this.client.useOAuth2Client(oauthClient)
|
this.client.useOAuth2Client(oauthClient)
|
||||||
|
|
|
@ -42,6 +42,7 @@ const INTEGRATIONS = {
|
||||||
[SourceNames.ARANGODB]: arangodb.integration,
|
[SourceNames.ARANGODB]: arangodb.integration,
|
||||||
[SourceNames.REST]: rest.integration,
|
[SourceNames.REST]: rest.integration,
|
||||||
[SourceNames.FIREBASE]: firebase.integration,
|
[SourceNames.FIREBASE]: firebase.integration,
|
||||||
|
[SourceNames.GOOGLE_SHEETS]: googlesheets.integration,
|
||||||
}
|
}
|
||||||
|
|
||||||
// optionally add oracle integration if the oracle binary can be installed
|
// optionally add oracle integration if the oracle binary can be installed
|
||||||
|
@ -51,10 +52,9 @@ if (!(process.arch === "arm64" && process.platform === "darwin")) {
|
||||||
INTEGRATIONS[SourceNames.ORACLE] = oracle.integration
|
INTEGRATIONS[SourceNames.ORACLE] = oracle.integration
|
||||||
}
|
}
|
||||||
|
|
||||||
if (environment.SELF_HOSTED) {
|
// if (environment.SELF_HOSTED) {
|
||||||
DEFINITIONS[SourceNames.GOOGLE_SHEETS] = googlesheets.schema
|
// DEFINITIONS[SourceNames.GOOGLE_SHEETS] = googlesheets.schema
|
||||||
INTEGRATIONS[SourceNames.GOOGLE_SHEETS] = googlesheets.integration
|
// }
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
definitions: DEFINITIONS,
|
definitions: DEFINITIONS,
|
||||||
|
|
Loading…
Reference in New Issue