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

Add step 1 and 2 (download enonce and immutable files)

parent 1638cde8
Branches
Tags
No related merge requests found
Pipeline #25597 passed
...@@ -2,5 +2,7 @@ ...@@ -2,5 +2,7 @@
<project version="4"> <project version="4">
<component name="VcsDirectoryMappings"> <component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" /> <mapping directory="$PROJECT_DIR$/.." vcs="Git" />
<mapping directory="$PROJECT_DIR$/src/shared" vcs="Git" />
<mapping directory="$PROJECT_DIR$/src/sharedByClients" vcs="Git" />
</component> </component>
</project> </project>
\ No newline at end of file
...@@ -4,20 +4,42 @@ const path = require('node:path'); ...@@ -4,20 +4,42 @@ const path = require('node:path');
require('dotenv').config({ path: path.join(__dirname, '../.env') }); require('dotenv').config({ path: path.join(__dirname, '../.env') });
require('./shared/helpers/TypeScriptExtensions'); // ATTENTION : This line MUST be the second of this file require('./shared/helpers/TypeScriptExtensions'); // ATTENTION : This line MUST be the second of this file
import * as fs from 'fs';
import chalk from 'chalk'; import chalk from 'chalk';
import HttpManager from './managers/HttpManager'; import HttpManager from './managers/HttpManager';
import DojoBackendManager from './managers/DojoBackendManager';
import Config from './config/Config';
(async () => {
HttpManager.registerAxiosInterceptor(); HttpManager.registerAxiosInterceptor();
console.log(chalk.blue('Dojo Exercice Checker')); console.log(chalk.blue('Dojo Exercice Checker'));
// Step 1: Read the dojo enonce file from the enonce repository /*
// Step 2: Download immutables files (maybe throw or show an error if the files have been modified ?) - Can be merged with step 1 Step 1 & 2:
- Read the dojo enonce file from the enonce repository
- Download immutables files (maybe throw or show an error if the files have been modified ?)
*/
const exerciceEnonce = await DojoBackendManager.getExerciceEnonce();
if ( !exerciceEnonce ) {
console.error(chalk.red(`Error while getting the exercice's enonce`));
process.exit(1);
}
exerciceEnonce.immutable.forEach(immutableFile => {
const filePath = `${ Config.filesFolder }/${ immutableFile.file_path }`.replace(/\/\//g, '/');
fs.mkdirSync(path.dirname(filePath), { recursive: true });
fs.writeFileSync(filePath, immutableFile.content, { encoding: 'base64' });
});
// Step 3: Run docker-compose file // Step 3: Run docker-compose file
// Step 4: Wait the end of the execution of the result container // Step 4: Wait the end of the execution of the result container
// Step 5: Get the result from the volume // Step 5: Get the result from the volume
// Step 6: Check content requirements and content size // Step 6: Check content requirements and content size
// Step 7: Upload and show the results // Step 7: Upload and show the results
})();
class Config {
public readonly filesFolder: string;
public exercice: {
id: string; secret: string;
};
constructor() {
this.filesFolder = process.env.FILES_FOLDER || './';
this.exercice = {
id : process.env.DOJO_EXERCICE_ID || '',
secret: process.env.DOJO_SECRET || ''
};
}
}
export default new Config();
import ClientsSharedConfig from '../sharedByClients/config/ClientsSharedConfig'; import ClientsSharedConfig from '../sharedByClients/config/ClientsSharedConfig';
import ApiRoutes from '../sharedByClients/types/ApiRoutes'; import ApiRoutes from '../sharedByClients/types/ApiRoutes';
import axios from 'axios';
import DojoResponse from '../shared/types/Dojo/DojoResponse';
import ExerciceEnonce from '../sharedByClients/models/ExerciceEnonce';
import Config from '../config/Config';
class DojoBackendManager { class DojoBackendManager {
public getApiUrl(route: ApiRoutes): string { public getApiUrl(route: ApiRoutes): string {
return `${ ClientsSharedConfig.apiURL }${ route }`; return `${ ClientsSharedConfig.apiURL }${ route }`;
} }
public async getExerciceEnonce(): Promise<ExerciceEnonce | undefined> {
try {
return (await axios.get<DojoResponse<ExerciceEnonce>>(this.getApiUrl(ApiRoutes.EXERCICE_ENONCE).replace('{{id}}', Config.exercice.id))).data.data;
} catch ( error ) {
return undefined;
}
}
} }
......
import axios, { AxiosRequestHeaders } from 'axios'; import axios, { AxiosRequestHeaders } from 'axios';
import FormData from 'form-data'; import FormData from 'form-data';
import ClientsSharedConfig from '../sharedByClients/config/ClientsSharedConfig'; import ClientsSharedConfig from '../sharedByClients/config/ClientsSharedConfig';
import Config from '../config/Config';
class HttpManager { class HttpManager {
...@@ -18,9 +19,13 @@ class HttpManager { ...@@ -18,9 +19,13 @@ class HttpManager {
} }
if ( config.url && (config.url.indexOf(ClientsSharedConfig.apiURL) !== -1) ) { if ( config.url && (config.url.indexOf(ClientsSharedConfig.apiURL) !== -1) ) {
config.headers['Accept-Encoding'] = 'gzip';
if ( config.data && Object.keys(config.data).length > 0 ) { if ( config.data && Object.keys(config.data).length > 0 ) {
config.headers['Content-Type'] = 'multipart/form-data'; config.headers['Content-Type'] = 'multipart/form-data';
} }
config.headers.Authorization = `ExerciceSecret ${ Config.exercice.secret }`;
} }
return config; return config;
......
Subproject commit c9154d42dac81311cf1957f0d75f806737849b40 Subproject commit bfca2c401e4b5ff69b0a515fd9dcab49d36ee212
Subproject commit 8fe8e9417a527cf2182a9acc440e68b99024487e Subproject commit b78ee5ffda1f10ffacf8cde47fbf45e76a3d9094
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment