From 0ee86353480fa8b596fbf68f7d9d2fa04327578a Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Fri, 8 Jul 2022 11:09:06 +0100 Subject: [PATCH 1/3] make auth check optional when caller is automation --- .../server/src/api/controllers/query/index.ts | 16 +++++++++------- .../server/src/automations/steps/executeQuery.js | 3 ++- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/packages/server/src/api/controllers/query/index.ts b/packages/server/src/api/controllers/query/index.ts index ce6eeda7c7..b15333f80a 100644 --- a/packages/server/src/api/controllers/query/index.ts +++ b/packages/server/src/api/controllers/query/index.ts @@ -166,14 +166,16 @@ export async function preview(ctx: any) { } } -async function execute(ctx: any, opts = { rowsOnly: false }) { +async function execute(ctx: any, opts = { rowsOnly: false, isAutomation: false }) { const db = getAppDB() const query = await db.get(ctx.params.queryId) const datasource = await db.get(query.datasourceId) - - const authConfigCtx: any = getAuthConfig(ctx) - + + let authConfigCtx: any = {} + if (!opts.isAutomation) { + authConfigCtx = getAuthConfig(ctx) + } const enrichedParameters = ctx.request.body.parameters || {} // make sure parameters are fully enriched with defaults if (query && query.parameters) { @@ -214,11 +216,11 @@ async function execute(ctx: any, opts = { rowsOnly: false }) { } export async function executeV1(ctx: any) { - return execute(ctx, { rowsOnly: true }) + return execute(ctx, { rowsOnly: true, isAutomation: false }) } -export async function executeV2(ctx: any) { - return execute(ctx, { rowsOnly: false }) +export async function executeV2(ctx: any, isAutomation?: any) { + return execute(ctx, { rowsOnly: false, isAutomation }) } const removeDynamicVariables = async (queryId: any) => { diff --git a/packages/server/src/automations/steps/executeQuery.js b/packages/server/src/automations/steps/executeQuery.js index 156df504e9..b33ed678ba 100644 --- a/packages/server/src/automations/steps/executeQuery.js +++ b/packages/server/src/automations/steps/executeQuery.js @@ -71,8 +71,9 @@ exports.run = async function ({ inputs, appId, emitter }) { }, }) + const isAutomation = true try { - await queryController.executeV2(ctx) + await queryController.executeV2(ctx, isAutomation) const { data, ...rest } = ctx.body return { response: data, From 4bf9dda4d6ce16eca5843bab5a80864a22a5b62f Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Fri, 8 Jul 2022 11:11:03 +0100 Subject: [PATCH 2/3] linting --- packages/server/src/api/controllers/query/index.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/server/src/api/controllers/query/index.ts b/packages/server/src/api/controllers/query/index.ts index b15333f80a..ea407dbcdc 100644 --- a/packages/server/src/api/controllers/query/index.ts +++ b/packages/server/src/api/controllers/query/index.ts @@ -166,12 +166,15 @@ export async function preview(ctx: any) { } } -async function execute(ctx: any, opts = { rowsOnly: false, isAutomation: false }) { +async function execute( + ctx: any, + opts = { rowsOnly: false, isAutomation: false } +) { const db = getAppDB() const query = await db.get(ctx.params.queryId) const datasource = await db.get(query.datasourceId) - + let authConfigCtx: any = {} if (!opts.isAutomation) { authConfigCtx = getAuthConfig(ctx) From 218abe39ccb83d5eadeba137d7bb6aca11ebbfbd Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Fri, 8 Jul 2022 12:16:27 +0100 Subject: [PATCH 3/3] add isAutomation to object --- packages/server/src/api/controllers/query/index.ts | 9 ++++++--- packages/server/src/automations/steps/executeQuery.js | 3 +-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/server/src/api/controllers/query/index.ts b/packages/server/src/api/controllers/query/index.ts index ea407dbcdc..8dcf570343 100644 --- a/packages/server/src/api/controllers/query/index.ts +++ b/packages/server/src/api/controllers/query/index.ts @@ -168,7 +168,7 @@ export async function preview(ctx: any) { async function execute( ctx: any, - opts = { rowsOnly: false, isAutomation: false } + opts: any = { rowsOnly: false, isAutomation: false } ) { const db = getAppDB() @@ -219,10 +219,13 @@ async function execute( } export async function executeV1(ctx: any) { - return execute(ctx, { rowsOnly: true, isAutomation: false }) + return execute(ctx, { rowsOnly: true }) } -export async function executeV2(ctx: any, isAutomation?: any) { +export async function executeV2( + ctx: any, + { isAutomation }: { isAutomation?: boolean } = {} +) { return execute(ctx, { rowsOnly: false, isAutomation }) } diff --git a/packages/server/src/automations/steps/executeQuery.js b/packages/server/src/automations/steps/executeQuery.js index b33ed678ba..30f74e17be 100644 --- a/packages/server/src/automations/steps/executeQuery.js +++ b/packages/server/src/automations/steps/executeQuery.js @@ -71,9 +71,8 @@ exports.run = async function ({ inputs, appId, emitter }) { }, }) - const isAutomation = true try { - await queryController.executeV2(ctx, isAutomation) + await queryController.executeV2(ctx, { isAutomation: true }) const { data, ...rest } = ctx.body return { response: data,