diff --git a/backend/back/src/workflows/workflows.service.ts b/backend/back/src/workflows/workflows.service.ts index d0dffe0e..22153eb1 100644 --- a/backend/back/src/workflows/workflows.service.ts +++ b/backend/back/src/workflows/workflows.service.ts @@ -18,10 +18,12 @@ import UpdateWorkflowDto from "./dto/update-workflow.dto"; import UserConnection from "../connections/entities/user-connection.entity"; import { JobsIdentifiers } from "../types/jobIds"; import { JobsService } from "../jobs/jobs.service"; -import { JobsType } from "../types/jobs"; +import { JobParamsClasses, JobsType } from "../types/jobs"; import Service from "../services/entities/service.entity"; import { ConnectionsService } from "../connections/connections.service"; import { ServiceName } from "../services/services.service"; +import { UniqueJobParams } from "../types/jobParams"; +import { plainToInstance } from "class-transformer"; @Injectable() export class WorkflowsService { @@ -340,7 +342,11 @@ export class WorkflowsService { return dbReactions; } - private async getNeededNewScopes(userId: string, serviceId: ServiceName, neededScopeIds: string[]) { + private async getNeededNewScopes( + userId: string, + serviceId: ServiceName, + neededScopeIds: string[], + ): Promise { const service = await this.workflowRepository.manager.findOneBy(Service, { id: serviceId }); if (!service) throw new NotFoundException(`Service ${serviceId} not found.`); if (!service.needConnection) return []; @@ -389,13 +395,15 @@ export class WorkflowsService { areaServiceId, workflowArea.area.serviceScopesNeeded.map(({ id }) => id), ); - if (neededNewScopes.length > 0) { + if (neededNewScopes && neededNewScopes.length > 0) { throw new BadRequestException( `You need to connect to ${areaServiceId} with scopes ${neededNewScopes.join(", ")}.`, ); } const jobType = `${areaServiceId}-${areaId}`; - parameters.workflowStepId = id; + if (plainToInstance(JobParamsClasses[jobType], parameters) instanceof UniqueJobParams) { + parameters.workflowStepId = id; + } workflowArea.parameters = await this.jobsService.convertParams(jobType as JobsType, parameters).catch((err) => { throw new BadRequestException(`Invalid parameters for workflow area ${id} (${jobType}): ${err.message}`); }); diff --git a/backend/back/yarn.lock b/backend/back/yarn.lock index 830ae3cf..9e4cf60e 100644 --- a/backend/back/yarn.lock +++ b/backend/back/yarn.lock @@ -2264,11 +2264,6 @@ cross-spawn@^7.0.0, cross-spawn@^7.0.2, cross-spawn@^7.0.3: shebang-command "^2.0.0" which "^2.0.1" -crypto@^1.0.1: - version "1.0.1" - resolved "https://registry.yarnpkg.com/crypto/-/crypto-1.0.1.tgz#2af1b7cad8175d24c8a1b0778255794a21803037" - integrity sha512-VxBKmeNcqQdiUQUW2Tzq0t377b54N2bMtXO/qiLa+6eRRmmC4qT3D4OnTGoT/U6O9aklQ/jTwbOtRMTTY8G0Ig== - date-fns@^2.29.3: version "2.30.0" resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-2.30.0.tgz#f367e644839ff57894ec6ac480de40cae4b0f4d0" diff --git a/backend/supervisor/jobs/jobs.go b/backend/supervisor/jobs/jobs.go index 49d3b5df..714a33dd 100644 --- a/backend/supervisor/jobs/jobs.go +++ b/backend/supervisor/jobs/jobs.go @@ -7,6 +7,7 @@ import ( "github.com/docker/docker/api/types/container" "github.com/docker/docker/client" "log" + "regexp" ) type JobManager struct { @@ -24,6 +25,7 @@ type Job struct { } var instance *JobManager +var nonAlphanumericRegex = regexp.MustCompile(`[^a-zA-Z0-9 ]+`) func InitJobManager(cli *client.Client, callbackUrl string, env string) { instance = &JobManager{cli, map[string]Job{}, callbackUrl, env == "production", 0} @@ -119,16 +121,6 @@ func (jm *JobManager) KillJob(identifier string) error { return err } - if !jm.production { - err = jm.dockerClient.ContainerRemove(context.Background(), job.containerID, types.ContainerRemoveOptions{ - Force: true, - }) - if err != nil { - log.Printf("Error when removing job %s: %v\n", identifier, err) - return err - } - } - delete(jm.jobs, identifier) log.Printf("Job %s killed\n", identifier) return nil @@ -170,10 +162,11 @@ func (jm *JobManager) cleanContainers() error { } func (jm *JobManager) generateContainerName(identifier string) string { + name := nonAlphanumericRegex.ReplaceAllString(identifier, "-") if jm.production { - return identifier + return name } - return fmt.Sprintf("%s-%d", identifier, jm.jobsCount) + return fmt.Sprintf("%s-%d", name, jm.jobsCount) } func isSupervisorContainer(image string) bool { diff --git a/backend/workers/github/.dockerignore b/backend/workers/github/.dockerignore index e5be654b..68096962 100644 --- a/backend/workers/github/.dockerignore +++ b/backend/workers/github/.dockerignore @@ -1,3 +1,4 @@ dist/ node_modules/ proto/ +.env