Skip to content

Commit

Permalink
Merge pull request #10 from trendmicro/update_to_latest_version_v1.0.3
Browse files Browse the repository at this point in the history
update to latest version: v1.0.3
  • Loading branch information
trend-wesley-hsu authored Jan 22, 2024
2 parents 453fc81 + dfa8434 commit cca0562
Show file tree
Hide file tree
Showing 16 changed files with 11,868 additions and 83 deletions.
9 changes: 2 additions & 7 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,13 @@ name: NPM Publish

on:
release:
types: [created]
types: [published]

jobs:
publish-npm:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
registry-url: https://registry.npmjs.org/
- run: npm install
- run: make build
- run: make publish
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
**/node_modules/
**/output/
**/examples/**/dist/
**/package-lock.json
**/examples/**/package-lock.json
coverage/
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
registry = "https://registry.npmjs.org/"
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# CHANGELOG

## 1.0.3 - 2024-01-16

- Create static sha test file for unit test

## 1.0.2 - 2023-12-29

- Fix linting issues
- Update generated protobuf file location in SDK

## 1.0.1 - 2023-11-22

- Fix a minor bug to show correct valid regions in error messages
Expand Down
9 changes: 5 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,25 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
USER su-amaas

## Copy source codes and documents
COPY --chown=su-amaas:su-amaas package.json scan.proto tsconfig.json LICENSE .eslintrc.json README.md /home/su-amaas/
COPY --chown=su-amaas:su-amaas package.json package-lock.json tsconfig.json LICENSE .eslintrc.json README.md /home/su-amaas/
COPY --chown=su-amaas:su-amaas protos /home/su-amaas/protos
COPY --chown=su-amaas:su-amaas src /home/su-amaas/src

WORKDIR /home/su-amaas

RUN npm install
RUN npm ci

## Generate protobuf files
RUN npx grpc_tools_node_protoc \
--js_out=import_style=commonjs,binary:./src/lib \
--grpc_out=grpc_js:./src/lib \
--plugin=protoc-gen-grpc=./node_modules/.bin/grpc_tools_node_protoc_plugin \
./scan.proto
./protos/scan.proto

RUN protoc \
--plugin=protoc-gen-ts=./node_modules/.bin/protoc-gen-ts \
--ts_out=grpc_js:./src/lib \
./scan.proto
./protos/scan.proto

RUN mkdir -p ./output

Expand Down
17 changes: 11 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,23 @@ endif
all: clean build

build:
cp ./protos/scan.proto scan.proto
$(SED) 's/__PACKAGE_VERSION__/$(VERSION)/' ./package.json
docker build \
-t $(IMAGE_NAME) \
--build-arg PACK_CMD=pack \
--build-arg TM_AM_LOG_LEVEL=$(TM_AM_LOG_LEVEL) \
.
mkdir -p output
docker run --rm $(IMAGE_NAME) tar -cz file-security-sdk-$(VERSION).tgz | tar xzf - -C output

publish:
docker build \
-t $(IMAGE_NAME) \
--build-arg NPM_TOKEN=$(NODE_AUTH_TOKEN) \
--build-arg PACK_CMD=publish \
--build-arg TM_AM_LOG_LEVEL=$(TM_AM_LOG_LEVEL) \
.
$(SED) 's/$(VERSION)/__PACKAGE_VERSION__/' ./package.json

test:
cp ./protos/scan.proto scan.proto
docker build \
--target unit_test \
-t $(IMAGE_NAME) \
Expand All @@ -35,8 +41,7 @@ test:

clean:
-@docker rmi -f $(IMAGE_NAME) || true
rm -f scan.proto
rm -rf output
rm -rf coverage

.PHONY: all build test clean
.PHONY: all build publish test clean
43 changes: 0 additions & 43 deletions Makefile.dev

This file was deleted.

