From 607346afbe80b802a5eb7a3f92cf41ccee3b7ad9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Vi=C3=A9not?= Date: Tue, 5 Dec 2023 22:15:58 +0100 Subject: [PATCH 1/4] Add dryrun query parameter to /session/input-files and /session/verify-checked end-points. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Simon Viénot --- .../session-state/input-files.session-state.paths.yaml | 7 ++++++- .../verification/session-state/session-state.handlers.ts | 8 ++++++-- .../controllers/verification/verification.common.ts | 5 +++-- .../verify/session/verify.session.handlers.ts | 4 +++- .../verification/verify/session/verify.session.paths.yaml | 7 +++++++ 5 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/server/controllers/verification/session-state/input-files.session-state.paths.yaml b/src/server/controllers/verification/session-state/input-files.session-state.paths.yaml index 61cf2167..e18a9d54 100644 --- a/src/server/controllers/verification/session-state/input-files.session-state.paths.yaml +++ b/src/server/controllers/verification/session-state/input-files.session-state.paths.yaml @@ -1,5 +1,4 @@ openapi: "3.0.0" - paths: /session/input-files: post: @@ -39,6 +38,12 @@ paths: format: uri description: Remote file URL required: false + - name: dryrun + in: query + schema: + type: boolean + description: Dry-run flag. When set to true, a successful verification result will not be stored in the repository. + required: false responses: "200": description: Response is sent when the upload is successful under different conditions. diff --git a/src/server/controllers/verification/session-state/session-state.handlers.ts b/src/server/controllers/verification/session-state/session-state.handlers.ts index da503112..52c11181 100644 --- a/src/server/controllers/verification/session-state/session-state.handlers.ts +++ b/src/server/controllers/verification/session-state/session-state.handlers.ts @@ -40,6 +40,7 @@ export async function addInputFilesEndpoint(req: Request, res: Response) { return { path: pb.path, content: pb.buffer.toString(FILE_ENCODING) }; }); + const dryRun = Boolean(req.body.dryRun) const session = req.session; const newFilesCount = saveFiles(pathContents, session); if (newFilesCount) { @@ -48,7 +49,8 @@ export async function addInputFilesEndpoint(req: Request, res: Response) { session.contractWrappers, session, services.verification, - services.repository + services.repository, + dryRun ); } res.send(getSessionJSON(session)); @@ -102,6 +104,7 @@ export async function addInputContractEndpoint(req: Request, res: Response) { content: retrievedMetadataBase64, }); + const dryRun = Boolean(req.query.dryrun) const session = req.session; const newFilesCount = saveFiles(pathContents, session); @@ -112,7 +115,8 @@ export async function addInputContractEndpoint(req: Request, res: Response) { session.contractWrappers, session, services.verification, - services.repository + services.repository, + dryRun ); } res.send(getSessionJSON(session)); diff --git a/src/server/controllers/verification/verification.common.ts b/src/server/controllers/verification/verification.common.ts index a35c8953..2878803b 100644 --- a/src/server/controllers/verification/verification.common.ts +++ b/src/server/controllers/verification/verification.common.ts @@ -294,7 +294,8 @@ export const verifyContractsInSession = async ( contractWrappers: ContractWrapperMap, session: Session, verificationService: IVerificationService, - repositoryService: IRepositoryService + repositoryService: IRepositoryService, + dryRun: boolean = false ): Promise => { for (const id in contractWrappers) { const contractWrapper = contractWrappers[id]; @@ -379,7 +380,7 @@ export const verifyContractsInSession = async ( contractWrapper.status = match.status || "error"; contractWrapper.statusMessage = match.message; contractWrapper.storageTimestamp = match.storageTimestamp; - if (match.status) { + if (match.status && !dryRun) { await repositoryService.storeMatch(checkedContract, match); } } diff --git a/src/server/controllers/verification/verify/session/verify.session.handlers.ts b/src/server/controllers/verification/verify/session/verify.session.handlers.ts index 71442dad..005e461f 100644 --- a/src/server/controllers/verification/verify/session/verify.session.handlers.ts +++ b/src/server/controllers/verification/verify/session/verify.session.handlers.ts @@ -19,6 +19,7 @@ export async function verifyContractsInSessionEndpoint( throw new BadRequestError("There are currently no pending contracts."); } + const dryRun = Boolean(req.query.dryRun) const receivedContracts: SendableContract[] = req.body.contracts; const verifiable: ContractWrapperMap = {}; @@ -40,7 +41,8 @@ export async function verifyContractsInSessionEndpoint( verifiable, session, services.verification, - services.repository + services.repository, + dryRun ); res.send(getSessionJSON(session)); } diff --git a/src/server/controllers/verification/verify/session/verify.session.paths.yaml b/src/server/controllers/verification/verify/session/verify.session.paths.yaml index e8773c9f..52b77fba 100644 --- a/src/server/controllers/verification/verify/session/verify.session.paths.yaml +++ b/src/server/controllers/verification/verify/session/verify.session.paths.yaml @@ -31,6 +31,13 @@ paths: verificationId: type: string example: "0x3f67e9f57515bb1e7195c7c5af1eff630091567c0bb65ba3dece57a56da766fe" + parameters: + - name: dryrun + in: query + schema: + type: boolean + description: Dry-run flag. When set to true, a successful verification result will not be stored in the repository. + required: false responses: "200": description: OK From 6b4c5a2f867384e1f5e0f9f76dea9a5a6758c55c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Vi=C3=A9not?= Date: Thu, 7 Dec 2023 19:55:00 +0100 Subject: [PATCH 2/4] Document default value for dryrun query parameter in /session/input-files and /session/verify-checked end-points. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Simon Viénot --- .../session-state/input-files.session-state.paths.yaml | 3 ++- .../verification/verify/session/verify.session.paths.yaml | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/server/controllers/verification/session-state/input-files.session-state.paths.yaml b/src/server/controllers/verification/session-state/input-files.session-state.paths.yaml index e18a9d54..6049cc92 100644 --- a/src/server/controllers/verification/session-state/input-files.session-state.paths.yaml +++ b/src/server/controllers/verification/session-state/input-files.session-state.paths.yaml @@ -42,7 +42,8 @@ paths: in: query schema: type: boolean - description: Dry-run flag. When set to true, a successful verification result will not be stored in the repository. + default: false + description: Dry-run flag. When present and set to true, a successful verification result will not be stored in the repository. required: false responses: "200": diff --git a/src/server/controllers/verification/verify/session/verify.session.paths.yaml b/src/server/controllers/verification/verify/session/verify.session.paths.yaml index 52b77fba..e223d2ac 100644 --- a/src/server/controllers/verification/verify/session/verify.session.paths.yaml +++ b/src/server/controllers/verification/verify/session/verify.session.paths.yaml @@ -36,7 +36,8 @@ paths: in: query schema: type: boolean - description: Dry-run flag. When set to true, a successful verification result will not be stored in the repository. + default: false + description: Dry-run flag. When present and set to true, a successful verification result will not be stored in the repository. required: false responses: "200": From 6707fcc533f311e59dfb83dbe1482afe219b45b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Vi=C3=A9not?= Date: Thu, 7 Dec 2023 19:59:15 +0100 Subject: [PATCH 3/4] Fix use of dryrun query parameter in /session/input-files end-points. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Simon Viénot --- .../verification/session-state/session-state.handlers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server/controllers/verification/session-state/session-state.handlers.ts b/src/server/controllers/verification/session-state/session-state.handlers.ts index 52c11181..6549810a 100644 --- a/src/server/controllers/verification/session-state/session-state.handlers.ts +++ b/src/server/controllers/verification/session-state/session-state.handlers.ts @@ -40,7 +40,7 @@ export async function addInputFilesEndpoint(req: Request, res: Response) { return { path: pb.path, content: pb.buffer.toString(FILE_ENCODING) }; }); - const dryRun = Boolean(req.body.dryRun) + const dryRun = Boolean(req.query.dryrun) const session = req.session; const newFilesCount = saveFiles(pathContents, session); if (newFilesCount) { From f35d464329592492e5bcf97f5b880675aadb94d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Vi=C3=A9not?= Date: Thu, 7 Dec 2023 23:57:44 +0100 Subject: [PATCH 4/4] Add comment to clarify the new dryrun parameter. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Simon Viénot --- .../verification/session-state/session-state.handlers.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/server/controllers/verification/session-state/session-state.handlers.ts b/src/server/controllers/verification/session-state/session-state.handlers.ts index 6549810a..3d546b3a 100644 --- a/src/server/controllers/verification/session-state/session-state.handlers.ts +++ b/src/server/controllers/verification/session-state/session-state.handlers.ts @@ -40,6 +40,7 @@ export async function addInputFilesEndpoint(req: Request, res: Response) { return { path: pb.path, content: pb.buffer.toString(FILE_ENCODING) }; }); + // when undefined, the dryrun parameter interpreted as false const dryRun = Boolean(req.query.dryrun) const session = req.session; const newFilesCount = saveFiles(pathContents, session); @@ -104,6 +105,7 @@ export async function addInputContractEndpoint(req: Request, res: Response) { content: retrievedMetadataBase64, }); + // when undefined, the dryrun parameter interpreted as false const dryRun = Boolean(req.query.dryrun) const session = req.session;