Skip to content

Commit

Permalink
Merge pull request #3765 from uselagoon/fix-task-helper-scope-pass
Browse files Browse the repository at this point in the history
fix: pass adminscopes to task helpers
  • Loading branch information
tobybellwood authored Jul 5, 2024
2 parents b8ffdf4 + adb0957 commit 74d4ecd
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions services/api/src/resources/task/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
36 changes: 18 additions & 18 deletions services/api/src/resources/task/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand All @@ -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(
Expand Down Expand Up @@ -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,
Expand All @@ -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(
Expand Down Expand Up @@ -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,
Expand All @@ -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(
Expand All @@ -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,
Expand All @@ -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(
Expand Down Expand Up @@ -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,
Expand All @@ -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(
Expand Down Expand Up @@ -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,
Expand All @@ -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(
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions services/api/src/resources/task/task_definition_resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 74d4ecd

Please sign in to comment.