diff --git a/README.md b/README.md index 5e5dbc9649da7082367e40da5fee3dd242218eaa..577bc02967cbc4a094a14bea3cb1a74cd1ecc6f2 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ Certaines variables sensibles (mots de passe par exemple) sont stockées dans le | TREATMENT_FILE_PATH | Fichier qui contient la date du début du traitement. Dans le cas d'un traitement lancé via une tâche cron, cela permet de ne pas lancer un nouveau traitement tant que le précédent n'est pas terminé. | /tmp/rpa/treatment-json.log | | LOG_PATH | Dossier de stockage des fichiers de logs générés par l'application | /tmp/rpa/logs/ | | LOG_LEVEL | Niveau de log ("debug" pour le développement & tests ou "info" en production | "info" | -| SIZE_FILE_LIMIT | Taille maximun des fichiers en octets pouvant être transmis à Chorus | 10485760 | +| SIZE_FILE_LIMIT | Taille maximun des fichiers en octets pouvant être transmis à Chorus | Limite supprimée | | DELAY_BETWEEN_CHECK | Délais en millisecondes entre chaque traitement de fichier | 500 | | SERVER_HOST | Nom du serveur NodeJS qui expose l'API RPA du traitement | localhost | | SERVER_PORT | N° de port du serveur NodeJS qui expose l'API RPA du traitement | 3000 | diff --git a/deployment/configmap-pro.yaml b/deployment/configmap-pro.yaml index 8351f68bc7805e6ffa835798720b189c627de0c2..cce0b0a96431fa7d01a7159d2a29695d3c9b1e49 100644 --- a/deployment/configmap-pro.yaml +++ b/deployment/configmap-pro.yaml @@ -33,3 +33,4 @@ data: CHORUS_API_AUTH_URL: "https://oauth.piste.gouv.fr/api/oauth/token" CHORUS_API_URL: "https://api.piste.gouv.fr/esignature/v1/reports" NODE_TLS_REJECT_UNAUTHORIZED: "0" + SIZE_FILE_LIMIT: "15728640" # (15 Mo) Plus utilisé \ No newline at end of file diff --git a/deployment/configmap-rec.yaml b/deployment/configmap-rec.yaml index e3e42f545650440e6c13ff2f6d1aa9a2ec3b4d75..092856ecc23977f5bc51c41278995d9fa8451e8d 100644 --- a/deployment/configmap-rec.yaml +++ b/deployment/configmap-rec.yaml @@ -33,3 +33,4 @@ data: CHORUS_API_AUTH_URL: "https://sandbox-oauth.piste.gouv.fr/api/oauth/token" CHORUS_API_URL: "https://sandbox-api.piste.gouv.fr/esignature/v1/reports" NODE_TLS_REJECT_UNAUTHORIZED: "0" + SIZE_FILE_LIMIT: "15728640" # (15 Mo) Plus utilisé \ No newline at end of file diff --git a/deployment/cronjob.yaml b/deployment/cronjob.yaml index b9d3c475edb9bbade7b8ee2414d3fca951bd4808..a837f91621d707a49addf6c521fb4a386aafead4 100644 --- a/deployment/cronjob.yaml +++ b/deployment/cronjob.yaml @@ -12,7 +12,7 @@ spec: spec: containers: - name: signatures-task - image: registry.forge.grandlyon.com/systemes-dinformation/demat/rpa:{ENV} + image: registry.forge.grandlyon.com/systemes-dinformation/demat/verif-signatures:{ENV} args: - bash - '/usr/src/app/docker_execution/start-process-script.sh' diff --git a/documentation/GuideUtilisateur.md b/documentation/GuideUtilisateur.md index 03e1d42569e2287354b3d204cf0da445ad03362d..d3318cd8373da06d69da619804cf5ccdfa784a37 100644 --- a/documentation/GuideUtilisateur.md +++ b/documentation/GuideUtilisateur.md @@ -25,7 +25,6 @@ retracent tous les documents traités et le resultat du traitement. vue détaillée du traitement : > ### Pour chaque fichier retourné par la requête sur alfresco : > - Enregistrement du fichier<br> -> - Vérification de la taille du fichier téléchargé<br> - lié à l alimite de taille imposée par l'API chorus > - Soumission du fichier au service Chorus E-Signature via l'API si la taille est <= au paramètre de configuration<br> >>Si la signature est valide<br> >> - Une trace est écrite dans le fichier d'historisation<br> diff --git a/documentation/Specifications_Fonctionelles.XLSX b/documentation/Specifications_Fonctionelles.XLSX index b28e0e22893f8cb22b593f314a266eff9684376d..ebba8d166ff22a928aaafcecdd8b27ef5acd8e89 100644 Binary files a/documentation/Specifications_Fonctionelles.XLSX and b/documentation/Specifications_Fonctionelles.XLSX differ diff --git a/src/config/config.js b/src/config/config.js index 13d7646b1231f8e9c0db66f93e524024885c4818..68108cd44908f6a2d6e0c7af3af422a3766ae8cd 100644 --- a/src/config/config.js +++ b/src/config/config.js @@ -96,7 +96,7 @@ const config = { chorus_api_url: env.chorusApiUrl ? env.chorusApiUrl : "XXX", - sizeFileLimit: env.size_File_Limit ? env.size_File_Limit : 10485760, //Taille en octets (10Mo) = 10485760 + sizeFileLimit: env.size_File_Limit ? env.size_File_Limit : 10485760, //Taille en octets (10Mo) = 10485760 // Plus de contrôle sur la taille des fichiers delayBetweenCheck: env.delay_Between_Check ? env.delay_Between_Check : 500, }, server_settings:{ diff --git a/src/process_documents.js b/src/process_documents.js index d73c6b854cf3fe2a14a7382b5882df73c1c91ec7..fbbd64ed3ea032f03bfd88a1c34280ea10d21745 100644 --- a/src/process_documents.js +++ b/src/process_documents.js @@ -212,7 +212,7 @@ async function prepareAlfrescoFolderForResults(parentNodeId, autoRename) { "cm:description": "Dossier résultat application RPA", } }; - try{ + try { await nodesApi.createNode(parentNodeId, nodeBody, optsCreateNode); } catch (error) { //The folder already exist @@ -228,7 +228,7 @@ async function prepareAlfrescoFolderForResults(parentNodeId, autoRename) { }, relativePath: folderYearName }; - try{ + try { await nodesApi.createNode(parentNodeId, nodeBody, optsCreateNode); } catch (error) { //The folder already exist @@ -244,7 +244,7 @@ async function prepareAlfrescoFolderForResults(parentNodeId, autoRename) { }, relativePath: folderYearName + '/' + folderMonthName }; - try{ + try { await nodesApi.createNode(parentNodeId, nodeBody, optsCreateNode); } catch (error) { //The folder already exist @@ -269,12 +269,12 @@ async function uploadFileToAlfresco( let uploadReturn = await uploadApi.uploadFile( fileToUpload, relativePath, - parentFolderId, + parentFolderId, null, - {autoRename: true} + { autoRename: true } ); - if(!(isSetCodeNature === undefined)){ - if(isSetCodeNature == true) { + if (!(isSetCodeNature === undefined)) { + if (isSetCodeNature == true) { nodeBodyUpdate.name = uploadReturn.entry.name; nodeBodyUpdate.aspectNames = uploadReturn.entry.aspectNames; @@ -295,15 +295,15 @@ async function uploadFileToAlfresco( } //Get full path of the document -async function getFolderPathName(nodeParentId, lastNodeName){ - if(nodeParentId === undefined){ +async function getFolderPathName(nodeParentId, lastNodeName) { + if (nodeParentId === undefined) { return lastNodeName; } let nodeRef = await nodesApi.getNode(nodeParentId); - let retourPath =undefined; + let retourPath = undefined; - if(lastNodeName === undefined){ + if (lastNodeName === undefined) { retourPath = nodeRef.entry.name; } else { retourPath = nodeRef.entry.name + '/' + lastNodeName; @@ -398,7 +398,7 @@ const getDocumentsFromAlfresco = async ( //Initialize value for progressBar let progressValueUnit = 0; let progressValue = 0; - if(data.list.pagination.totalItems > 0) { + if (data.list.pagination.totalItems > 0) { progressValueUnit = 100 / data.list.pagination.totalItems; } socket?.emit('logmessage', data.list.pagination.totalItems + ' fichiers vont être traités'); @@ -442,137 +442,118 @@ const getDocumentsFromAlfresco = async ( Buffer.from(buffer) ); - //Verify signature from Chorus - //Get the file size - const statsFile = await fs.promises.stat(tocheck_path + "/" + doc.name); - let fileSize = statsFile.size; - - //File size must not exceed the limit - if (fileSize <= sizeFileLimit) { - appendFile( - historisationPathFileName, - "Checking file : " + doc.name + "\n" - ); + appendFile( + historisationPathFileName, + "Checking file : " + doc.name + "\n" + ); - try { - var options = undefined; - - if (!(proxyUrl === undefined)) { - options = { - method: "POST", - url: chorus_api_url, - headers: { - Authorization: "Bearer " + fromApiAuth.access_token, - }, - proxy: proxyUrl, - formData: { - clientIdentification: chorus_api_client_id, - originalFiles: "", - reportType: chorus_api_report_type, - signedDocument: { - value: fs.createReadStream(`${tocheck_path}/${doc.name}`), - options: { - filename: `${tocheck_path}/${doc.name}`, - contentType: null, - }, + try { + var options = undefined; + + if (!(proxyUrl === undefined)) { + options = { + method: "POST", + url: chorus_api_url, + headers: { + Authorization: "Bearer " + fromApiAuth.access_token, + }, + proxy: proxyUrl, + formData: { + clientIdentification: chorus_api_client_id, + originalFiles: "", + reportType: chorus_api_report_type, + signedDocument: { + value: fs.createReadStream(`${tocheck_path}/${doc.name}`), + options: { + filename: `${tocheck_path}/${doc.name}`, + contentType: null, }, }, - }; - } else { - options = { - method: "POST", - url: chorus_api_url, - headers: { - Authorization: "Bearer " + fromApiAuth.access_token, - }, - formData: { - clientIdentification: chorus_api_client_id, - originalFiles: "", - reportType: chorus_api_report_type, - signedDocument: { - value: fs.createReadStream(`${tocheck_path}/${doc.name}`), - options: { - filename: `${tocheck_path}/${doc.name}`, - contentType: null, - }, + }, + }; + } else { + options = { + method: "POST", + url: chorus_api_url, + headers: { + Authorization: "Bearer " + fromApiAuth.access_token, + }, + formData: { + clientIdentification: chorus_api_client_id, + originalFiles: "", + reportType: chorus_api_report_type, + signedDocument: { + value: fs.createReadStream(`${tocheck_path}/${doc.name}`), + options: { + filename: `${tocheck_path}/${doc.name}`, + contentType: null, }, }, - }; - } - const resultApiFileCheck = new Promise((resolve, reject) => { - request(options, function (error, response) { - console.log(response); - if (error) throw error; - return resolve(response); - }); + }, + }; + } + const resultApiFileCheck = new Promise((resolve, reject) => { + request(options, function (error, response) { + console.log(response); + if (error) throw error; + return resolve(response); }); + }); - const fromApiResultCheck = await resultApiFileCheck; + const fromApiResultCheck = await resultApiFileCheck; - let returnResultCheck = await tools.writeResultCheckToFileLogAppApi( - historisationPathFileName, - fromApiResultCheck, - doc.name - ); + let returnResultCheck = await tools.writeResultCheckToFileLogAppApi( + historisationPathFileName, + fromApiResultCheck, + doc.name + ); - numberFilesChorusSigned += - returnResultCheck.numberFilesChorusSigned; - numberFilesChorusSignedError += - returnResultCheck.numberFilesChorusSignedError; - numberFilesChorusNotSigned += - returnResultCheck.numberFilesChorusNotSigned; - - //If Chorus test signature OK, add tag to document in Alfresco - if (returnResultCheck.numberFilesChorusSigned == 1 || returnResultCheck.numberFilesChorusSignedError == 1) { - let optsCreateTag = undefined; - - if(returnResultCheck.numberFilesChorusSigned == 1) { - let tagRetour = await tagsApi.createTagForNode( - doc.id, - '{"tag":"' + alfresco_tag_rpa + '"}', - optsCreateTag - ); - } - if(returnResultCheck.numberFilesChorusSignedError == 1) { - let tagRetour = await tagsApi.createTagForNode( - doc.id, - '{"tag":"' + alfresco_tag_rpa_err + '"}', - optsCreateTag - ); - } - - //Load the file Chorus report in the same folder (parentId) as the source file - await uploadFileToAlfresco( - doc.parentId, - "", - returnResultCheck.fileNameChorusReport, - true + numberFilesChorusSigned += + returnResultCheck.numberFilesChorusSigned; + numberFilesChorusSignedError += + returnResultCheck.numberFilesChorusSignedError; + numberFilesChorusNotSigned += + returnResultCheck.numberFilesChorusNotSigned; + + //If Chorus test signature OK, add tag to document in Alfresco + if (returnResultCheck.numberFilesChorusSigned == 1 || returnResultCheck.numberFilesChorusSignedError == 1) { + let optsCreateTag = undefined; + + if (returnResultCheck.numberFilesChorusSigned == 1) { + let tagRetour = await tagsApi.createTagForNode( + doc.id, + '{"tag":"' + alfresco_tag_rpa + '"}', + optsCreateTag + ); + } + if (returnResultCheck.numberFilesChorusSignedError == 1) { + let tagRetour = await tagsApi.createTagForNode( + doc.id, + '{"tag":"' + alfresco_tag_rpa_err + '"}', + optsCreateTag ); } - await tools.sleep(delayBetweenCheck); - - progressValue = progressValueUnit * numberFilesControled; - socket?.emit('progress', progressValue); - } catch (error) { - tools.writeToFileLog(error, "errors"); - appendFile( - historisationPathFileName, - "Error in signature control in Chorus : see errors file\n\n" + //Load the file Chorus report in the same folder (parentId) as the source file + await uploadFileToAlfresco( + doc.parentId, + "", + returnResultCheck.fileNameChorusReport, + true ); - console.log("An error occured", error); } - } else { - //Size too big to be uploaded to Chorus - numberFilesSizeTooBig += 1; + await tools.sleep(delayBetweenCheck); + + progressValue = progressValueUnit * numberFilesControled; + socket?.emit('progress', progressValue); + + } catch (error) { + tools.writeToFileLog(error, "errors"); appendFile( historisationPathFileName, - "The file : " + - doc.name + - " exceeded the size limit : " + - sizeFileLimit + - "\n" + "Error in signature control in Chorus : see errors file\n\n" ); + console.log("An error occured", error); } } } @@ -602,17 +583,17 @@ const processDocsFromAlfresco = async ( JSON.stringify({ lastTreatmentDate: dateStart }, null, 4) ); - socket?.emit('logmessage','Nettoyage des dossiers de travail'); + socket?.emit('logmessage', 'Nettoyage des dossiers de travail'); // Clean download directory tools.cleanDir(tocheck_path); // Clean report directory tools.cleanDir(checked_path); - + //Alfresco prepare for authentification - // if (fromApiAuth === undefined) { //Correction erreur HTTP 401 + // if (fromApiAuth === undefined) { //Correction erreur HTTP 401 var result = new Promise((resolve, reject) => { request(options, function (error, response, body) { if (error) { @@ -624,13 +605,13 @@ const processDocsFromAlfresco = async ( }); fromApiAuth = await result; - // } + // } //if (loginTicket === undefined) { //Correction erreur HTTP 401 loginTicket = await alfrescoSdk.login( alfresco_username, alfresco_password - ); + ); tagsApi = new PaquetAfresco.TagsApi(alfrescoSdk); nodesApi = new PaquetAfresco.NodesApi(alfrescoSdk); queriesApi = new PaquetAfresco.QueriesApi(alfrescoSdk); @@ -639,7 +620,7 @@ const processDocsFromAlfresco = async ( //} //Alfresco create folder for results with relative path : year/month/day - let folderRelativePathForResults = await prepareAlfrescoFolderForResults( alfresco_rootNodeID_for_results, false); + let folderRelativePathForResults = await prepareAlfrescoFolderForResults(alfresco_rootNodeID_for_results, false); //Report data dateStart = new Date(); @@ -765,7 +746,7 @@ const processDocsFromAlfresco = async ( ); } catch (error) { //Delete file if error - socket?.emit('logmessage','An error occured ' + error); + socket?.emit('logmessage', 'An error occured ' + error); if (fs.existsSync(treatment_File_Path)) { fs.rmSync(treatment_File_Path); }