Skip to content

Commit dfa8434

Browse files
committed
update to latest version: v1.0.3
1 parent 453fc81 commit dfa8434

16 files changed

+11868
-83
lines changed

.github/workflows/npm-publish.yml

+2-7
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,13 @@ name: NPM Publish
55

66
on:
77
release:
8-
types: [created]
8+
types: [published]
99

1010
jobs:
1111
publish-npm:
1212
runs-on: ubuntu-latest
1313
steps:
1414
- uses: actions/checkout@v3
15-
- uses: actions/setup-node@v3
16-
with:
17-
node-version: 16
18-
registry-url: https://registry.npmjs.org/
19-
- run: npm install
20-
- run: make build
15+
- run: make publish
2116
env:
2217
NODE_AUTH_TOKEN: ${{secrets.npm_token}}

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
**/node_modules/
33
**/output/
44
**/examples/**/dist/
5-
**/package-lock.json
5+
**/examples/**/package-lock.json
6+
coverage/

.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
registry = "https://registry.npmjs.org/"

CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# CHANGELOG
22

3+
## 1.0.3 - 2024-01-16
4+
5+
- Create static sha test file for unit test
6+
7+
## 1.0.2 - 2023-12-29
8+
9+
- Fix linting issues
10+
- Update generated protobuf file location in SDK
11+
312
## 1.0.1 - 2023-11-22
413

514
- Fix a minor bug to show correct valid regions in error messages

Dockerfile

+5-4
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,25 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
1212
USER su-amaas
1313

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

1819
WORKDIR /home/su-amaas
1920

20-
RUN npm install
21+
RUN npm ci
2122

2223
## Generate protobuf files
2324
RUN npx grpc_tools_node_protoc \
2425
--js_out=import_style=commonjs,binary:./src/lib \
2526
--grpc_out=grpc_js:./src/lib \
2627
--plugin=protoc-gen-grpc=./node_modules/.bin/grpc_tools_node_protoc_plugin \
27-
./scan.proto
28+
./protos/scan.proto
2829

2930
RUN protoc \
3031
--plugin=protoc-gen-ts=./node_modules/.bin/protoc-gen-ts \
3132
--ts_out=grpc_js:./src/lib \
32-
./scan.proto
33+
./protos/scan.proto
3334

3435
RUN mkdir -p ./output
3536

Makefile

+11-6
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,23 @@ endif
1515
all: clean build
1616

1717
build:
18-
cp ./protos/scan.proto scan.proto
19-
$(SED) 's/__PACKAGE_VERSION__/$(VERSION)/' ./package.json
18+
docker build \
19+
-t $(IMAGE_NAME) \
20+
--build-arg PACK_CMD=pack \
21+
--build-arg TM_AM_LOG_LEVEL=$(TM_AM_LOG_LEVEL) \
22+
.
23+
mkdir -p output
24+
docker run --rm $(IMAGE_NAME) tar -cz file-security-sdk-$(VERSION).tgz | tar xzf - -C output
25+
26+
publish:
2027
docker build \
2128
-t $(IMAGE_NAME) \
2229
--build-arg NPM_TOKEN=$(NODE_AUTH_TOKEN) \
2330
--build-arg PACK_CMD=publish \
2431
--build-arg TM_AM_LOG_LEVEL=$(TM_AM_LOG_LEVEL) \
2532
.
26-
$(SED) 's/$(VERSION)/__PACKAGE_VERSION__/' ./package.json
33+
2734
test:
28-
cp ./protos/scan.proto scan.proto
2935
docker build \
3036
--target unit_test \
3137
-t $(IMAGE_NAME) \
@@ -35,8 +41,7 @@ test:
3541

3642
clean:
3743
-@docker rmi -f $(IMAGE_NAME) || true
38-
rm -f scan.proto
3944
rm -rf output
4045
rm -rf coverage
4146

42-
.PHONY: all build test clean
47+
.PHONY: all build publish test clean

Makefile.dev

-43
This file was deleted.

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.1
1+
1.0.3

__tests__/amaasSDK.test.ts

