Compare commits

..

7 Commits

Author SHA1 Message Date
Duan-0916
c6beb142f3
chore: Add Code Scan Action (#113)
Motivation:

为了增强代码审查流程并确保代码的安全性和合规性,我新增了代码安全扫描和开源组件扫描。通过加入这些扫描,我们可以识别潜在的漏洞,并确保代码库符合开源项目治理标准化的要求。

Modification:

新增了cloud_code_scan.yml模板,添加了代码安全扫描和开源组件扫描步骤。这些步骤将作为工作流的一部分进行执行,以执行必要的安全检查和合规性验证。通过添加这些扫描,我们可以积极解决安全问题,并确保遵守开源许可协议。

Result:

通过引入代码安全扫描和开源组件扫描,增强了代码审查流程。它有助于识别安全漏洞,并确保符合开源许可要求。这一改进有助于提高代码库的整体质量和安全性。
2023-12-01 22:54:35 +08:00
semantic-release-bot
81fcb24288 Release 2.10.0
[skip ci]

## [2.10.0](https://github.com/sofastack/sofa-rpc-node/compare/v2.9.0...v2.10.0) (2023-05-22)

### Features

* remove debug deps ([#112](https://github.com/sofastack/sofa-rpc-node/issues/112)) ([aada766](aada7662fa))
2023-05-22 06:52:49 +00:00
fengmk2
aada7662fa
feat: remove debug deps (#112) 2023-05-22 14:51:59 +08:00
semantic-release-bot
489eb7f497 Release 2.9.0
[skip ci]

## [2.9.0](https://github.com/sofastack/sofa-rpc-node/compare/v2.8.0...v2.9.0) (2023-05-22)

### Features

* add logger for decoder/encoder options ([#111](https://github.com/sofastack/sofa-rpc-node/issues/111)) ([2115ffb](2115ffb0e5))
2023-05-22 03:49:14 +00:00
killa
2115ffb0e5
feat: add logger for decoder/encoder options (#111) 2023-05-22 11:48:19 +08:00
semantic-release-bot
91ba177b26 Release 2.8.0
[skip ci]

## [2.8.0](https://github.com/sofastack/sofa-rpc-node/compare/v2.7.0...v2.8.0) (2022-12-21)

### Features

* support localStorage mode on sdk-base ([#109](https://github.com/sofastack/sofa-rpc-node/issues/109)) ([be9a630](be9a630891))
2022-12-21 14:33:07 +00:00
fengmk2
be9a630891
feat: support localStorage mode on sdk-base (#109)
https://github.com/node-modules/sdk-base/pull/21
2022-12-21 22:14:47 +08:00
14 changed files with 216 additions and 82 deletions

22
.github/workflows/cloud_code_scan.yml vendored Normal file
View File

@ -0,0 +1,22 @@
name: Alipay Cloud Devops Codescan
on:
pull_request_target:
jobs:
stc: # Code security scanning
runs-on: ubuntu-latest
steps:
- name: codeScan
uses: layotto/alipay-cloud-devops-codescan@main
with:
parent_uid: ${{ secrets.ALI_PID }}
private_key: ${{ secrets.ALI_PK }}
scan_type: stc
sca: # Open source compliance scanning
runs-on: ubuntu-latest
steps:
- name: codeScan
uses: layotto/alipay-cloud-devops-codescan@main
with:
parent_uid: ${{ secrets.ALI_PID }}
private_key: ${{ secrets.ALI_PK }}
scan_type: sca

View File

@ -1,47 +1,23 @@
name: Node.js CI
name: CI
on:
push:
branches:
- main
- master
branches: [ master ]
pull_request:
branches:
- main
- master
schedule:
- cron: '0 2 * * *'
branches: [ master ]
workflow_dispatch: {}
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
node-version: [14, 16, 18]
os: [ubuntu-latest]
steps:
- name: Checkout Git Source
uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Install Dependencies
run: |
Job:
name: Node.js
uses: artusjs/github-actions/.github/workflows/node-test.yml@v1
with:
os: 'ubuntu-latest'
version: '14, 16, 18, 20'
install: |
tar xf zookeeper-3.4.6.tar.gz
mv zookeeper-3.4.6/conf/zoo_sample.cfg zookeeper-3.4.6/conf/zoo.cfg
./zookeeper-3.4.6/bin/zkServer.sh start
npm i
- name: Continuous Integration
run: npm run ci
- name: Code Coverage
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
npm i --no-package-lock --no-fund

17
.github/workflows/release.yml vendored Normal file
View File

@ -0,0 +1,17 @@
name: Release
on:
push:
branches: [ master ]
workflow_dispatch: {}
jobs:
release:
name: Node.js
uses: artusjs/github-actions/.github/workflows/node-release.yml@v1
secrets:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
GIT_TOKEN: ${{ secrets.GIT_TOKEN }}
with:
checkTest: false

17
AUTHORS
View File

@ -1,17 +0,0 @@
# Ordered by date of first contribution.
# Auto-generated by 'contributors' on Mon, 07 Nov 2022 00:49:23 GMT.
# https://github.com/xingrz/node-contributors
zōng yǔ <gxcsoccer@126.com> (https://github.com/gxcsoccer)
zōng yǔ <gxcsoccer@users.noreply.github.com>
zl <1183163+smile21@users.noreply.github.com>
RabbitSion <rabbitsion@gmail.com> (https://github.com/RabbitSion)
killa <killa123@126.com>
mansonchor.github.com <mansonchor@126.com>
兔子人开源 <changeden520@gmail.com> (https://github.com/chans-open-source)
陈峰 <348018533@qq.com>
mansonchor.github.com <mansonchor1987@gmail.com> (https://github.com/mansonchor)
fengmk2 <fengmk2@gmail.com> (https://github.com/fengmk2)
羊鹿 <general_up@163.com>
hyj1991 <yeekwanvong@gmail.com> (https://github.com/hyj1991)
mytEcust <mytfromecust@gmail.com>

View File

@ -1,3 +1,28 @@
# Changelog
## [2.10.0](https://github.com/sofastack/sofa-rpc-node/compare/v2.9.0...v2.10.0) (2023-05-22)
### Features
* remove debug deps ([#112](https://github.com/sofastack/sofa-rpc-node/issues/112)) ([aada766](https://github.com/sofastack/sofa-rpc-node/commit/aada7662faddbc2f7eb0c5d200e4753d3ebbf0ba))
## [2.9.0](https://github.com/sofastack/sofa-rpc-node/compare/v2.8.0...v2.9.0) (2023-05-22)
### Features
* add logger for decoder/encoder options ([#111](https://github.com/sofastack/sofa-rpc-node/issues/111)) ([2115ffb](https://github.com/sofastack/sofa-rpc-node/commit/2115ffb0e55350a1f80d83e473006796d4e6cb9c))
## [2.8.0](https://github.com/sofastack/sofa-rpc-node/compare/v2.7.0...v2.8.0) (2022-12-21)
### Features
* support localStorage mode on sdk-base ([#109](https://github.com/sofastack/sofa-rpc-node/issues/109)) ([be9a630](https://github.com/sofastack/sofa-rpc-node/commit/be9a630891e8b4c00226a193d1bb9a2775acc4eb))
---
2.7.0 / 2022-12-05
==================
@ -309,4 +334,3 @@
**others**
,fatal: No names found, cannot describe anything.

View File

@ -332,3 +332,16 @@ invoke().catch(console.error);
## 五、开源协议
[MIT](LICENSE)
<!-- GITCONTRIBUTOR_START -->
## Contributors
|[<img src="https://avatars.githubusercontent.com/u/1207064?v=4" width="100px;"/><br/><sub><b>gxcsoccer</b></sub>](https://github.com/gxcsoccer)<br/>|[<img src="https://avatars.githubusercontent.com/u/156269?v=4" width="100px;"/><br/><sub><b>fengmk2</b></sub>](https://github.com/fengmk2)<br/>|[<img src="https://avatars.githubusercontent.com/u/6897780?v=4" width="100px;"/><br/><sub><b>killagu</b></sub>](https://github.com/killagu)<br/>|[<img src="https://avatars.githubusercontent.com/u/2160731?v=4" width="100px;"/><br/><sub><b>mansonchor</b></sub>](https://github.com/mansonchor)<br/>|[<img src="https://avatars.githubusercontent.com/u/32174276?v=4" width="100px;"/><br/><sub><b>semantic-release-bot</b></sub>](https://github.com/semantic-release-bot)<br/>|[<img src="https://avatars.githubusercontent.com/u/9605663?v=4" width="100px;"/><br/><sub><b>ChangedenCZD</b></sub>](https://github.com/ChangedenCZD)<br/>|
| :---: | :---: | :---: | :---: | :---: | :---: |
|[<img src="https://avatars.githubusercontent.com/u/18223471?v=4" width="100px;"/><br/><sub><b>KenyeeC</b></sub>](https://github.com/KenyeeC)<br/>|[<img src="https://avatars.githubusercontent.com/u/9674709?v=4" width="100px;"/><br/><sub><b>RabbitSion</b></sub>](https://github.com/RabbitSion)<br/>|[<img src="https://avatars.githubusercontent.com/u/19908330?v=4" width="100px;"/><br/><sub><b>hyj1991</b></sub>](https://github.com/hyj1991)<br/>|[<img src="https://avatars.githubusercontent.com/u/17831480?v=4" width="100px;"/><br/><sub><b>mytEcust</b></sub>](https://github.com/mytEcust)<br/>|[<img src="https://avatars.githubusercontent.com/u/1183163?v=4" width="100px;"/><br/><sub><b>smile21</b></sub>](https://github.com/smile21)<br/>|[<img src="https://avatars.githubusercontent.com/u/16103358?v=4" width="100px;"/><br/><sub><b>onlylovermb</b></sub>](https://github.com/onlylovermb)<br/>|
[<img src="https://avatars.githubusercontent.com/u/7371122?v=4" width="100px;"/><br/><sub><b>chenfengjw163</b></sub>](https://github.com/chenfengjw163)<br/>
This project follows the git-contributor [spec](https://github.com/xudafeng/git-contributor), auto updated at `Mon May 22 2023 14:22:46 GMT+0800`.
<!-- GITCONTRIBUTOR_END -->

View File

@ -1,11 +1,11 @@
'use strict';
const debug = require('debug')('rpc-client');
const Base = require('sdk-base');
const debug = require('util').debuglog('rpc-client');
const assert = require('assert');
const Base = require('sdk-base');
const protocol = require('sofa-bolt-node');
const Scheduler = require('./scheduler');
const RpcConsumer = require('./consumer');
const protocol = require('sofa-bolt-node');
const RpcConnection = require('./connection/rpc');
const ConnectionManager = require('./connection_mgr');

View File

@ -96,11 +96,13 @@ class RpcConnection extends Base {
sentReqs: this._sentReqs,
classCache: this.options.classCache || new Map(),
address: this.address,
logger: this.options.logger,
};
const decodeOpts = {
sentReqs: this._sentReqs,
classCache: this.options.classCache || new Map(),
address: this.address,
logger: this.options.logger,
};
// 针对 classMap 针对 hessian, proto 针对 protobuf

View File

@ -190,9 +190,9 @@ class RpcConsumer extends Base {
async invoke(method, args, options = {}) {
if (!this._isReady) {
try {
await this.readyOrTimeout(options.responseTimeout || this.options.responseTimeout)
await this.readyOrTimeout(options.responseTimeout || this.options.responseTimeout);
} catch (err) {
throw new Error('[RpcConsumer] Consumer ready error: ' + err.message)
throw new Error('[RpcConsumer] Consumer ready error: ' + err.message);
}
}
const req = this.createRequest(method, args, options);

View File

@ -28,10 +28,12 @@ class RpcConnection extends Base {
const encodeOpts = {
sentReqs: this._sentReqs,
classCache: this.options.classCache || new Map(),
logger: this.options.logger,
};
const decodeOpts = {
sentReqs: this._sentReqs,
classCache: this.options.classCache || new Map(),
logger: this.options.logger,
};
// 针对 classMap 针对 hessian, proto 针对 protobuf
// 因为可能需要同时支持,所以分开设置(一般通过全局设置,所以这里要判断是否有值)

View File

@ -271,15 +271,25 @@ class RpcServer extends Base {
}
async _handleRequest(req, conn) {
const id = req.data.serverSignature;
const serviceId = req.data.serverSignature;
req.data.interfaceName = req.data.interfaceName || req.data.serverSignature.split(':')[0];
const service = this._services.get(id);
const res = new this.responseClass(req, conn);
const ctx = this.createContext(req, res);
if (this.localStorage && ctx) {
await this.localStorage.run(ctx, async () => {
await this._invokeService(serviceId, req, res, ctx);
});
} else {
await this._invokeService(serviceId, req, res, ctx);
}
}
async _invokeService(serviceId, req, res, ctx) {
const service = this._services.get(serviceId);
this.emit('request', { req, ctx });
try {
if (!service) {
throw new Error('not found service: ' + id);
throw new Error('not found service: ' + serviceId);
}
await service.invoke(ctx, req, res);
} catch (err) {

View File

@ -1,6 +1,6 @@
{
"name": "sofa-rpc-node",
"version": "2.7.0",
"version": "2.10.0",
"description": "SOFARPC Nodejs Implementation",
"main": "lib/index.js",
"files": [
@ -11,9 +11,8 @@
"cov": "egg-bin cov",
"test": "npm run lint && npm run test-local",
"test-local": "egg-bin test",
"pkgfiles": "egg-bin pkgfiles --check",
"ci": "npm run start:zk && npm run pkgfiles && npm run lint && npm run cov",
"contributors": "contributors -f plain -o AUTHORS",
"ci": "npm run start:zk && npm run lint && npm run cov",
"contributors": "git-contributor",
"start:zk": "node test/scripts/start.js",
"stop:zk": "node test/scripts/stop.js"
},
@ -38,14 +37,13 @@
"await-first": "^1.0.0",
"byte": "^2.0.0",
"cluster-client": "^3.0.1",
"debug": "^4.1.1",
"easy-table": "^1.1.1",
"graceful": "^1.1.0",
"is-type-of": "^1.2.1",
"koa-compose": "^4.1.0",
"mz-modules": "^2.1.0",
"pump": "^3.0.0",
"sdk-base": "^4.0.0",
"sdk-base": "^4.2.1",
"sofa-bolt-node": "^2.0.1",
"urlencode": "^1.1.0",
"utility": "^1.16.3",
@ -54,12 +52,12 @@
"devDependencies": {
"antpb": "^1.0.0",
"coffee": "^5.4.0",
"contributors": "^0.5.1",
"detect-port": "^1.5.1",
"dubbo-remoting": "^2.1.4",
"egg-bin": "^5.3.1",
"eslint": "^8.27.0",
"eslint-config-egg": "^12.1.0",
"git-contributor": "^2.1.5",
"mm": "^3.2.0",
"node-zookeeper-client": "^1.1.0",
"pedding": "^1.1.0",

View File

@ -516,20 +516,20 @@ describe('test/client/consumer.test.js', () => {
},
registry,
logger,
responseTimeout: 10
responseTimeout: 10,
});
await consumer.ready()
consumer._isReady = false
consumer.ready(false)
await consumer.ready();
consumer._isReady = false;
consumer.ready(false);
try {
await consumer.invoke('test', [{}])
await consumer.invoke('test', [{}]);
assert(false);
} catch (err) {
assert(err && err.message.includes('[RpcConsumer] Consumer ready error: Promise timed out after 10 milliseconds'));
}
})
});
describe('should filter invalid address', () => {
class CustomRegistry extends Base {

View File

@ -1,14 +1,13 @@
'use strict';
const mm = require('mm');
const net = require('net');
const { AsyncLocalStorage } = require('async_hooks');
const assert = require('assert');
const mm = require('mm');
const sleep = require('mz-modules/sleep');
const request = require('../../').test;
const dubboProtocol = require('dubbo-remoting');
const protocol = require('sofa-bolt-node/lib/protocol');
const request = require('../../').test;
const RpcClient = require('../../').client.RpcClient;
const RpcServer = require('../../').server.RpcServer;
const protocol = require('sofa-bolt-node/lib/protocol');
const ZookeeperRegistry = require('../../').registry.ZookeeperRegistry;
const logger = console;
@ -394,4 +393,92 @@ describe('test/server/server.test.js', () => {
});
});
describe('bolt with localStorage', () => {
const asyncLocalStorage = new AsyncLocalStorage();
before(async () => {
class NewRpcServer extends RpcServer {
createContext(req) {
return { req };
}
}
server = new NewRpcServer({
appName: 'test',
registry,
version,
logger,
port: 0,
localStorage: asyncLocalStorage,
});
server.addService({
interfaceName: 'com.alipay.x.facade.HelloRpcFacade',
version,
apiMeta: {
methods: [{
name: 'plus',
parameterTypes: [
'java.lang.Integer',
'java.lang.Integer',
],
returnType: 'java.lang.Integer',
}],
},
}, {
// a + b
async plus(a, b) {
return a + b;
},
});
server.addService({
interfaceName: 'com.alipay.test.TestService',
}, {
async error() {
const ctx = asyncLocalStorage.getStore();
console.log('ctx', !!ctx, typeof ctx);
throw new Error('mock error with ctx ' + !!ctx);
},
});
server.addService({
interfaceName: 'com.alipay.test.HelloService',
version,
uniqueId: 'hello',
}, {
async hello() {
await sleep(2000);
return 'hello';
},
});
await server.start();
await server.publish();
});
after(async () => {
await server.close();
server = null;
});
it('should invoke ok', () => {
return request(server)
.service('com.alipay.x.facade.HelloRpcFacade')
.invoke('plus')
.send([ 1, 2 ])
.expect(3);
});
it('should resultCode=01 if biz error', async () => {
let meta;
server.once('response', data => {
meta = data.res.meta;
});
await request(server)
.service('com.alipay.test.TestService')
.invoke('error')
.timeout(1000)
.send([])
.error(/mock error with ctx true/);
assert(meta && meta.resultCode === '01');
});
});
});