Skip to content
Snippets Groups Projects
Commit 5eb40e87 authored by michael.minelli's avatar michael.minelli
Browse files

Files validation => Adapt to zod library

parent 989672df
No related branches found
No related tags found
No related merge requests found
...@@ -4,7 +4,6 @@ import SharedAssignmentHelper from '../../../shared/helpers/Dojo/SharedAssign ...@@ -4,7 +4,6 @@ import SharedAssignmentHelper from '../../../shared/helpers/Dojo/SharedAssign
import path from 'node:path'; import path from 'node:path';
import AssignmentCheckerError from '../../../shared/types/Dojo/AssignmentCheckerError'; import AssignmentCheckerError from '../../../shared/types/Dojo/AssignmentCheckerError';
import fs from 'fs-extra'; import fs from 'fs-extra';
import JSON5 from 'json5';
import ClientsSharedConfig from '../../config/ClientsSharedConfig'; import ClientsSharedConfig from '../../config/ClientsSharedConfig';
import YAML from 'yaml'; import YAML from 'yaml';
import DojoDockerCompose from '../../types/Dojo/DojoDockerCompose'; import DojoDockerCompose from '../../types/Dojo/DojoDockerCompose';
...@@ -133,16 +132,16 @@ class AssignmentValidator { ...@@ -133,16 +132,16 @@ class AssignmentValidator {
this.newSubStep('ASSIGNMENT_FILE_SCHEMA_VALIDATION', 'Validating dojo_assignment.json file schema'); this.newSubStep('ASSIGNMENT_FILE_SCHEMA_VALIDATION', 'Validating dojo_assignment.json file schema');
const validationResults = SharedAssignmentHelper.validateDescriptionFile(path.join(this.folderAssignment, ClientsSharedConfig.assignment.filename)); const validationResults = SharedAssignmentHelper.validateDescriptionFile(path.join(this.folderAssignment, ClientsSharedConfig.assignment.filename));
if ( !validationResults.isValid ) { if ( !validationResults.isValid ) {
this.emitError(`dojo_assignment.json file schema is invalid.\nHere are the errors:\n${ JSON5.stringify(validationResults.errors) }`, 'dojo_assignment.json file is invalid', AssignmentCheckerError.ASSIGNMENT_FILE_SCHEMA_ERROR); this.emitError(`dojo_assignment.json file schema is invalid.\nHere are the errors:\n${ validationResults.error }`, 'dojo_assignment.json file is invalid', AssignmentCheckerError.ASSIGNMENT_FILE_SCHEMA_ERROR);
return; return;
} }
assignmentFile = validationResults.results!; assignmentFile = validationResults.content!;
this.endSubStep('dojo_assignment.json file schema is valid', false); this.endSubStep('dojo_assignment.json file schema is valid', false);
// Immutable files validation (Check if exists and if the given type is correct) // Immutable files validation (Check if exists and if the given type is correct)
this.newSubStep('ASSIGNMENT_FILE_IMMUTABLES_VALIDATION', 'Validating immutable files'); this.newSubStep('ASSIGNMENT_FILE_IMMUTABLES_VALIDATION', 'Validating immutable files');
for ( const immutable of validationResults.results!.immutable ) { for ( const immutable of validationResults.content!.immutable ) {
const immutablePath = path.join(this.folderAssignment, immutable.path); const immutablePath = path.join(this.folderAssignment, immutable.path);
if ( !fs.existsSync(immutablePath) ) { if ( !fs.existsSync(immutablePath) ) {
this.emitError(`Immutable path not found: ${ immutable.path }`, 'dojo_assignment.json file is invalid', AssignmentCheckerError.IMMUTABLE_PATH_NOT_FOUND); this.emitError(`Immutable path not found: ${ immutable.path }`, 'dojo_assignment.json file is invalid', AssignmentCheckerError.IMMUTABLE_PATH_NOT_FOUND);
......
...@@ -2,12 +2,12 @@ import { TypedEmitter } from 'tiny-typed-emitter'; ...@@ -2,12 +2,12 @@ import { TypedEmitter } from 'tiny-typed-emitter';
import ExerciseRunningEvents from '../../types/Dojo/ExerciseRunningEvents'; import ExerciseRunningEvents from '../../types/Dojo/ExerciseRunningEvents';
import ExerciseCheckerError from '../../../shared/types/Dojo/ExerciseCheckerError'; import ExerciseCheckerError from '../../../shared/types/Dojo/ExerciseCheckerError';
import path from 'node:path'; import path from 'node:path';
import SharedExerciseHelper from '../../../shared/helpers/Dojo/SharedExerciseHelper';
import ClientsSharedConfig from '../../config/ClientsSharedConfig'; import ClientsSharedConfig from '../../config/ClientsSharedConfig';
import Toolbox from '../../../shared/helpers/Toolbox'; import Toolbox from '../../../shared/helpers/Toolbox';
import * as fs from 'fs-extra'; import * as fs from 'fs-extra';
import ExerciseResultsFile from '../../../shared/types/Dojo/ExerciseResultsFile'; import ExerciseResultsFile from '../../../shared/types/Dojo/ExerciseResultsFile';
import JSON5 from 'json5'; import JSON5 from 'json5';
import Json5FileValidator from '../../../shared/helpers/Json5FileValidator';
class ExerciseResultsSanitizerAndValidator { class ExerciseResultsSanitizerAndValidator {
...@@ -37,13 +37,13 @@ class ExerciseResultsSanitizerAndValidator { ...@@ -37,13 +37,13 @@ class ExerciseResultsSanitizerAndValidator {
// Results file schema validation // Results file schema validation
{ {
this.events.emit('step', 'VALIDATE_RESULTS_FILE', 'Validating results file schema'); this.events.emit('step', 'VALIDATE_RESULTS_FILE', 'Validating results file schema');
const validationResults = SharedExerciseHelper.validateResultFile(path); const validationResults = Json5FileValidator.validateFile(ExerciseResultsFile, path);
if ( !validationResults.isValid ) { if ( !validationResults.isValid ) {
this.events.emit('endStep', 'VALIDATE_RESULTS_FILE', `Results file is not valid. Here are the errors :\n${ JSON.stringify(validationResults.errors) }`, true); this.events.emit('endStep', 'VALIDATE_RESULTS_FILE', `Results file is not valid. Here are the errors :\n${ validationResults.error }`, true);
this.events.emit('finished', false, ExerciseCheckerError.EXERCISE_RESULTS_FILE_SCHEMA_NOT_VALID); this.events.emit('finished', false, ExerciseCheckerError.EXERCISE_RESULTS_FILE_SCHEMA_NOT_VALID);
return false; return false;
} }
this.exerciseResults = validationResults.results ?? {}; this.exerciseResults = validationResults.content ?? {};
this.events.emit('endStep', 'VALIDATE_RESULTS_FILE', 'Results file is valid', false); this.events.emit('endStep', 'VALIDATE_RESULTS_FILE', 'Results file is valid', false);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment