Skip to content

Commit

Permalink
Merge pull request #8068 from opengovsg/release_v6.176.0
Browse files Browse the repository at this point in the history
* feat: add retry for clamav init (#8067)

* feat: add retry for clamav init

* fix: incorrect mock test implementation

---------

Co-authored-by: Ken <[email protected]>

* chore: update virus-scanner node version (#8069)

* chore: bump version to v6.176.0

---------

Co-authored-by: Kevin Foong <[email protected]>
  • Loading branch information
KenLSM and kevin9foong authored Jan 23, 2025
2 parents e2de0a3 + f36ffcf commit 9816c9c
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 23 deletions.
20 changes: 15 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,31 @@ All notable changes to this project will be documented in this file. Dates are d

Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

#### [v6.175.0](https://github.com/opengovsg/FormSG/compare/v6.175.0...v6.175.0)
#### [v6.176.0](https://github.com/opengovsg/FormSG/compare/v6.176.0...v6.176.0)

- feat: speed up encryption and decryption with precomputation [`#8052`](https://github.com/opengovsg/FormSG/pull/8052)
- fix(deps): bump libphonenumber-js from 1.11.17 to 1.11.18 in /shared [`#8057`](https://github.com/opengovsg/FormSG/pull/8057)
- chore: update virus-scanner node version [`#8069`](https://github.com/opengovsg/FormSG/pull/8069)

#### [v6.176.0](https://github.com/opengovsg/FormSG/compare/v6.175.0...v6.176.0)

> 23 January 2025

- feat: add retry for clamav init [`#8067`](https://github.com/opengovsg/FormSG/pull/8067)
- build: merge release v6.175.0 to develop [`#8064`](https://github.com/opengovsg/FormSG/pull/8064)
- build: release v6.175.0 [`#8055`](https://github.com/opengovsg/FormSG/pull/8055)
- chore: bump version to v6.176.0 [`c308767`](https://github.com/opengovsg/FormSG/commit/c3087674f6b2adb7f36fc6e712db8d211addfb76)

#### [v6.175.0](https://github.com/opengovsg/FormSG/compare/v6.174.0...v6.175.0)

> 16 January 2025
> 20 January 2025

- feat: speed up encryption and decryption with precomputation [`#8052`](https://github.com/opengovsg/FormSG/pull/8052)
- fix(deps): bump libphonenumber-js from 1.11.17 to 1.11.18 in /shared [`#8057`](https://github.com/opengovsg/FormSG/pull/8057)
- fix: paragraph markdown styling error [`#8051`](https://github.com/opengovsg/FormSG/pull/8051)
- build: merge release v6.174.0 to develop [`#8050`](https://github.com/opengovsg/FormSG/pull/8050)
- * fix(deps): bump libphonenumber-js from 1.11.16 to 1.11.17 in /shared (#8021) [`#8039`](https://github.com/opengovsg/FormSG/pull/8039)
- fix(deps): bump zod from 3.23.8 to 3.24.1 in /shared [`#7996`](https://github.com/opengovsg/FormSG/pull/7996)
- fix(deps): bump type-fest from 4.30.2 to 4.32.0 in /shared [`#8037`](https://github.com/opengovsg/FormSG/pull/8037)
- chore: bump version to v6.175.0 [`1aac70b`](https://github.com/opengovsg/FormSG/commit/1aac70bd7210d5862bd46b129ec86afc7ceccc50)
- chore: bump version to v6.175.0 [`d31bb97`](https://github.com/opengovsg/FormSG/commit/d31bb9717625d365d6798a51d8235b5acdab706c)

#### [v6.174.0](https://github.com/opengovsg/FormSG/compare/v6.173.1...v6.174.0)

Expand Down
4 changes: 2 additions & 2 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "form-frontend",
"version": "6.175.0",
"version": "6.176.0",
"homepage": ".",
"type": "module",
"private": true,
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "FormSG",
"description": "Form Manager for Government",
"version": "6.175.0",
"version": "6.176.0",
"homepage": "https://form.gov.sg",
"authors": [
"FormSG <[email protected]>"
Expand Down
2 changes: 1 addition & 1 deletion serverless/virus-scanner/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:16.20-bullseye-slim
FROM node:18.12-bullseye-slim

# Install aws-lambda-cpp build dependencies
RUN apt-get update && \
Expand Down
8 changes: 2 additions & 6 deletions serverless/virus-scanner/src/__tests/clamscan.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,8 @@ let scanResult: {
jest.mock('clamscan', () => {
return jest.fn().mockImplementation(() => {
return {
init: jest.fn().mockImplementation(() => {
return {
scanStream: jest.fn().mockImplementation(() => {
return scanResult
}),
}
init: jest.fn().mockResolvedValue({
scanStream: jest.fn().mockResolvedValue(scanResult),
}),
}
})
Expand Down
37 changes: 32 additions & 5 deletions serverless/virus-scanner/src/clamscan.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,45 @@ import internal from 'stream'
import { getLambdaLogger } from './logger'
import { ScanFileStreamResult } from './types'

const MAX_RETRIES = 3
const RETRY_INTERVAL_MS = 1000

const retryFunction = <T>(
func: () => Promise<T>,
retries: number,
interval: number,
): Promise<T> => {
return new Promise((resolve, reject) => {
const attempt = () => {
func()
.then(resolve)
.catch((error) => {
if (retries === 0) {
reject(error)
} else {
setTimeout(() => {
retries--
attempt()
}, interval)
}
})
}
attempt()
})
}

export async function scanFileStream(
s3Stream: internal.Readable,
): Promise<ScanFileStreamResult> {
const logger = getLambdaLogger('scanFileStream')

logger.info('Scanning file stream')

const scanner = await new NodeClam().init({
clamdscan: {
socket: '/tmp/clamd.ctl',
},
})
const scanner = await retryFunction<NodeClam>(
() => new NodeClam().init({ clamdscan: { socket: '/tmp/clamd.ctl' } }),
MAX_RETRIES,
RETRY_INTERVAL_MS,
)

const { isInfected: isMalicious, viruses: virusMetadata } =
await scanner.scanStream(s3Stream)
Expand Down

0 comments on commit 9816c9c

Please sign in to comment.