2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.1
1.0.3
17 changes: 8 additions & 9 deletions __tests__/amaasSDK.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { AmaasGrpcClient } from '../src/lib/amaasGrpcClient'
import { AmaasScanResultObject } from '../src/lib/amaasScanResultObject'
import { AmaasCredentials } from '../src/lib/amaasCredentials'
import { Logger, LogLevel } from '../src/lib/logger'
import * as scanPb from '../src/lib/scan_pb'
import * as scanPb from '../src/lib/protos/scan_pb'
import { isJWT, validateTags, getHashes, getBufferHashes } from '../src/lib/utils'
import { readFile } from './utils/fileUtils'
import { generateJwtToken } from './utils/jwtTokens'
Expand All @@ -28,7 +28,7 @@ const protoLoaderOptions = {
defaults: true,
oneofs: true
}
const scanProtoFile = path.resolve('./', 'scan.proto')
const scanProtoFile = path.resolve('./protos/', 'scan.proto')
const packageDefinition = loadSync(
scanProtoFile,
protoLoaderOptions
Expand Down Expand Up @@ -113,7 +113,7 @@ const credent: AmaasCredentials = {
credentType: 'apikey',
secret: authKey
}
const filesToScan = ['package-lock.json', 'jest.config.ts', 'scan.proto']
const filesToScan = ['package-lock.json', 'jest.config.ts', './protos/scan.proto']

// Disable NodeJS gRPC DNS resolution when localhost is used to fix process doesn't exit immediately issue
const server = new Server({ 'grpc.service_config_disable_resolution': 1 })
Expand Down Expand Up @@ -305,10 +305,9 @@ describe('error testing', () => {
it('should return an error when incorrect TLS protocol is used', async () => {
const amaasGrpcClient = new AmaasGrpcClient(amaasHostName, authKey)
expect(amaasGrpcClient).toBeDefined()
const error = new Error('Service is not reachable. No connection established')
await expect(async () => {
await amaasGrpcClient.scanFile(filesToScan[0])
}).rejects.toEqual(error)
}).rejects.toThrow('Service is not reachable. No connection established')
amaasGrpcClient.close()
})

Expand Down Expand Up @@ -391,13 +390,13 @@ describe('Utils testing', () => {
}).toThrowError(error)
})
it('getHashes should return sha256 and sha1 correctly', async () => {
await expect(getHashes(filesToScan[0], ['sha256', 'sha1'], 'hex'))
.resolves.toEqual(['aee0f54d87f888dce437f56f7da52dc7c35081ae27218facd2ecd1d10e5552d6', '89e5eee8a309074bf3a71001a011adfaffadb4b3'])
await expect(getHashes('__tests__/sha_test_file.txt', ['sha256', 'sha1'], 'hex'))
.resolves.toEqual(['d2393511488886a425b8e514b25a2264aaa4aa4ac81ada9c4a8a47975747a955', 'c6afdcdc2841076fb94dd2f1985c595ad0fda864'])
})
it('getBufferHashes should return sha256 and sha1 correctly', async () => {
const buff = readFile(filesToScan[0], statSync(filesToScan[0]).size)
const buff = readFile('__tests__/sha_test_file.txt', statSync('__tests__/sha_test_file.txt').size)
await expect(getBufferHashes(buff, ['sha256', 'sha1'], 'hex'))
.resolves.toEqual(['aee0f54d87f888dce437f56f7da52dc7c35081ae27218facd2ecd1d10e5552d6', '89e5eee8a309074bf3a71001a011adfaffadb4b3'])
.resolves.toEqual(['d2393511488886a425b8e514b25a2264aaa4aa4ac81ada9c4a8a47975747a955', 'c6afdcdc2841076fb94dd2f1985c595ad0fda864'])
})
it('validateTags should return true if each tag size does not exceed maxTagLength', async () => {
const tags = ['tag1', 'tag2', 'tag3']
Expand Down
1 change: 1 addition & 0 deletions __tests__/sha_test_file.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is a dummy file for SHA-1 and SHA-256 unit test.
18 changes: 11 additions & 7 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ The following instructions assumes you are at the `<top level>/client/ts/example
```sh
cd cli/
```

or

```sh
cd cli-esm/
```
Expand Down Expand Up @@ -75,6 +77,7 @@ The following instructions assumes you are at the `<top level>/client/ts/example
```

- batchBufferScan

```sh
SOURCE=batchBufferScan.ts npm run build # cli
```
Expand All @@ -98,37 +101,38 @@ The following instructions assumes you are at the `<top level>/client/ts/example
- Handler: index.handler
- Architecture: x86_64 or arm64

2. Set up environment variables for your function by clicking on "Configuration" and then "Environment variables". Add the following keys and values. Replace `__YOUR_VISION_ONE_API_KEY_REGION__` and `__YOUR_VISION_ONE_API_KEY__` with your own API key region and Vision One API key.
1. Set up environment variables for your function by clicking on "Configuration" and then "Environment variables". Add the following keys and values. Replace `__YOUR_VISION_ONE_API_KEY_REGION__` and `__YOUR_VISION_ONE_API_KEY__` with your own API key region and Vision One API key.

|Key|Value|Default value|
|---|---|---|
|TM_AM_SERVER_ADDR|`__YOUR_VISION_ONE_API_KEY_REGION__`|
|TM_AM_AUTH_KEY|`__YOUR_VISION_ONE_API_KEY__`|
|TM_AM_LOG_LEVEL|FATAL \| ERROR \| WARN \| INFO \| DEBUG| OFF |

3. Navigate to 'lambda/' or 'lambda-esm/'.
1. Navigate to 'lambda/' or 'lambda-esm/'.

```sh
cd lambda/
```

or

```sh
cd lambda-esm/
```

4. Install dependencies. This will install the SDK and all required devDependencies.
1. Install dependencies. This will install the SDK and all required devDependencies.

```sh
npm install
```

5. You should have the a 7-Zip executable (v16.02 or greater) available in your system.
1. You should have the a 7-Zip executable (v16.02 or greater) available in your system.

- On Debian and Ubuntu install the p7zip-full package or use 7-Zip 21.02 alpha or higher
- On Mac OSX use Homebrew brew install p7zip
- On Windows get 7-Zip from 7-Zip download page.
6. Build the example by running one of the following commands:
1. Build the example by running one of the following commands:

- fileScan:

Expand Down Expand Up @@ -182,6 +186,6 @@ The following instructions assumes you are at the `<top level>/client/ts/example

An archive file `index.zip` which contains index.js and node_modules will be generated under the 'dist/' directory.

7. Deploy `dist/index.zip` to your Lambda function created in step 1 by clicking on "Function code" and then "Upload from" and selecting the index.zip file.
1. Deploy `dist/index.zip` to your Lambda function created in step 1 by clicking on "Function code" and then "Upload from" and selecting the index.zip file.

8. Create a test for your function by clicking on "Configure test events" and then "Create new test event". Choose "Hello World" as the template and click "Create". Click "Test" to run the test.
1. Create a test for your function by clicking on "Configure test events" and then "Create new test event". Choose "Hello World" as the template and click "Create". Click "Test" to run the test.
Loading

0 comments on commit cca0562

Please sign in to comment.