Skip to content

Commit 3c4c8eb

Browse files
committed
fix enum
1 parent b4ed4a5 commit 3c4c8eb

File tree

14 files changed

+99
-53
lines changed

14 files changed

+99
-53
lines changed

.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
REDIS_URI=redis://localhost:6379/0
1+
SESAME_REDIS_URI=redis://localhost:6379/0

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
include .env
22
IMG_NAME = "ghcr.io/libertech-fr/sesame-deamon"
33
BASE_NAME = "sesame"
4-
APP_NAME = "sesame-deamon"
4+
APP_NAME = "sesame-daemon"
55
PLATFORM = "linux/amd64"
66

77
.DEFAULT_GOAL := help
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/bin/sh
2-
echo "Hello Word"
2+
echo "{\"status\": 0, \"message\": \"dummy backend\"}"
33
exit 0

src/_common/tasks/executor.task.ts

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,59 @@
1-
import { spawnSync } from 'node:child_process';
1+
import { spawn } from 'node:child_process';
22
import { Job } from 'bullmq';
33
import { ExecutorResponseInterface } from '../interfaces/executor-response.interface';
44
import { ExecutorConfigInterface } from '../interfaces/executor-config.interface';
55
import { join } from 'path';
66

7-
export default function executorTask(
7+
export async function executorTask(
88
command: string,
99
job: Job,
1010
options?: ExecutorConfigInterface,
1111
): Promise<ExecutorResponseInterface> {
12-
const out = spawnSync(join(command), [], {
12+
return new Promise((resolve, reject) => {
13+
const child = spawn(join(command), [], {
14+
shell: options?.shell ?? true,
15+
});
16+
17+
let output = '';
18+
let error = '';
19+
20+
// Ecoute pour la sortie standard (stdout)
21+
child.stdout.on('data', (data) => {
22+
console.log(`stdout: ${data}`);
23+
output += data;
24+
});
25+
26+
// Ecoute pour la sortie d'erreur (stderr)
27+
child.stderr.on('data', (data) => {
28+
console.error(`stderr: ${data}`);
29+
error += data;
30+
});
31+
32+
// Envoyer les données de job au processus enfant
33+
child.stdin.write(JSON.stringify(job.data));
34+
child.stdin.end();
35+
36+
child.on('close', (code) => {
37+
console.log(`Le processus enfant s'est terminé avec le code ${code}`);
38+
resolve({
39+
status: code,
40+
output: output,
41+
error: error,
42+
});
43+
});
44+
45+
child.on('error', (spawnError) => {
46+
console.error('Erreur lors du lancement du processus enfant', spawnError);
47+
reject(spawnError);
48+
});
49+
});
50+
/**const out = spawnSync(join(command), [], {
1351
input: JSON.stringify(job.data),
1452
shell: options?.shell ?? true,
1553
});
1654
return Promise.resolve({
1755
status: out.status,
1856
output: out.stdout?.toString(),
1957
error: out.stderr?.toString(),
20-
});
58+
});**/
2159
}

src/backend-runner/_dto/backend-config-v1.dto.ts

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,8 @@
11
import { Transform, plainToInstance } from 'class-transformer';
22
import { IsBoolean, IsEnum, IsNotEmpty, IsString, Validate } from 'class-validator';
33
import { IsActionConstraintValidator } from '../_validators/is-action-constraint.validator';
4-
5-
export enum ActionType {
6-
LIST_BACKENDS = 'LIST_BACKENDS',
7-
PING_TARGET = 'PING_TARGET',
8-
IDENTITY_CREATE = 'IDENTITY_CREATE',
9-
IDENTITY_UPDATE = 'IDENTITY_UPDATE',
10-
IDENTITY_DELETE = 'IDENTITY_DELETE',
11-
IDENTITY_PASSWORD_RESET = 'IDENTITY_PASSWORD_RESET',
12-
IDENTITY_PASSWORD_CHANGE = 'IDENTITY_PASSWORD_CHANGE',
13-
}
14-
15-
export enum OnErrorType {
16-
CONTINUE = 'continue',
17-
STOP = 'stop',
18-
}
4+
import { ActionType } from '../_enum/action-type.enum';
5+
import { OnErrorType } from '../_enum/on-error-type.enum';
196

207
export class BackendConfigActionDto {
218
@IsString()
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export enum ActionType {
2+
LIST_BACKENDS = 'LIST_BACKENDS',
3+
PING_TARGET = 'PING_TARGET',
4+
IDENTITY_CREATE = 'IDENTITY_CREATE',
5+
IDENTITY_UPDATE = 'IDENTITY_UPDATE',
6+
IDENTITY_DELETE = 'IDENTITY_DELETE',
7+
IDENTITY_PASSWORD_RESET = 'IDENTITY_PASSWORD_RESET',
8+
IDENTITY_PASSWORD_CHANGE = 'IDENTITY_PASSWORD_CHANGE',
9+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export enum OnErrorType {
2+
CONTINUE = 'continue',
3+
STOP = 'stop',
4+
}

src/backend-runner/_executors/catch-all.executor.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import executorTask from '~/_common/tasks/executor.task';
1+
import { executorTask } from '~/_common/tasks/executor.task';
22
import { BackendRunnerService } from '../backend-runner.service';
33
import { ExecutorExecuteResponseInterface, ExecutorInterface } from '../executors.interface';
44
import { join } from 'path';
55
import { Job } from 'bullmq';
66
import { BackendConfigV1Dto } from '../_dto/backend-config-v1.dto';
77
import { BackendResultInterface } from '../_interfaces/backend-result.interface';
8-
import { ExecutorConfigInterface } from '~/_common/interfaces/executor-config.interface';
8+
import { BackendCodesEnum } from '../_interfaces/backend-codes.enum';
99

1010
export class CatchAllExecutor implements ExecutorInterface {
1111
public constructor(public service: BackendRunnerService) {}
@@ -39,30 +39,33 @@ export class CatchAllExecutor implements ExecutorInterface {
3939
}
4040

4141
public async executeBackend(job: Job, backend: BackendConfigV1Dto): Promise<BackendResultInterface> {
42-
const process = await executorTask(join(backend.path, 'bin', backend.actions[job.name].exec), job, {
43-
...this.service.config.get<ExecutorConfigInterface>('backendExecutorConfig'),
42+
const process = await executorTask(join(backend.path, 'bin', backend.actions[job.name].script), job, {
43+
...this.service.backendExecutorConfig,
4444
});
4545

4646
try {
4747
if (process.status !== 0) {
48+
this.service.logger.error(`Error executing backend ${backend.name}`);
4849
return {
4950
backend: backend.name,
5051
status: process.status,
5152
error: JSON.parse(process.output),
5253
};
5354
}
5455

56+
this.service.logger.log(`Backend ${backend.name} executed successfully`);
5557
return {
5658
backend: backend.name,
5759
status: process.status,
5860
output: JSON.parse(process.output),
5961
};
6062
} catch (e) {
63+
this.service.logger.error(`Error parsing JSON output from backend ${backend.name}`);
6164
return {
6265
backend: backend.name,
63-
status: process.status,
66+
status: BackendCodesEnum.INVALID_JSON_RESPONSE,
6467
error: {
65-
status: process.status,
68+
status: BackendCodesEnum.INVALID_JSON_RESPONSE,
6669
message: process.error,
6770
},
6871
};

src/backend-runner/_interfaces/backend-codes.enum.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ export enum BackendCodesEnum {
1313
CONNECTION_ERROR = 1 << 2,
1414
INVALID_LOGIN = 1 << 3,
1515
INVALID_CREDENTIALS = 1 << 4,
16+
INVALID_JSON_RESPONSE = 1 << 5,
1617
}

src/backend-runner/_validators/is-action-constraint.validator.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import {
44
ValidationArguments,
55
validateOrReject,
66
} from 'class-validator';
7-
import { ActionType, BackendConfigActionDto } from '../_dto/backend-config-v1.dto';
7+
import { BackendConfigActionDto } from '../_dto/backend-config-v1.dto';
8+
import { ActionType } from '../_enum/action-type.enum';
89

910
@ValidatorConstraint({ async: true })
1011
export class IsActionConstraintValidator implements ValidatorConstraintInterface {

0 commit comments

Comments
 (0)