+8-9
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { AmaasGrpcClient } from '../src/lib/amaasGrpcClient'
1313
import { AmaasScanResultObject } from '../src/lib/amaasScanResultObject'
1414
import { AmaasCredentials } from '../src/lib/amaasCredentials'
1515
import { Logger, LogLevel } from '../src/lib/logger'
16-
import * as scanPb from '../src/lib/scan_pb'
16+
import * as scanPb from '../src/lib/protos/scan_pb'
1717
import { isJWT, validateTags, getHashes, getBufferHashes } from '../src/lib/utils'
1818
import { readFile } from './utils/fileUtils'
1919
import { generateJwtToken } from './utils/jwtTokens'
@@ -28,7 +28,7 @@ const protoLoaderOptions = {
2828
defaults: true,
2929
oneofs: true
3030
}
31-
const scanProtoFile = path.resolve('./', 'scan.proto')
31+
const scanProtoFile = path.resolve('./protos/', 'scan.proto')
3232
const packageDefinition = loadSync(
3333
scanProtoFile,
3434
protoLoaderOptions
@@ -113,7 +113,7 @@ const credent: AmaasCredentials = {
113113
credentType: 'apikey',
114114
secret: authKey
115115
}
116-
const filesToScan = ['package-lock.json', 'jest.config.ts', 'scan.proto']
116+
const filesToScan = ['package-lock.json', 'jest.config.ts', './protos/scan.proto']
117117

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

@@ -391,13 +390,13 @@ describe('Utils testing', () => {
391390
}).toThrowError(error)
392391
})
393392
it('getHashes should return sha256 and sha1 correctly', async () => {
394-
await expect(getHashes(filesToScan[0], ['sha256', 'sha1'], 'hex'))
395-
.resolves.toEqual(['aee0f54d87f888dce437f56f7da52dc7c35081ae27218facd2ecd1d10e5552d6', '89e5eee8a309074bf3a71001a011adfaffadb4b3'])
393+
await expect(getHashes('__tests__/sha_test_file.txt', ['sha256', 'sha1'], 'hex'))
394+
.resolves.toEqual(['d2393511488886a425b8e514b25a2264aaa4aa4ac81ada9c4a8a47975747a955', 'c6afdcdc2841076fb94dd2f1985c595ad0fda864'])
396395
})
397396
it('getBufferHashes should return sha256 and sha1 correctly', async () => {
398-
const buff = readFile(filesToScan[0], statSync(filesToScan[0]).size)
397+
const buff = readFile('__tests__/sha_test_file.txt', statSync('__tests__/sha_test_file.txt').size)
399398
await expect(getBufferHashes(buff, ['sha256', 'sha1'], 'hex'))
400-
.resolves.toEqual(['aee0f54d87f888dce437f56f7da52dc7c35081ae27218facd2ecd1d10e5552d6', '89e5eee8a309074bf3a71001a011adfaffadb4b3'])
399+
.resolves.toEqual(['d2393511488886a425b8e514b25a2264aaa4aa4ac81ada9c4a8a47975747a955', 'c6afdcdc2841076fb94dd2f1985c595ad0fda864'])
401400
})
402401
it('validateTags should return true if each tag size does not exceed maxTagLength', async () => {
403402
const tags = ['tag1', 'tag2', 'tag3']

__tests__/sha_test_file.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is a dummy file for SHA-1 and SHA-256 unit test.

examples/README.md

+11-7
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ The following instructions assumes you are at the `<top level>/client/ts/example
1818
```sh
1919
cd cli/
2020
```
21+
2122
or
23+
2224
```sh
2325
cd cli-esm/
2426
```
@@ -75,6 +77,7 @@ The following instructions assumes you are at the `<top level>/client/ts/example
7577
```
7678

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

101-
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.
104+
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.
102105

103106
|Key|Value|Default value|
104107
|---|---|---|
105108
|TM_AM_SERVER_ADDR|`__YOUR_VISION_ONE_API_KEY_REGION__`|
106109
|TM_AM_AUTH_KEY|`__YOUR_VISION_ONE_API_KEY__`|
107110
|TM_AM_LOG_LEVEL|FATAL \| ERROR \| WARN \| INFO \| DEBUG| OFF |
108111

109-
3. Navigate to 'lambda/' or 'lambda-esm/'.
112+
1. Navigate to 'lambda/' or 'lambda-esm/'.
110113

111114
```sh
112115
cd lambda/
113116
```
117+
114118
or
115119

116120
```sh
117121
cd lambda-esm/
118122
```
119123

120-
4. Install dependencies. This will install the SDK and all required devDependencies.
124+
1. Install dependencies. This will install the SDK and all required devDependencies.
121125

122126
```sh
123127
npm install
124128
```
125129

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

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

133137
- fileScan:
134138

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

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

185-
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.
189+
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.
186190

187-
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.
191+
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.

0 commit comments

Comments
 (0)