From adb09576ab3880e8d9de02d60af7480fc7a96e73 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Fri, 5 Jul 2024 11:05:33 +1000 Subject: [PATCH] fix: pass adminscopes to task helpers --- services/api/src/resources/task/helpers.ts | 4 +-- services/api/src/resources/task/resolvers.ts | 36 +++++++++---------- .../task/task_definition_resolvers.ts | 4 +-- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/services/api/src/resources/task/helpers.ts b/services/api/src/resources/task/helpers.ts index ac995485a0..db28a8c71e 100644 --- a/services/api/src/resources/task/helpers.ts +++ b/services/api/src/resources/task/helpers.ts @@ -11,8 +11,8 @@ import { Sql as environmentSql } from '../environment/sql'; import { Helpers as environmentHelpers } from '../environment/helpers'; import { logger } from '../../loggers/logger'; -export const Helpers = (sqlClientPool: Pool, hasPermission) => { - const getTaskById = async (TaskID: number, adminScopes) => { +export const Helpers = (sqlClientPool: Pool, hasPermission, adminScopes) => { + const getTaskById = async (TaskID: number) => { const queryString = knex('task') .where('id', '=', TaskID) .toString(); diff --git a/services/api/src/resources/task/resolvers.ts b/services/api/src/resources/task/resolvers.ts index 4cfbd15f4a..57a7c34e10 100644 --- a/services/api/src/resources/task/resolvers.ts +++ b/services/api/src/resources/task/resolvers.ts @@ -245,7 +245,7 @@ export const addTask: ResolverFn = async ( sourceUser, } }, - { sqlClientPool, hasPermission, userActivityLogger, keycloakGrant, legacyGrant } + { sqlClientPool, hasPermission, userActivityLogger, keycloakGrant, legacyGrant, adminScopes } ) => { await envValidators(sqlClientPool).environmentExists(environment); const envPerm = await environmentHelpers(sqlClientPool).getEnvironmentById( @@ -297,7 +297,7 @@ export const addTask: ResolverFn = async ( } }); - const taskData = await Helpers(sqlClientPool, hasPermission).addTask({ + const taskData = await Helpers(sqlClientPool, hasPermission, adminScopes).addTask({ id, name, taskName, @@ -352,10 +352,10 @@ export const cancelTask: ResolverFn = async ( task: taskInput, } }, - { sqlClientPool, hasPermission, userActivityLogger } + { sqlClientPool, hasPermission, userActivityLogger, adminScopes } ) => { - const task = await Helpers(sqlClientPool, hasPermission).getTaskByTaskInput(taskInput); + const task = await Helpers(sqlClientPool, hasPermission, adminScopes).getTaskByTaskInput(taskInput); if (!task) { return null; } @@ -498,7 +498,7 @@ export const updateTask: ResolverFn = async ( export const taskDrushArchiveDump: ResolverFn = async ( root, { environment: environmentId }, - { sqlClientPool, hasPermission, userActivityLogger, keycloakGrant, legacyGrant } + { sqlClientPool, hasPermission, userActivityLogger, keycloakGrant, legacyGrant, adminScopes } ) => { await envValidators(sqlClientPool).environmentExists(environmentId); const envPerm = await environmentHelpers(sqlClientPool).getEnvironmentById( @@ -529,7 +529,7 @@ TOKEN="$(ssh -p `+"${LAGOON_CONFIG_TOKEN_PORT:-$TASK_SSH_PORT}"+` -t lagoon@`+"$ }); const sourceUser = await deploymentHelpers(sqlClientPool).getSourceUser(keycloakGrant, legacyGrant) - const taskData = await Helpers(sqlClientPool, hasPermission).addTask({ + const taskData = await Helpers(sqlClientPool, hasPermission, adminScopes).addTask({ name: 'Drush archive-dump', taskName: generateTaskName(), environment: environmentId, @@ -549,7 +549,7 @@ TOKEN="$(ssh -p `+"${LAGOON_CONFIG_TOKEN_PORT:-$TASK_SSH_PORT}"+` -t lagoon@`+"$ export const taskDrushSqlDump: ResolverFn = async ( root, { environment: environmentId }, - { sqlClientPool, hasPermission, userActivityLogger, keycloakGrant, legacyGrant } + { sqlClientPool, hasPermission, userActivityLogger, keycloakGrant, legacyGrant, adminScopes } ) => { await envValidators(sqlClientPool).environmentExists(environmentId); const envPerm = await environmentHelpers(sqlClientPool).getEnvironmentById( @@ -581,7 +581,7 @@ TOKEN="$(ssh -p `+"${LAGOON_CONFIG_TOKEN_PORT:-$TASK_SSH_PORT}"+` -t lagoon@`+"$ }); const sourceUser = await deploymentHelpers(sqlClientPool).getSourceUser(keycloakGrant, legacyGrant) - const taskData = await Helpers(sqlClientPool, hasPermission).addTask({ + const taskData = await Helpers(sqlClientPool, hasPermission, adminScopes).addTask({ name: 'Drush sql-dump', taskName: generateTaskName(), environment: environmentId, @@ -601,7 +601,7 @@ TOKEN="$(ssh -p `+"${LAGOON_CONFIG_TOKEN_PORT:-$TASK_SSH_PORT}"+` -t lagoon@`+"$ export const taskDrushCacheClear: ResolverFn = async ( root, { environment: environmentId }, - { sqlClientPool, hasPermission, userActivityLogger, keycloakGrant, legacyGrant } + { sqlClientPool, hasPermission, userActivityLogger, keycloakGrant, legacyGrant, adminScopes } ) => { await envValidators(sqlClientPool).environmentExists(environmentId); const envPerm = await environmentHelpers(sqlClientPool).getEnvironmentById( @@ -635,7 +635,7 @@ export const taskDrushCacheClear: ResolverFn = async ( }); const sourceUser = await deploymentHelpers(sqlClientPool).getSourceUser(keycloakGrant, legacyGrant) - const taskData = await Helpers(sqlClientPool, hasPermission).addTask({ + const taskData = await Helpers(sqlClientPool, hasPermission, adminScopes).addTask({ name: 'Drush cache-clear', taskName: generateTaskName(), environment: environmentId, @@ -655,7 +655,7 @@ export const taskDrushCacheClear: ResolverFn = async ( export const taskDrushCron: ResolverFn = async ( root, { environment: environmentId }, - { sqlClientPool, hasPermission, userActivityLogger, keycloakGrant, legacyGrant } + { sqlClientPool, hasPermission, userActivityLogger, keycloakGrant, legacyGrant, adminScopes } ) => { await envValidators(sqlClientPool).environmentExists(environmentId); const envPerm = await environmentHelpers(sqlClientPool).getEnvironmentById( @@ -678,7 +678,7 @@ export const taskDrushCron: ResolverFn = async ( }); const sourceUser = await deploymentHelpers(sqlClientPool).getSourceUser(keycloakGrant, legacyGrant) - const taskData = await Helpers(sqlClientPool, hasPermission).addTask({ + const taskData = await Helpers(sqlClientPool, hasPermission, adminScopes).addTask({ name: 'Drush cron', taskName: generateTaskName(), environment: environmentId, @@ -701,7 +701,7 @@ export const taskDrushSqlSync: ResolverFn = async ( sourceEnvironment: sourceEnvironmentId, destinationEnvironment: destinationEnvironmentId }, - { sqlClientPool, hasPermission, userActivityLogger, keycloakGrant, legacyGrant } + { sqlClientPool, hasPermission, userActivityLogger, keycloakGrant, legacyGrant, adminScopes } ) => { await envValidators(sqlClientPool).environmentExists(sourceEnvironmentId); await envValidators(sqlClientPool).environmentExists( @@ -753,7 +753,7 @@ export const taskDrushSqlSync: ResolverFn = async ( drush -y sql-sync @\${LAGOON_ALIAS_PREFIX}${sourceEnvironment.name} @self`; const sourceUser = await deploymentHelpers(sqlClientPool).getSourceUser(keycloakGrant, legacyGrant) - const taskData = await Helpers(sqlClientPool, hasPermission).addTask({ + const taskData = await Helpers(sqlClientPool, hasPermission, adminScopes).addTask({ name: `Sync DB ${sourceEnvironment.name} -> ${destinationEnvironment.name}`, taskName: generateTaskName(), environment: destinationEnvironmentId, @@ -776,7 +776,7 @@ export const taskDrushRsyncFiles: ResolverFn = async ( sourceEnvironment: sourceEnvironmentId, destinationEnvironment: destinationEnvironmentId }, - { sqlClientPool, hasPermission, userActivityLogger, keycloakGrant, legacyGrant } + { sqlClientPool, hasPermission, userActivityLogger, keycloakGrant, legacyGrant, adminScopes } ) => { await envValidators(sqlClientPool).environmentExists(sourceEnvironmentId); await envValidators(sqlClientPool).environmentExists( @@ -828,7 +828,7 @@ export const taskDrushRsyncFiles: ResolverFn = async ( drush -y rsync @\${LAGOON_ALIAS_PREFIX}${sourceEnvironment.name}:%files @self:%files -- --omit-dir-times --no-perms --no-group --no-owner --chmod=ugo=rwX`; const sourceUser = await deploymentHelpers(sqlClientPool).getSourceUser(keycloakGrant, legacyGrant) - const taskData = await Helpers(sqlClientPool, hasPermission).addTask({ + const taskData = await Helpers(sqlClientPool, hasPermission, adminScopes).addTask({ name: `Sync files ${sourceEnvironment.name} -> ${destinationEnvironment.name}`, taskName: generateTaskName(), environment: destinationEnvironmentId, @@ -848,7 +848,7 @@ export const taskDrushRsyncFiles: ResolverFn = async ( export const taskDrushUserLogin: ResolverFn = async ( root, { environment: environmentId }, - { sqlClientPool, hasPermission, userActivityLogger, keycloakGrant, legacyGrant } + { sqlClientPool, hasPermission, userActivityLogger, keycloakGrant, legacyGrant, adminScopes } ) => { await envValidators(sqlClientPool).environmentExists(environmentId); const envPerm = await environmentHelpers(sqlClientPool).getEnvironmentById( @@ -871,7 +871,7 @@ export const taskDrushUserLogin: ResolverFn = async ( }); const sourceUser = await deploymentHelpers(sqlClientPool).getSourceUser(keycloakGrant, legacyGrant) - const taskData = await Helpers(sqlClientPool, hasPermission).addTask({ + const taskData = await Helpers(sqlClientPool, hasPermission, adminScopes).addTask({ name: 'Drush uli', taskName: generateTaskName(), environment: environmentId, diff --git a/services/api/src/resources/task/task_definition_resolvers.ts b/services/api/src/resources/task/task_definition_resolvers.ts index 97f9a281b4..a783eb9427 100644 --- a/services/api/src/resources/task/task_definition_resolvers.ts +++ b/services/api/src/resources/task/task_definition_resolvers.ts @@ -613,7 +613,7 @@ export const invokeRegisteredTask = async ( sourceType = "API" } const sourceUser = await deploymentHelpers(sqlClientPool).getSourceUser(keycloakGrant, legacyGrant) - const taskData = await Helpers(sqlClientPool, hasPermission).addTask({ + const taskData = await Helpers(sqlClientPool, hasPermission, adminScopes).addTask({ name: task.name, taskName: generateTaskName(), environment: environment, @@ -641,7 +641,7 @@ export const invokeRegisteredTask = async ( } - const advancedTaskData = await Helpers(sqlClientPool, hasPermission).addAdvancedTask({ + const advancedTaskData = await Helpers(sqlClientPool, hasPermission, adminScopes).addAdvancedTask({ name: task.name, taskName: generateTaskName(), created: undefined,