From 975d81edc22a44f7836a314822a0b2c264de032d Mon Sep 17 00:00:00 2001 From: dfounderliu Date: Tue, 26 Nov 2019 19:00:58 +0800 Subject: [PATCH 01/24] fix function status --- deploy/lib/deployFunction.js | 14 +++++++++++--- deploy/tencentDeploy.js | 16 ++++++++++++++++ deploy/tencentDeployFunction.js | 16 ++++++++++++++++ package.json | 2 +- 4 files changed, 44 insertions(+), 4 deletions(-) diff --git a/deploy/lib/deployFunction.js b/deploy/lib/deployFunction.js index 836ac49..2ab1a9d 100644 --- a/deploy/lib/deployFunction.js +++ b/deploy/lib/deployFunction.js @@ -22,11 +22,19 @@ class DeployFunction extends AbstractHandler { this.serverless.cli.log('Updating code... ') await this.updateFunctionCode(ns, funcObject) // when update code Status is Active, continue - let status = 'updating' - while (status != 'Active') { + let status = 'Updating' + let times = 90 + while (status == 'Updating') { const tempFunc = await this.getFunction(ns, funcObject.FuncName) status = tempFunc.Status - await utils.sleep(500) + await utils.sleep(1000) + times = times - 1 + if (times <= 0) { + throw `Function ${funcObject.FuncName} update failed` + } + } + if (status != 'Active') { + throw `Function ${funcObject.FuncName} update failed` } this.serverless.cli.log('Updating configure... ') await this.updateConfiguration(ns, func, funcObject) diff --git a/deploy/tencentDeploy.js b/deploy/tencentDeploy.js index c8c5956..b4919b5 100644 --- a/deploy/tencentDeploy.js +++ b/deploy/tencentDeploy.js @@ -74,6 +74,22 @@ class TencentDeploy { this.serverless.cli.log(`Setting tags for function ${funcObject.FuncName}`) await func.createTags('default', funcObject.FuncName, funcObject.Properties.Tags) + // Function status + let status = 'Updating' + let times = 90 + while (status == 'Updating' || status == 'Creating') { + const tempFunc = await this.getFunction('default', funcObject.FuncName) + status = tempFunc.Status + await utils.sleep(1000) + times = times - 1 + if (times <= 0) { + throw `Function ${funcObject.FuncName} create/update failed` + } + } + if (status != 'Active') { + throw `Function ${funcObject.FuncName} create/update failed` + } + this.serverless.cli.log(`Creating trigger for function ${funcObject.FuncName}`) await trigger.create( 'default', diff --git a/deploy/tencentDeployFunction.js b/deploy/tencentDeployFunction.js index e014120..ee08b4e 100644 --- a/deploy/tencentDeployFunction.js +++ b/deploy/tencentDeployFunction.js @@ -93,6 +93,22 @@ class TencentDeployFunction { this.serverless.cli.log(`Setting tags for function ${funcObject.FuncName}`) await func.createTags('default', funcObject.FuncName, funcObject.Properties.Tags) + // Function status + let status = 'Updating' + let times = 90 + while (status == 'Updating' || status == 'Creating') { + const tempFunc = await this.getFunction('default', funcObject.FuncName) + status = tempFunc.Status + await utils.sleep(1000) + times = times - 1 + if (times <= 0) { + throw `Function ${funcObject.FuncName} create/update failed` + } + } + if (status != 'Active') { + throw `Function ${funcObject.FuncName} create/update failed` + } + this.serverless.cli.log(`Creating trigger for function ${funcObject.FuncName}`) result = await trigger.create( 'default', diff --git a/package.json b/package.json index ea24fc6..0b80f01 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "serverless-tencent-scf", - "version": "0.1.16", + "version": "0.1.17", "description": "Provider plugin for the Serverless Framework v1.x which adds support for Tencent Cloud Functions.", "main": "index.js", "author": "Tencent Cloud, Inc.", From a4a886bed29a85ef713731151cf993d2855e624b Mon Sep 17 00:00:00 2001 From: dfounderliu Date: Tue, 26 Nov 2019 19:07:45 +0800 Subject: [PATCH 02/24] fix function status --- Changelog.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 Changelog.md diff --git a/Changelog.md b/Changelog.md new file mode 100644 index 0000000..e44ee92 --- /dev/null +++ b/Changelog.md @@ -0,0 +1,4 @@ +# 变更历史 + +## 2019-11-26 +* 更新函数状态,提高部署成功率 From 8f571713b2510ce734654cd0fdf3f0c563097710 Mon Sep 17 00:00:00 2001 From: dfounderliu Date: Tue, 26 Nov 2019 19:09:33 +0800 Subject: [PATCH 03/24] fix function status --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0b80f01..9cfb71d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "serverless-tencent-scf", - "version": "0.1.17", + "version": "0.1.18", "description": "Provider plugin for the Serverless Framework v1.x which adds support for Tencent Cloud Functions.", "main": "index.js", "author": "Tencent Cloud, Inc.", From 25488be35c2afb4b2034d7ecc657a10cc37cb187 Mon Sep 17 00:00:00 2001 From: dfounderliu Date: Tue, 26 Nov 2019 19:32:35 +0800 Subject: [PATCH 04/24] fix function status --- deploy/tencentDeploy.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/deploy/tencentDeploy.js b/deploy/tencentDeploy.js index b4919b5..3471702 100644 --- a/deploy/tencentDeploy.js +++ b/deploy/tencentDeploy.js @@ -78,7 +78,7 @@ class TencentDeploy { let status = 'Updating' let times = 90 while (status == 'Updating' || status == 'Creating') { - const tempFunc = await this.getFunction('default', funcObject.FuncName) + const tempFunc = await func.getFunction('default', funcObject.FuncName) status = tempFunc.Status await utils.sleep(1000) times = times - 1 diff --git a/package.json b/package.json index 9cfb71d..df8aac9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "serverless-tencent-scf", - "version": "0.1.18", + "version": "0.1.19", "description": "Provider plugin for the Serverless Framework v1.x which adds support for Tencent Cloud Functions.", "main": "index.js", "author": "Tencent Cloud, Inc.", From e07be42e0fd335b5d160fca2dabd6ec48794287b Mon Sep 17 00:00:00 2001 From: dfounderliu Date: Tue, 26 Nov 2019 19:33:50 +0800 Subject: [PATCH 05/24] fix function status --- deploy/tencentDeployFunction.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deploy/tencentDeployFunction.js b/deploy/tencentDeployFunction.js index ee08b4e..b2c7aca 100644 --- a/deploy/tencentDeployFunction.js +++ b/deploy/tencentDeployFunction.js @@ -97,7 +97,7 @@ class TencentDeployFunction { let status = 'Updating' let times = 90 while (status == 'Updating' || status == 'Creating') { - const tempFunc = await this.getFunction('default', funcObject.FuncName) + const tempFunc = await func.getFunction('default', funcObject.FuncName) status = tempFunc.Status await utils.sleep(1000) times = times - 1 From 9bfe84da20b957a71badccaf49d50276eef5e3d7 Mon Sep 17 00:00:00 2001 From: dfounderliu Date: Wed, 27 Nov 2019 19:31:36 +0800 Subject: [PATCH 06/24] add apigw key --- deploy/lib/deployTrigger.js | 7 +++++-- docs/en/yaml.md | 3 +++ docs/zh/yaml.md | 4 ++++ package.json | 2 +- provider/tencentProvider.js | 5 ++++- 5 files changed, 17 insertions(+), 4 deletions(-) diff --git a/deploy/lib/deployTrigger.js b/deploy/lib/deployTrigger.js index f7051d9..9af731f 100644 --- a/deploy/lib/deployTrigger.js +++ b/deploy/lib/deployTrigger.js @@ -96,9 +96,12 @@ class DeployTrigger extends AbstractHandler { api: { authRequired: 'FALSE', requestConfig: { - method: trigger.Properties.HttpMethod || 'GET' + method: trigger.Properties.HttpMethod || 'GET', + path: trigger.Properties.Path || '/' + funcObject.FuncName }, - isIntegratedResponse: trigger.Properties.IntegratedResponse ? 'TRUE' : 'FALSE' + isIntegratedResponse: trigger.Properties.IntegratedResponse ? 'TRUE' : 'FALSE', + enableCORS: trigger.Properties.EnableCORS ? 'TRUE' : 'FALSE', + serviceTimeout: trigger.Properties.ServiceTimeout || 10 }, service: { serviceName: 'SCF_API_SERVICE' diff --git a/docs/en/yaml.md b/docs/en/yaml.md index b484556..d2b19e3 100644 --- a/docs/en/yaml.md +++ b/docs/en/yaml.md @@ -85,6 +85,9 @@ functions: # serviceId: # httpMethod: ANY # integratedResponse: true +# path: /abc/cde +# enableCORS: true +# serviceTimeout: 10 # - cmq: # name: cmq_trigger # parameters: diff --git a/docs/zh/yaml.md b/docs/zh/yaml.md index 900403f..f07b422 100644 --- a/docs/zh/yaml.md +++ b/docs/zh/yaml.md @@ -83,6 +83,10 @@ functions: # stageName: release # serviceId: # httpMethod: ANY +# integratedResponse: true +# path: /abc/cde +# enableCORS: true +# serviceTimeout: 10 # - cmq: # name: cmq_trigger # parameters: diff --git a/package.json b/package.json index df8aac9..7dc7a1b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "serverless-tencent-scf", - "version": "0.1.19", + "version": "0.1.20", "description": "Provider plugin for the Serverless Framework v1.x which adds support for Tencent Cloud Functions.", "main": "index.js", "author": "Tencent Cloud, Inc.", diff --git a/provider/tencentProvider.js b/provider/tencentProvider.js index ad5d844..9feda0f 100644 --- a/provider/tencentProvider.js +++ b/provider/tencentProvider.js @@ -340,7 +340,10 @@ class TencentProvider { HttpMethod: event.parameters.httpMethod, ServiceId: serviceId, IntegratedResponse: event.parameters.integratedResponse, - Enable: event.parameters.enable + Enable: event.parameters.enable, + Path: event.parameters.path, + ServiceTimeout: event.parameters.serviceTimeout, + EnableCORS: event.parameters.enableCORS } } return trigger From 5c5ae0be3042c9bb04be87c3db2322eb8ce5fe7d Mon Sep 17 00:00:00 2001 From: dfounderliu Date: Mon, 2 Dec 2019 09:56:04 +0800 Subject: [PATCH 07/24] add apigw key --- logs/tencentLogs.js | 1 + package.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/logs/tencentLogs.js b/logs/tencentLogs.js index 98dae68..5cf42d8 100644 --- a/logs/tencentLogs.js +++ b/logs/tencentLogs.js @@ -103,6 +103,7 @@ class TencentLogs { } } } else { + const handler = new LogsFunction(this.options, this.serverless) const result = await handler.logs( functionName, this.options.startTime || this.getTimeFunction(timeFormat, 1 * 60 * 60 * 1000), diff --git a/package.json b/package.json index 7dc7a1b..861d58a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "serverless-tencent-scf", - "version": "0.1.20", + "version": "0.1.21", "description": "Provider plugin for the Serverless Framework v1.x which adds support for Tencent Cloud Functions.", "main": "index.js", "author": "Tencent Cloud, Inc.", From 93f4855aa68388860cf338eb07f8a8d5405dd74b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?tinafang=28=E6=96=B9=E5=9D=A4=E4=B8=81=29?= Date: Fri, 8 Nov 2019 19:48:03 +0800 Subject: [PATCH 08/24] =?UTF-8?q?Update=20=E6=89=93=E5=8C=85=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "docs/zh/\346\211\223\345\214\205\346\234\215\345\212\241.md" | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git "a/docs/zh/\346\211\223\345\214\205\346\234\215\345\212\241.md" "b/docs/zh/\346\211\223\345\214\205\346\234\215\345\212\241.md" index 58661e5..a066fcf 100644 --- "a/docs/zh/\346\211\223\345\214\205\346\234\215\345\212\241.md" +++ "b/docs/zh/\346\211\223\345\214\205\346\234\215\345\212\241.md" @@ -11,7 +11,7 @@ serverless package ## 参数说明 - `--stage` 或`-s` 目标部署环境,您可以自定义指定诸如`dev`,`pro` 等环境参数,默认为`dev`。部署后,环境参数将追加至云函数名之后,且会作为云函数的标签。 -- `--region`或`-r` 目标部署区域,默认为 `ap-guangzhou` +- `--region`或`-r` 目标部署区域,默认为广州 `ap-guangzhou` - `--package`或`-p` 自定义部署包目录 From c1afcc338e7e23a13885ab0622d79a99367aab4d Mon Sep 17 00:00:00 2001 From: dfounderliu Date: Mon, 30 Dec 2019 13:09:44 +0800 Subject: [PATCH 09/24] update version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 861d58a..1556400 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "serverless-tencent-scf", - "version": "0.1.21", + "version": "0.1.22", "description": "Provider plugin for the Serverless Framework v1.x which adds support for Tencent Cloud Functions.", "main": "index.js", "author": "Tencent Cloud, Inc.", From 2b2d65ce138a747c4fa510ede436d4867d2b359a Mon Sep 17 00:00:00 2001 From: dfounderliu Date: Thu, 9 Jan 2020 22:13:50 +0800 Subject: [PATCH 10/24] add auth --- deploy/tencentDeploy.js | 6 ++- deploy/tencentDeployFunction.js | 6 ++- deploy/tencentDeployList.js | 6 ++- deploy/tencentDeployListFunctions.js | 6 ++- info/tencentInfo.js | 6 ++- invoke/tencentInvoke.js | 6 ++- logs/tencentLogs.js | 6 ++- metrics/tencentMetrics.js | 6 ++- package.json | 3 +- provider/tencentProvider.js | 65 +++++++++++++++++++++++++--- remove/tencentRemove.js | 6 ++- rollback/tencentRollback.js | 6 ++- 12 files changed, 102 insertions(+), 26 deletions(-) diff --git a/deploy/tencentDeploy.js b/deploy/tencentDeploy.js index 3471702..2aa2772 100644 --- a/deploy/tencentDeploy.js +++ b/deploy/tencentDeploy.js @@ -26,17 +26,19 @@ class TencentDeploy { } async deploy() { + const provider = new tencentProvider(this.serverless, this.options) if (!this.options.credentials || !this.options.credentials.tencent_secret_id) { - const provider = new tencentProvider(this.serverless, this.options) const tencentTemp = await provider.getTempKey() this.options.credentials = { tencent_secret_id: tencentTemp.tencent_secret_id, tencent_secret_key: tencentTemp.tencent_secret_key, - tencent_appid: tencentTemp.tencent_appid + tencent_appid: tencentTemp.tencent_appid, + tencent_owneruin: tencentTemp.tencent_owneruin } this.options.token = tencentTemp.token this.options.timestamp = tencentTemp.timestamp } + await provider.getUserAuth(this.options.credentials.tencent_owneruin) const services = this.provider.getServiceResource() const func = new DeployFunction(this.options, this.serverless) diff --git a/deploy/tencentDeployFunction.js b/deploy/tencentDeployFunction.js index b2c7aca..efe9de4 100644 --- a/deploy/tencentDeployFunction.js +++ b/deploy/tencentDeployFunction.js @@ -31,17 +31,19 @@ class TencentDeployFunction { } async deploy() { + const provider = new tencentProvider(this.serverless, this.options) if (!this.options.credentials || !this.options.credentials.tencent_secret_id) { - const provider = new tencentProvider(this.serverless, this.options) const tencentTemp = await provider.getTempKey() this.options.credentials = { tencent_secret_id: tencentTemp.tencent_secret_id, tencent_secret_key: tencentTemp.tencent_secret_key, - tencent_appid: tencentTemp.tencent_appid + tencent_appid: tencentTemp.tencent_appid, + tencent_owneruin: tencentTemp.tencent_owneruin } this.options.token = tencentTemp.token this.options.timestamp = tencentTemp.timestamp } + await provider.getUserAuth(this.options.credentials.tencent_owneruin) const services = this.provider.getServiceResource() diff --git a/deploy/tencentDeployList.js b/deploy/tencentDeployList.js index ab3956f..6e3b8fa 100644 --- a/deploy/tencentDeployList.js +++ b/deploy/tencentDeployList.js @@ -23,17 +23,19 @@ class TencentDeployList { } async serviceList() { + const provider = new tencentProvider(this.serverless, this.options) if (!this.options.credentials || !this.options.credentials.tencent_secret_id) { - const provider = new tencentProvider(this.serverless, this.options) const tencentTemp = await provider.getTempKey() this.options.credentials = { tencent_secret_id: tencentTemp.tencent_secret_id, tencent_secret_key: tencentTemp.tencent_secret_key, - tencent_appid: tencentTemp.tencent_appid + tencent_appid: tencentTemp.tencent_appid, + tencent_owneruin: tencentTemp.tencent_owneruin } this.options.token = tencentTemp.token this.options.timestamp = tencentTemp.timestamp } + await provider.getUserAuth(this.options.credentials.tencent_owneruin) const Handler = new RollbackService(this.options, this.serverless) const fileKeyPrefix = this.serverless.service.service + '-' + this.options.stage const cosBucket = this.provider.getDeployCosBucket() diff --git a/deploy/tencentDeployListFunctions.js b/deploy/tencentDeployListFunctions.js index 99059f8..ee1b972 100644 --- a/deploy/tencentDeployListFunctions.js +++ b/deploy/tencentDeployListFunctions.js @@ -25,17 +25,19 @@ class TencentDeployListFunction { } async functionList() { + const provider = new tencentProvider(this.serverless, this.options) if (!this.options.credentials || !this.options.credentials.tencent_secret_id) { - const provider = new tencentProvider(this.serverless, this.options) const tencentTemp = await provider.getTempKey() this.options.credentials = { tencent_secret_id: tencentTemp.tencent_secret_id, tencent_secret_key: tencentTemp.tencent_secret_key, - tencent_appid: tencentTemp.tencent_appid + tencent_appid: tencentTemp.tencent_appid, + tencent_owneruin: tencentTemp.tencent_owneruin } this.options.token = tencentTemp.token this.options.timestamp = tencentTemp.timestamp } + await provider.getUserAuth(this.options.credentials.tencent_owneruin) try { const infoHandler = new InfoFunction(this.options, this.serverless) const deployHandler = new ListFunctions(this.options, this.serverless) diff --git a/info/tencentInfo.js b/info/tencentInfo.js index c280e9a..27aae16 100644 --- a/info/tencentInfo.js +++ b/info/tencentInfo.js @@ -24,17 +24,19 @@ class TencentInfo { } async info() { + const provider = new tencentProvider(this.serverless, this.options) if (!this.options.credentials || !this.options.credentials.tencent_secret_id) { - const provider = new tencentProvider(this.serverless, this.options) const tencentTemp = await provider.getTempKey() this.options.credentials = { tencent_secret_id: tencentTemp.tencent_secret_id, tencent_secret_key: tencentTemp.tencent_secret_key, - tencent_appid: tencentTemp.tencent_appid + tencent_appid: tencentTemp.tencent_appid, + tencent_owneruin: tencentTemp.tencent_owneruin } this.options.token = tencentTemp.token this.options.timestamp = tencentTemp.timestamp } + await provider.getUserAuth(this.options.credentials.tencent_owneruin) try { const region = this.options.region const handler = new InfoFunction(this.options, this.serverless) diff --git a/invoke/tencentInvoke.js b/invoke/tencentInvoke.js index 34984f2..c890338 100644 --- a/invoke/tencentInvoke.js +++ b/invoke/tencentInvoke.js @@ -23,17 +23,19 @@ class TencentInvoke { } async invoke() { + const provider = new tencentProvider(this.serverless, this.options) if (!this.options.credentials || !this.options.credentials.tencent_secret_id) { - const provider = new tencentProvider(this.serverless, this.options) const tencentTemp = await provider.getTempKey() this.options.credentials = { tencent_secret_id: tencentTemp.tencent_secret_id, tencent_secret_key: tencentTemp.tencent_secret_key, - tencent_appid: tencentTemp.tencent_appid + tencent_appid: tencentTemp.tencent_appid, + tencent_owneruin: tencentTemp.tencent_owneruin } this.options.token = tencentTemp.token this.options.timestamp = tencentTemp.timestamp } + await provider.getUserAuth(this.options.credentials.tencent_owneruin) try { const options = { region: this.options.region diff --git a/logs/tencentLogs.js b/logs/tencentLogs.js index 5cf42d8..9a050ac 100644 --- a/logs/tencentLogs.js +++ b/logs/tencentLogs.js @@ -49,17 +49,19 @@ class TencentLogs { } async logs() { + const provider = new tencentProvider(this.serverless, this.options) if (!this.options.credentials || !this.options.credentials.tencent_secret_id) { - const provider = new tencentProvider(this.serverless, this.options) const tencentTemp = await provider.getTempKey() this.options.credentials = { tencent_secret_id: tencentTemp.tencent_secret_id, tencent_secret_key: tencentTemp.tencent_secret_key, - tencent_appid: tencentTemp.tencent_appid + tencent_appid: tencentTemp.tencent_appid, + tencent_owneruin: tencentTemp.tencent_owneruin } this.options.token = tencentTemp.token this.options.timestamp = tencentTemp.timestamp } + await provider.getUserAuth(this.options.credentials.tencent_owneruin) try { const timeFormat = 'yyyy-MM-dd hh:mm:ss' this.serverless.cli.log(`Get function logs...`) diff --git a/metrics/tencentMetrics.js b/metrics/tencentMetrics.js index 12c7252..b3eee65 100644 --- a/metrics/tencentMetrics.js +++ b/metrics/tencentMetrics.js @@ -57,17 +57,19 @@ class TencentInfo { } async metrics() { + const provider = new tencentProvider(this.serverless, this.options) if (!this.options.credentials || !this.options.credentials.tencent_secret_id) { - const provider = new tencentProvider(this.serverless, this.options) const tencentTemp = await provider.getTempKey() this.options.credentials = { tencent_secret_id: tencentTemp.tencent_secret_id, tencent_secret_key: tencentTemp.tencent_secret_key, - tencent_appid: tencentTemp.tencent_appid + tencent_appid: tencentTemp.tencent_appid, + tencent_owneruin: tencentTemp.tencent_owneruin } this.options.token = tencentTemp.token this.options.timestamp = tencentTemp.timestamp } + await provider.getUserAuth(this.options.credentials.tencent_owneruin) try { const Handler = new MetricsFunction(this.options, this.serverless) const functionList = await Handler.functionList( diff --git a/package.json b/package.json index 1556400..cc6387d 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,8 @@ "request": "^2.88.0", "tencentcloud-sdk-nodejs": "^3.0.87", "universal-analytics": "^0.4.20", - "tencent-login": "^0.1.6" + "tencent-login": "^0.1.6", + "serverless-tencent-auth-tool": "^1.0.0" }, "devDependencies": { "coveralls": "^3.0.5", diff --git a/provider/tencentProvider.js b/provider/tencentProvider.js index d860766..8c9861f 100644 --- a/provider/tencentProvider.js +++ b/provider/tencentProvider.js @@ -4,8 +4,10 @@ const os = require('os') const ini = require('ini') const _ = require('lodash') const util = require('util') +const QRCode = require('qrcode') const TencentLogin = require('tencent-login') const tencentcloud = require('tencentcloud-sdk-nodejs') +const { GetUserAuthInfo } = require('serverless-tencent-tools').Account const ClientProfile = require('tencentcloud-sdk-nodejs/tencentcloud/common/profile/client_profile.js') const HttpProfile = require('tencentcloud-sdk-nodejs/tencentcloud/common/profile/http_profile.js') const AbstractModel = require('tencentcloud-sdk-nodejs/tencentcloud/common/abstract_model') @@ -17,7 +19,6 @@ const constants = { class GetUserAppIdResponse extends AbstractModel { constructor() { super() - this.RequestId = null } @@ -26,6 +27,7 @@ class GetUserAppIdResponse extends AbstractModel { return } this.AppId = 'RequestId' in params ? params.AppId : null + this.OwnerUin = 'RequestId' in params ? params.OwnerUin : null this.RequestId = 'RequestId' in params ? params.RequestId : null } } @@ -54,6 +56,36 @@ class TencentProvider { return constants.providerName } + async getUserAuth(uin) { + try { + const getUserAuthInfo = new GetUserAuthInfo() + const result = await getUserAuthInfo.isAuth(uin) + if (result['Error'] == true) { + console.log('Failed to get real name authentication result.') + process.exit(-1) + } else { + if (result['Message']['Authentication'] == 1) { + return true + } + const verifyUrl = 'https://cloud.tencent.com/verify/identity' + console.log( + "You don't have real name authentication yet. You can open the url or scan QR code for real name authentication." + ) + console.log('Real name authentication url: ') + console.log(verifyUrl) + console.log('Real name authentication QR code: ') + QRCode.toString(verifyUrl, { type: 'terminal' }, function(err, url) { + console.log(url) + }) + console.log('Please re operate after real name authentication.') + process.exit(-1) + } + } catch (e) { + console.log(e) + process.exit(-1) + } + } + getAppid(credentials) { const secret_id = credentials.SecretId const secret_key = credentials.SecretKey @@ -137,6 +169,14 @@ class TencentProvider { uuid: tencent_credentials.uuid, timestamp: tencent_credentials.timestamp } + // From cam to getting appid + const userInfo = await this.getAppid({ + SecretId: tencent.tencent_secret_id, + SecretKey: tencent.tencent_secret_key, + token: tencent.token + }) + tencent.tencent_owneruin = userInfo.OwnerUin + tencent.tencent_appid = userInfo.AppId await fs.writeFileSync('./.env_temp', JSON.stringify(tencent)) return tencent } catch (e) { @@ -152,10 +192,16 @@ class TencentProvider { try { const tencent = {} const tencent_credentials_read = JSON.parse(data) - if ( - Date.now() / 1000 - tencent_credentials_read.timestamp <= 6000 && - tencent_credentials_read.tencent_appid - ) { + if (Date.now() / 1000 - tencent_credentials_read.timestamp <= 6000) { + const userInfo = await this.getAppid({ + SecretId: tencent_credentials_read.tencent_secret_id, + SecretKey: tencent_credentials_read.tencent_secret_key, + token: tencent_credentials_read.token + }) + + // From cam to getting appid + tencent_credentials_read.tencent_owneruin = userInfo.OwnerUin + tencent_credentials_read.tencent_appid = userInfo.AppId return tencent_credentials_read } const login = new TencentLogin() @@ -175,6 +221,14 @@ class TencentProvider { tencent.uuid = tencent_credentials_read.uuid tencent.timestamp = Date.now() / 1000 await fs.writeFileSync('./.env_temp', JSON.stringify(tencent)) + // From cam to getting appid + const userInfo = await this.getAppid({ + SecretId: tencent.tencent_secret_id, + SecretKey: tencent.tencent_secret_key, + token: tencent.token + }) + tencent.tencent_owneruin = userInfo.OwnerUin + tencent.tencent_appid = userInfo.AppId return tencent } return await that.doLogin() @@ -242,6 +296,7 @@ class TencentProvider { SecretKey: this.options.credentials.tencent_secret_key }) this.options.credentials.tencent_appid = appid.AppId + this.options.credentials.tencent_owneruin = appid.OwnerUin } } catch (e) {} return diff --git a/remove/tencentRemove.js b/remove/tencentRemove.js index 0a9b268..4d41a8d 100644 --- a/remove/tencentRemove.js +++ b/remove/tencentRemove.js @@ -24,17 +24,19 @@ class TencentRemove { } async remove() { + const provider = new tencentProvider(this.serverless, this.options) if (!this.options.credentials || !this.options.credentials.tencent_secret_id) { - const provider = new tencentProvider(this.serverless, this.options) const tencentTemp = await provider.getTempKey() this.options.credentials = { tencent_secret_id: tencentTemp.tencent_secret_id, tencent_secret_key: tencentTemp.tencent_secret_key, - tencent_appid: tencentTemp.tencent_appid + tencent_appid: tencentTemp.tencent_appid, + tencent_owneruin: tencentTemp.tencent_owneruin } this.options.token = tencentTemp.token this.options.timestamp = tencentTemp.timestamp } + await provider.getUserAuth(this.options.credentials.tencent_owneruin) try { const handler = new RemoveFunction(this.options, this.serverless) const service = this.provider.getServiceResource() diff --git a/rollback/tencentRollback.js b/rollback/tencentRollback.js index a52d648..9c6c7e1 100644 --- a/rollback/tencentRollback.js +++ b/rollback/tencentRollback.js @@ -26,17 +26,19 @@ class TencentRollback { } async rollback() { + const provider = new tencentProvider(this.serverless, this.options) if (!this.options.credentials || !this.options.credentials.tencent_secret_id) { - const provider = new tencentProvider(this.serverless, this.options) const tencentTemp = await provider.getTempKey() this.options.credentials = { tencent_secret_id: tencentTemp.tencent_secret_id, tencent_secret_key: tencentTemp.tencent_secret_key, - tencent_appid: tencentTemp.tencent_appid + tencent_appid: tencentTemp.tencent_appid, + tencent_owneruin: tencentTemp.tencent_owneruin } this.options.token = tencentTemp.token this.options.timestamp = tencentTemp.timestamp } + await provider.getUserAuth(this.options.credentials.tencent_owneruin) const Handler = new RollbackService(this.options, this.serverless) const fileKeyPrefix = this.serverless.service.service + '-' + this.options.stage const cosBucket = this.provider.getDeployCosBucket() From 200e5bd17a49e64dc7b75e41c25fb91a51175b73 Mon Sep 17 00:00:00 2001 From: dfounderliu Date: Mon, 13 Jan 2020 16:11:57 +0800 Subject: [PATCH 11/24] fix auth --- package.json | 2 +- provider/tencentProvider.js | 14 ++++++-------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index cc6387d..d9a2207 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "serverless-tencent-scf", - "version": "0.1.22", + "version": "0.1.24", "description": "Provider plugin for the Serverless Framework v1.x which adds support for Tencent Cloud Functions.", "main": "index.js", "author": "Tencent Cloud, Inc.", diff --git a/provider/tencentProvider.js b/provider/tencentProvider.js index 8c9861f..166ac00 100644 --- a/provider/tencentProvider.js +++ b/provider/tencentProvider.js @@ -290,14 +290,12 @@ class TencentProvider { } }) // From cam to getting appid - if (!this.options.credentials.tencent_appid) { - const appid = await this.getAppid({ - SecretId: this.options.credentials.tencent_secret_id, - SecretKey: this.options.credentials.tencent_secret_key - }) - this.options.credentials.tencent_appid = appid.AppId - this.options.credentials.tencent_owneruin = appid.OwnerUin - } + const appid = await this.getAppid({ + SecretId: this.options.credentials.tencent_secret_id, + SecretKey: this.options.credentials.tencent_secret_key + }) + this.options.credentials.tencent_appid = appid.AppId + this.options.credentials.tencent_owneruin = appid.OwnerUin } catch (e) {} return } From 3924b0343dcbda351196eca7556eb8e79399298e Mon Sep 17 00:00:00 2001 From: dfounderliu Date: Mon, 13 Jan 2020 17:29:34 +0800 Subject: [PATCH 12/24] fix auth --- package.json | 2 +- provider/tencentProvider.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index d9a2207..4735387 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "serverless-tencent-scf", - "version": "0.1.24", + "version": "0.1.25", "description": "Provider plugin for the Serverless Framework v1.x which adds support for Tencent Cloud Functions.", "main": "index.js", "author": "Tencent Cloud, Inc.", diff --git a/provider/tencentProvider.js b/provider/tencentProvider.js index 166ac00..6e605e9 100644 --- a/provider/tencentProvider.js +++ b/provider/tencentProvider.js @@ -72,7 +72,7 @@ class TencentProvider { "You don't have real name authentication yet. You can open the url or scan QR code for real name authentication." ) console.log('Real name authentication url: ') - console.log(verifyUrl) + console.log('https://console.cloud.tencent.com/developer/auth') console.log('Real name authentication QR code: ') QRCode.toString(verifyUrl, { type: 'terminal' }, function(err, url) { console.log(url) From 5d9829307e7382a7d389c7f0d82407e8b6fa69a0 Mon Sep 17 00:00:00 2001 From: dfounderliu Date: Thu, 16 Jan 2020 10:33:22 +0800 Subject: [PATCH 13/24] fix creating --- deploy/lib/deployFunction.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/deploy/lib/deployFunction.js b/deploy/lib/deployFunction.js index 2ab1a9d..57ac525 100644 --- a/deploy/lib/deployFunction.js +++ b/deploy/lib/deployFunction.js @@ -24,7 +24,7 @@ class DeployFunction extends AbstractHandler { // when update code Status is Active, continue let status = 'Updating' let times = 90 - while (status == 'Updating') { + while (status == 'Updating' || status == 'Creating') { const tempFunc = await this.getFunction(ns, funcObject.FuncName) status = tempFunc.Status await utils.sleep(1000) diff --git a/package.json b/package.json index 4735387..c2a24f5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "serverless-tencent-scf", - "version": "0.1.25", + "version": "0.1.26", "description": "Provider plugin for the Serverless Framework v1.x which adds support for Tencent Cloud Functions.", "main": "index.js", "author": "Tencent Cloud, Inc.", From 5520993ca1ebda9a5d78eece199a3d42f78ccb68 Mon Sep 17 00:00:00 2001 From: dfounderliu Date: Tue, 28 Jan 2020 09:50:28 +0800 Subject: [PATCH 14/24] fix creating --- deploy/tencentDeploy.js | 6 +++++- deploy/tencentDeployFunction.js | 6 +++++- deploy/tencentDeployList.js | 6 +++++- deploy/tencentDeployListFunctions.js | 6 +++++- info/tencentInfo.js | 6 +++++- invoke/tencentInvoke.js | 6 +++++- logs/tencentLogs.js | 6 +++++- metrics/tencentMetrics.js | 6 +++++- package.json | 2 +- remove/tencentRemove.js | 6 +++++- rollback/tencentRollback.js | 6 +++++- 11 files changed, 51 insertions(+), 11 deletions(-) diff --git a/deploy/tencentDeploy.js b/deploy/tencentDeploy.js index 2aa2772..f983f7a 100644 --- a/deploy/tencentDeploy.js +++ b/deploy/tencentDeploy.js @@ -27,7 +27,11 @@ class TencentDeploy { async deploy() { const provider = new tencentProvider(this.serverless, this.options) - if (!this.options.credentials || !this.options.credentials.tencent_secret_id) { + if ( + !this.options.credentials || + !this.options.credentials.tencent_secret_id || + !this.options.credentials.tencent_owneruin + ) { const tencentTemp = await provider.getTempKey() this.options.credentials = { tencent_secret_id: tencentTemp.tencent_secret_id, diff --git a/deploy/tencentDeployFunction.js b/deploy/tencentDeployFunction.js index efe9de4..66b452f 100644 --- a/deploy/tencentDeployFunction.js +++ b/deploy/tencentDeployFunction.js @@ -32,7 +32,11 @@ class TencentDeployFunction { async deploy() { const provider = new tencentProvider(this.serverless, this.options) - if (!this.options.credentials || !this.options.credentials.tencent_secret_id) { + if ( + !this.options.credentials || + !this.options.credentials.tencent_secret_id || + !this.options.credentials.tencent_owneruin + ) { const tencentTemp = await provider.getTempKey() this.options.credentials = { tencent_secret_id: tencentTemp.tencent_secret_id, diff --git a/deploy/tencentDeployList.js b/deploy/tencentDeployList.js index 6e3b8fa..18e728e 100644 --- a/deploy/tencentDeployList.js +++ b/deploy/tencentDeployList.js @@ -24,7 +24,11 @@ class TencentDeployList { async serviceList() { const provider = new tencentProvider(this.serverless, this.options) - if (!this.options.credentials || !this.options.credentials.tencent_secret_id) { + if ( + !this.options.credentials || + !this.options.credentials.tencent_secret_id || + !this.options.credentials.tencent_owneruin + ) { const tencentTemp = await provider.getTempKey() this.options.credentials = { tencent_secret_id: tencentTemp.tencent_secret_id, diff --git a/deploy/tencentDeployListFunctions.js b/deploy/tencentDeployListFunctions.js index ee1b972..ff7a042 100644 --- a/deploy/tencentDeployListFunctions.js +++ b/deploy/tencentDeployListFunctions.js @@ -26,7 +26,11 @@ class TencentDeployListFunction { async functionList() { const provider = new tencentProvider(this.serverless, this.options) - if (!this.options.credentials || !this.options.credentials.tencent_secret_id) { + if ( + !this.options.credentials || + !this.options.credentials.tencent_secret_id || + !this.options.credentials.tencent_owneruin + ) { const tencentTemp = await provider.getTempKey() this.options.credentials = { tencent_secret_id: tencentTemp.tencent_secret_id, diff --git a/info/tencentInfo.js b/info/tencentInfo.js index 27aae16..e0fe449 100644 --- a/info/tencentInfo.js +++ b/info/tencentInfo.js @@ -25,7 +25,11 @@ class TencentInfo { async info() { const provider = new tencentProvider(this.serverless, this.options) - if (!this.options.credentials || !this.options.credentials.tencent_secret_id) { + if ( + !this.options.credentials || + !this.options.credentials.tencent_secret_id || + !this.options.credentials.tencent_owneruin + ) { const tencentTemp = await provider.getTempKey() this.options.credentials = { tencent_secret_id: tencentTemp.tencent_secret_id, diff --git a/invoke/tencentInvoke.js b/invoke/tencentInvoke.js index c890338..d796f72 100644 --- a/invoke/tencentInvoke.js +++ b/invoke/tencentInvoke.js @@ -24,7 +24,11 @@ class TencentInvoke { async invoke() { const provider = new tencentProvider(this.serverless, this.options) - if (!this.options.credentials || !this.options.credentials.tencent_secret_id) { + if ( + !this.options.credentials || + !this.options.credentials.tencent_secret_id || + !this.options.credentials.tencent_owneruin + ) { const tencentTemp = await provider.getTempKey() this.options.credentials = { tencent_secret_id: tencentTemp.tencent_secret_id, diff --git a/logs/tencentLogs.js b/logs/tencentLogs.js index 9a050ac..7686914 100644 --- a/logs/tencentLogs.js +++ b/logs/tencentLogs.js @@ -50,7 +50,11 @@ class TencentLogs { async logs() { const provider = new tencentProvider(this.serverless, this.options) - if (!this.options.credentials || !this.options.credentials.tencent_secret_id) { + if ( + !this.options.credentials || + !this.options.credentials.tencent_secret_id || + !this.options.credentials.tencent_owneruin + ) { const tencentTemp = await provider.getTempKey() this.options.credentials = { tencent_secret_id: tencentTemp.tencent_secret_id, diff --git a/metrics/tencentMetrics.js b/metrics/tencentMetrics.js index b3eee65..a820076 100644 --- a/metrics/tencentMetrics.js +++ b/metrics/tencentMetrics.js @@ -58,7 +58,11 @@ class TencentInfo { async metrics() { const provider = new tencentProvider(this.serverless, this.options) - if (!this.options.credentials || !this.options.credentials.tencent_secret_id) { + if ( + !this.options.credentials || + !this.options.credentials.tencent_secret_id || + !this.options.credentials.tencent_owneruin + ) { const tencentTemp = await provider.getTempKey() this.options.credentials = { tencent_secret_id: tencentTemp.tencent_secret_id, diff --git a/package.json b/package.json index c2a24f5..8ba25b3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "serverless-tencent-scf", - "version": "0.1.26", + "version": "0.1.27", "description": "Provider plugin for the Serverless Framework v1.x which adds support for Tencent Cloud Functions.", "main": "index.js", "author": "Tencent Cloud, Inc.", diff --git a/remove/tencentRemove.js b/remove/tencentRemove.js index 4d41a8d..cb57ac5 100644 --- a/remove/tencentRemove.js +++ b/remove/tencentRemove.js @@ -25,7 +25,11 @@ class TencentRemove { async remove() { const provider = new tencentProvider(this.serverless, this.options) - if (!this.options.credentials || !this.options.credentials.tencent_secret_id) { + if ( + !this.options.credentials || + !this.options.credentials.tencent_secret_id || + !this.options.credentials.tencent_owneruin + ) { const tencentTemp = await provider.getTempKey() this.options.credentials = { tencent_secret_id: tencentTemp.tencent_secret_id, diff --git a/rollback/tencentRollback.js b/rollback/tencentRollback.js index 9c6c7e1..fb03a70 100644 --- a/rollback/tencentRollback.js +++ b/rollback/tencentRollback.js @@ -27,7 +27,11 @@ class TencentRollback { async rollback() { const provider = new tencentProvider(this.serverless, this.options) - if (!this.options.credentials || !this.options.credentials.tencent_secret_id) { + if ( + !this.options.credentials || + !this.options.credentials.tencent_secret_id || + !this.options.credentials.tencent_owneruin + ) { const tencentTemp = await provider.getTempKey() this.options.credentials = { tencent_secret_id: tencentTemp.tencent_secret_id, From da0ef2d7b694c2dc838fb0d9a41226b52eaf5355 Mon Sep 17 00:00:00 2001 From: dfounderliu Date: Tue, 28 Jan 2020 10:38:03 +0800 Subject: [PATCH 15/24] fix auth --- deploy/tencentDeploy.js | 16 +--------------- deploy/tencentDeployFunction.js | 16 +--------------- deploy/tencentDeployList.js | 17 ++--------------- deploy/tencentDeployListFunctions.js | 17 ++--------------- info/tencentInfo.js | 16 +--------------- invoke/tencentInvoke.js | 16 +--------------- logs/tencentLogs.js | 16 +--------------- metrics/tencentMetrics.js | 16 +--------------- package.json | 4 ++-- provider/tencentProvider.js | 25 ++++++++++++++++++++++++- remove/tencentRemove.js | 16 +--------------- rollback/tencentRollback.js | 16 +--------------- 12 files changed, 38 insertions(+), 153 deletions(-) diff --git a/deploy/tencentDeploy.js b/deploy/tencentDeploy.js index f983f7a..48b6458 100644 --- a/deploy/tencentDeploy.js +++ b/deploy/tencentDeploy.js @@ -27,21 +27,7 @@ class TencentDeploy { async deploy() { const provider = new tencentProvider(this.serverless, this.options) - if ( - !this.options.credentials || - !this.options.credentials.tencent_secret_id || - !this.options.credentials.tencent_owneruin - ) { - const tencentTemp = await provider.getTempKey() - this.options.credentials = { - tencent_secret_id: tencentTemp.tencent_secret_id, - tencent_secret_key: tencentTemp.tencent_secret_key, - tencent_appid: tencentTemp.tencent_appid, - tencent_owneruin: tencentTemp.tencent_owneruin - } - this.options.token = tencentTemp.token - this.options.timestamp = tencentTemp.timestamp - } + this.options = await provider.getUserCred(this.options) await provider.getUserAuth(this.options.credentials.tencent_owneruin) const services = this.provider.getServiceResource() diff --git a/deploy/tencentDeployFunction.js b/deploy/tencentDeployFunction.js index 66b452f..5e1be36 100644 --- a/deploy/tencentDeployFunction.js +++ b/deploy/tencentDeployFunction.js @@ -32,21 +32,7 @@ class TencentDeployFunction { async deploy() { const provider = new tencentProvider(this.serverless, this.options) - if ( - !this.options.credentials || - !this.options.credentials.tencent_secret_id || - !this.options.credentials.tencent_owneruin - ) { - const tencentTemp = await provider.getTempKey() - this.options.credentials = { - tencent_secret_id: tencentTemp.tencent_secret_id, - tencent_secret_key: tencentTemp.tencent_secret_key, - tencent_appid: tencentTemp.tencent_appid, - tencent_owneruin: tencentTemp.tencent_owneruin - } - this.options.token = tencentTemp.token - this.options.timestamp = tencentTemp.timestamp - } + this.options = await provider.getUserCred(this.options) await provider.getUserAuth(this.options.credentials.tencent_owneruin) const services = this.provider.getServiceResource() diff --git a/deploy/tencentDeployList.js b/deploy/tencentDeployList.js index 18e728e..4484548 100644 --- a/deploy/tencentDeployList.js +++ b/deploy/tencentDeployList.js @@ -24,22 +24,9 @@ class TencentDeployList { async serviceList() { const provider = new tencentProvider(this.serverless, this.options) - if ( - !this.options.credentials || - !this.options.credentials.tencent_secret_id || - !this.options.credentials.tencent_owneruin - ) { - const tencentTemp = await provider.getTempKey() - this.options.credentials = { - tencent_secret_id: tencentTemp.tencent_secret_id, - tencent_secret_key: tencentTemp.tencent_secret_key, - tencent_appid: tencentTemp.tencent_appid, - tencent_owneruin: tencentTemp.tencent_owneruin - } - this.options.token = tencentTemp.token - this.options.timestamp = tencentTemp.timestamp - } + this.options = await provider.getUserCred(this.options) await provider.getUserAuth(this.options.credentials.tencent_owneruin) + const Handler = new RollbackService(this.options, this.serverless) const fileKeyPrefix = this.serverless.service.service + '-' + this.options.stage const cosBucket = this.provider.getDeployCosBucket() diff --git a/deploy/tencentDeployListFunctions.js b/deploy/tencentDeployListFunctions.js index ff7a042..3ae3335 100644 --- a/deploy/tencentDeployListFunctions.js +++ b/deploy/tencentDeployListFunctions.js @@ -26,22 +26,9 @@ class TencentDeployListFunction { async functionList() { const provider = new tencentProvider(this.serverless, this.options) - if ( - !this.options.credentials || - !this.options.credentials.tencent_secret_id || - !this.options.credentials.tencent_owneruin - ) { - const tencentTemp = await provider.getTempKey() - this.options.credentials = { - tencent_secret_id: tencentTemp.tencent_secret_id, - tencent_secret_key: tencentTemp.tencent_secret_key, - tencent_appid: tencentTemp.tencent_appid, - tencent_owneruin: tencentTemp.tencent_owneruin - } - this.options.token = tencentTemp.token - this.options.timestamp = tencentTemp.timestamp - } + this.options = await provider.getUserCred(this.options) await provider.getUserAuth(this.options.credentials.tencent_owneruin) + try { const infoHandler = new InfoFunction(this.options, this.serverless) const deployHandler = new ListFunctions(this.options, this.serverless) diff --git a/info/tencentInfo.js b/info/tencentInfo.js index e0fe449..380d0a8 100644 --- a/info/tencentInfo.js +++ b/info/tencentInfo.js @@ -25,21 +25,7 @@ class TencentInfo { async info() { const provider = new tencentProvider(this.serverless, this.options) - if ( - !this.options.credentials || - !this.options.credentials.tencent_secret_id || - !this.options.credentials.tencent_owneruin - ) { - const tencentTemp = await provider.getTempKey() - this.options.credentials = { - tencent_secret_id: tencentTemp.tencent_secret_id, - tencent_secret_key: tencentTemp.tencent_secret_key, - tencent_appid: tencentTemp.tencent_appid, - tencent_owneruin: tencentTemp.tencent_owneruin - } - this.options.token = tencentTemp.token - this.options.timestamp = tencentTemp.timestamp - } + this.options = await provider.getUserCred(this.options) await provider.getUserAuth(this.options.credentials.tencent_owneruin) try { const region = this.options.region diff --git a/invoke/tencentInvoke.js b/invoke/tencentInvoke.js index d796f72..4b5a1eb 100644 --- a/invoke/tencentInvoke.js +++ b/invoke/tencentInvoke.js @@ -24,21 +24,7 @@ class TencentInvoke { async invoke() { const provider = new tencentProvider(this.serverless, this.options) - if ( - !this.options.credentials || - !this.options.credentials.tencent_secret_id || - !this.options.credentials.tencent_owneruin - ) { - const tencentTemp = await provider.getTempKey() - this.options.credentials = { - tencent_secret_id: tencentTemp.tencent_secret_id, - tencent_secret_key: tencentTemp.tencent_secret_key, - tencent_appid: tencentTemp.tencent_appid, - tencent_owneruin: tencentTemp.tencent_owneruin - } - this.options.token = tencentTemp.token - this.options.timestamp = tencentTemp.timestamp - } + this.options = await provider.getUserCred(this.options) await provider.getUserAuth(this.options.credentials.tencent_owneruin) try { const options = { diff --git a/logs/tencentLogs.js b/logs/tencentLogs.js index 7686914..f9a9e3b 100644 --- a/logs/tencentLogs.js +++ b/logs/tencentLogs.js @@ -50,21 +50,7 @@ class TencentLogs { async logs() { const provider = new tencentProvider(this.serverless, this.options) - if ( - !this.options.credentials || - !this.options.credentials.tencent_secret_id || - !this.options.credentials.tencent_owneruin - ) { - const tencentTemp = await provider.getTempKey() - this.options.credentials = { - tencent_secret_id: tencentTemp.tencent_secret_id, - tencent_secret_key: tencentTemp.tencent_secret_key, - tencent_appid: tencentTemp.tencent_appid, - tencent_owneruin: tencentTemp.tencent_owneruin - } - this.options.token = tencentTemp.token - this.options.timestamp = tencentTemp.timestamp - } + this.options = await provider.getUserCred(this.options) await provider.getUserAuth(this.options.credentials.tencent_owneruin) try { const timeFormat = 'yyyy-MM-dd hh:mm:ss' diff --git a/metrics/tencentMetrics.js b/metrics/tencentMetrics.js index a820076..2ba4723 100644 --- a/metrics/tencentMetrics.js +++ b/metrics/tencentMetrics.js @@ -58,21 +58,7 @@ class TencentInfo { async metrics() { const provider = new tencentProvider(this.serverless, this.options) - if ( - !this.options.credentials || - !this.options.credentials.tencent_secret_id || - !this.options.credentials.tencent_owneruin - ) { - const tencentTemp = await provider.getTempKey() - this.options.credentials = { - tencent_secret_id: tencentTemp.tencent_secret_id, - tencent_secret_key: tencentTemp.tencent_secret_key, - tencent_appid: tencentTemp.tencent_appid, - tencent_owneruin: tencentTemp.tencent_owneruin - } - this.options.token = tencentTemp.token - this.options.timestamp = tencentTemp.timestamp - } + this.options = await provider.getUserCred(this.options) await provider.getUserAuth(this.options.credentials.tencent_owneruin) try { const Handler = new MetricsFunction(this.options, this.serverless) diff --git a/package.json b/package.json index 8ba25b3..b130c27 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "serverless-tencent-scf", - "version": "0.1.27", + "version": "0.1.28", "description": "Provider plugin for the Serverless Framework v1.x which adds support for Tencent Cloud Functions.", "main": "index.js", "author": "Tencent Cloud, Inc.", @@ -44,7 +44,7 @@ "tencentcloud-sdk-nodejs": "^3.0.87", "universal-analytics": "^0.4.20", "tencent-login": "^0.1.6", - "serverless-tencent-auth-tool": "^1.0.0" + "serverless-tencent-auth-tool": "^1.0.9" }, "devDependencies": { "coveralls": "^3.0.5", diff --git a/provider/tencentProvider.js b/provider/tencentProvider.js index 6e605e9..7062a7d 100644 --- a/provider/tencentProvider.js +++ b/provider/tencentProvider.js @@ -56,10 +56,33 @@ class TencentProvider { return constants.providerName } + async getUserCred(options) { + if (!options.credentials || !options.credentials.tencent_secret_id) { + const tencentTemp = await this.getTempKey() + this.options.credentials = { + tencent_secret_id: tencentTemp.tencent_secret_id, + tencent_secret_key: tencentTemp.tencent_secret_key, + tencent_appid: tencentTemp.tencent_appid, + tencent_owneruin: tencentTemp.tencent_owneruin + } + options.token = tencentTemp.token + options.timestamp = tencentTemp.timestamp + } + if (!options.credentials.tencent_owneruin || !options.credentials.tencent_appid) { + const appid = await this.getAppid({ + SecretId: options.credentials.tencent_secret_id, + SecretKey: options.credentials.tencent_secret_key + }) + options.credentials.tencent_appid = appid.AppId + options.credentials.tencent_owneruin = appid.OwnerUin + } + return options + } + async getUserAuth(uin) { try { const getUserAuthInfo = new GetUserAuthInfo() - const result = await getUserAuthInfo.isAuth(uin) + const result = await getUserAuthInfo.isAuth(uin, 'plugin') if (result['Error'] == true) { console.log('Failed to get real name authentication result.') process.exit(-1) diff --git a/remove/tencentRemove.js b/remove/tencentRemove.js index cb57ac5..8b19884 100644 --- a/remove/tencentRemove.js +++ b/remove/tencentRemove.js @@ -25,21 +25,7 @@ class TencentRemove { async remove() { const provider = new tencentProvider(this.serverless, this.options) - if ( - !this.options.credentials || - !this.options.credentials.tencent_secret_id || - !this.options.credentials.tencent_owneruin - ) { - const tencentTemp = await provider.getTempKey() - this.options.credentials = { - tencent_secret_id: tencentTemp.tencent_secret_id, - tencent_secret_key: tencentTemp.tencent_secret_key, - tencent_appid: tencentTemp.tencent_appid, - tencent_owneruin: tencentTemp.tencent_owneruin - } - this.options.token = tencentTemp.token - this.options.timestamp = tencentTemp.timestamp - } + this.options = await provider.getUserCred(this.options) await provider.getUserAuth(this.options.credentials.tencent_owneruin) try { const handler = new RemoveFunction(this.options, this.serverless) diff --git a/rollback/tencentRollback.js b/rollback/tencentRollback.js index fb03a70..ed21f8b 100644 --- a/rollback/tencentRollback.js +++ b/rollback/tencentRollback.js @@ -27,21 +27,7 @@ class TencentRollback { async rollback() { const provider = new tencentProvider(this.serverless, this.options) - if ( - !this.options.credentials || - !this.options.credentials.tencent_secret_id || - !this.options.credentials.tencent_owneruin - ) { - const tencentTemp = await provider.getTempKey() - this.options.credentials = { - tencent_secret_id: tencentTemp.tencent_secret_id, - tencent_secret_key: tencentTemp.tencent_secret_key, - tencent_appid: tencentTemp.tencent_appid, - tencent_owneruin: tencentTemp.tencent_owneruin - } - this.options.token = tencentTemp.token - this.options.timestamp = tencentTemp.timestamp - } + this.options = await provider.getUserCred(this.options) await provider.getUserAuth(this.options.credentials.tencent_owneruin) const Handler = new RollbackService(this.options, this.serverless) const fileKeyPrefix = this.serverless.service.service + '-' + this.options.stage From 215be0d96c4e6cc79f01aeab238a6837579ff5d7 Mon Sep 17 00:00:00 2001 From: dfounderliu Date: Tue, 28 Jan 2020 16:33:58 +0800 Subject: [PATCH 16/24] add uin --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index b130c27..b00ed7f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "serverless-tencent-scf", - "version": "0.1.28", + "version": "0.1.29", "description": "Provider plugin for the Serverless Framework v1.x which adds support for Tencent Cloud Functions.", "main": "index.js", "author": "Tencent Cloud, Inc.", @@ -44,7 +44,8 @@ "tencentcloud-sdk-nodejs": "^3.0.87", "universal-analytics": "^0.4.20", "tencent-login": "^0.1.6", - "serverless-tencent-auth-tool": "^1.0.9" + "serverless-tencent-tools": "^0.0.9", + "serverless-tencent-auth-tool": "^1.0.12" }, "devDependencies": { "coveralls": "^3.0.5", From d952625ffd70270059660d57ab6861b19a37b261 Mon Sep 17 00:00:00 2001 From: dfounderliu Date: Tue, 28 Jan 2020 16:44:04 +0800 Subject: [PATCH 17/24] update version --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index b00ed7f..c898ab3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "serverless-tencent-scf", - "version": "0.1.29", + "version": "0.1.30", "description": "Provider plugin for the Serverless Framework v1.x which adds support for Tencent Cloud Functions.", "main": "index.js", "author": "Tencent Cloud, Inc.", @@ -44,8 +44,8 @@ "tencentcloud-sdk-nodejs": "^3.0.87", "universal-analytics": "^0.4.20", "tencent-login": "^0.1.6", - "serverless-tencent-tools": "^0.0.9", - "serverless-tencent-auth-tool": "^1.0.12" + "serverless-tencent-tools": "^0.0.10", + "serverless-tencent-auth-tool": "^1.0.13" }, "devDependencies": { "coveralls": "^3.0.5", From bd3bbf7caf0d63c28e3b2ca34af5e3fe0f506939 Mon Sep 17 00:00:00 2001 From: dfounderliu Date: Sun, 2 Feb 2020 14:52:49 +0800 Subject: [PATCH 18/24] add uin --- deploy/tencentDeployFunction.js | 19 +++++++++++++++++-- package.json | 2 +- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/deploy/tencentDeployFunction.js b/deploy/tencentDeployFunction.js index 5e1be36..6a5c6d5 100644 --- a/deploy/tencentDeployFunction.js +++ b/deploy/tencentDeployFunction.js @@ -79,6 +79,22 @@ class TencentDeployFunction { const oldFunc = await func.deploy('default', funcObject) this.serverless.cli.log(`Created function ${funcObject.FuncName}`) + // when update code Status is Active, continue + let status = 'Updating' + let times = 90 + while (status == 'Updating' || status == 'Creating') { + const tempFunc = await func.getFunction('default', funcObject.FuncName) + status = tempFunc.Status + await utils.sleep(1000) + times = times - 1 + if (times <= 0) { + throw `Function ${funcObject.FuncName} create/update failed` + } + } + if (status != 'Active') { + throw `Function ${funcObject.FuncName} create/update failed` + } + this.serverless.cli.log(`Updating configure for function ${funcObject.FuncName}`) await func.updateConfiguration('default', oldFunc, funcObject) @@ -86,8 +102,7 @@ class TencentDeployFunction { await func.createTags('default', funcObject.FuncName, funcObject.Properties.Tags) // Function status - let status = 'Updating' - let times = 90 + status = 'Updating' while (status == 'Updating' || status == 'Creating') { const tempFunc = await func.getFunction('default', funcObject.FuncName) status = tempFunc.Status diff --git a/package.json b/package.json index c898ab3..d25653c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "serverless-tencent-scf", - "version": "0.1.30", + "version": "0.1.33", "description": "Provider plugin for the Serverless Framework v1.x which adds support for Tencent Cloud Functions.", "main": "index.js", "author": "Tencent Cloud, Inc.", From 52f428013e5808e73dc627dbef7b404cfee32295 Mon Sep 17 00:00:00 2001 From: dfounderliu Date: Tue, 4 Feb 2020 12:54:18 +0800 Subject: [PATCH 19/24] fix auth --- provider/tencentProvider.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/provider/tencentProvider.js b/provider/tencentProvider.js index 7062a7d..62ec223 100644 --- a/provider/tencentProvider.js +++ b/provider/tencentProvider.js @@ -82,7 +82,7 @@ class TencentProvider { async getUserAuth(uin) { try { const getUserAuthInfo = new GetUserAuthInfo() - const result = await getUserAuthInfo.isAuth(uin, 'plugin') + const result = await getUserAuthInfo.isAuth(uin, { client: 'plugin' }) if (result['Error'] == true) { console.log('Failed to get real name authentication result.') process.exit(-1) From 50936a70e8739a386934294a12db45ef2e096393 Mon Sep 17 00:00:00 2001 From: dfounderliu Date: Fri, 7 Feb 2020 08:54:10 +0800 Subject: [PATCH 20/24] fix status --- .eslintrc.js | 1 - Changelog.md | 6 ++++++ deploy/lib/deployFunction.js | 26 +++++++++++++------------- deploy/tencentDeploy.js | 14 +------------- deploy/tencentDeployFunction.js | 27 ++------------------------- invoke/tencentInvoke.js | 3 --- package.json | 6 +++--- provider/tencentProvider.js | 25 +++++++++++++++++++++++-- rollback/tencentRollback.js | 8 ++++++++ 9 files changed, 56 insertions(+), 60 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 60a9b4f..420e593 100755 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -43,7 +43,6 @@ module.exports = { } ], 'no-alert': 'error', - 'no-console': 'error', 'no-const-assign': 'error', 'no-else-return': 'error', 'no-empty': 'off', diff --git a/Changelog.md b/Changelog.md index e44ee92..d6298a7 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,4 +1,10 @@ # 变更历史 + + +## 2020-02-06 +* 修复rollback操作可能出现函数状态错误问题 +* 优化函数状态检测部分代码 + ## 2019-11-26 * 更新函数状态,提高部署成功率 diff --git a/deploy/lib/deployFunction.js b/deploy/lib/deployFunction.js index 57ac525..e206538 100644 --- a/deploy/lib/deployFunction.js +++ b/deploy/lib/deployFunction.js @@ -21,19 +21,7 @@ class DeployFunction extends AbstractHandler { } this.serverless.cli.log('Updating code... ') await this.updateFunctionCode(ns, funcObject) - // when update code Status is Active, continue - let status = 'Updating' - let times = 90 - while (status == 'Updating' || status == 'Creating') { - const tempFunc = await this.getFunction(ns, funcObject.FuncName) - status = tempFunc.Status - await utils.sleep(1000) - times = times - 1 - if (times <= 0) { - throw `Function ${funcObject.FuncName} update failed` - } - } - if (status != 'Active') { + if ((await this.checkStatus(ns, funcObject)) == false) { throw `Function ${funcObject.FuncName} update failed` } this.serverless.cli.log('Updating configure... ') @@ -43,6 +31,18 @@ class DeployFunction extends AbstractHandler { return null } + async checkStatus(ns, funcObject) { + let status = 'Updating' + let times = 90 + while ((status == 'Updating' || status == 'Creating') && times > 0) { + const tempFunc = await this.getFunction(ns, funcObject.FuncName) + status = tempFunc.Status + await utils.sleep(1000) + times = times - 1 + } + return status != 'Active' ? false : true + } + async addRole() { try { const roleName = 'SCF_QcsRole' diff --git a/deploy/tencentDeploy.js b/deploy/tencentDeploy.js index 48b6458..3e3f28a 100644 --- a/deploy/tencentDeploy.js +++ b/deploy/tencentDeploy.js @@ -66,19 +66,7 @@ class TencentDeploy { this.serverless.cli.log(`Setting tags for function ${funcObject.FuncName}`) await func.createTags('default', funcObject.FuncName, funcObject.Properties.Tags) - // Function status - let status = 'Updating' - let times = 90 - while (status == 'Updating' || status == 'Creating') { - const tempFunc = await func.getFunction('default', funcObject.FuncName) - status = tempFunc.Status - await utils.sleep(1000) - times = times - 1 - if (times <= 0) { - throw `Function ${funcObject.FuncName} create/update failed` - } - } - if (status != 'Active') { + if ((await func.checkStatus('default', funcObject)) == false) { throw `Function ${funcObject.FuncName} create/update failed` } diff --git a/deploy/tencentDeployFunction.js b/deploy/tencentDeployFunction.js index 6a5c6d5..137c460 100644 --- a/deploy/tencentDeployFunction.js +++ b/deploy/tencentDeployFunction.js @@ -79,19 +79,7 @@ class TencentDeployFunction { const oldFunc = await func.deploy('default', funcObject) this.serverless.cli.log(`Created function ${funcObject.FuncName}`) - // when update code Status is Active, continue - let status = 'Updating' - let times = 90 - while (status == 'Updating' || status == 'Creating') { - const tempFunc = await func.getFunction('default', funcObject.FuncName) - status = tempFunc.Status - await utils.sleep(1000) - times = times - 1 - if (times <= 0) { - throw `Function ${funcObject.FuncName} create/update failed` - } - } - if (status != 'Active') { + if ((await func.checkStatus('default', funcObject)) == false) { throw `Function ${funcObject.FuncName} create/update failed` } @@ -101,18 +89,7 @@ class TencentDeployFunction { this.serverless.cli.log(`Setting tags for function ${funcObject.FuncName}`) await func.createTags('default', funcObject.FuncName, funcObject.Properties.Tags) - // Function status - status = 'Updating' - while (status == 'Updating' || status == 'Creating') { - const tempFunc = await func.getFunction('default', funcObject.FuncName) - status = tempFunc.Status - await utils.sleep(1000) - times = times - 1 - if (times <= 0) { - throw `Function ${funcObject.FuncName} create/update failed` - } - } - if (status != 'Active') { + if ((await func.checkStatus('default', funcObject)) == false) { throw `Function ${funcObject.FuncName} create/update failed` } diff --git a/invoke/tencentInvoke.js b/invoke/tencentInvoke.js index 4b5a1eb..0ac662f 100644 --- a/invoke/tencentInvoke.js +++ b/invoke/tencentInvoke.js @@ -27,9 +27,6 @@ class TencentInvoke { this.options = await provider.getUserCred(this.options) await provider.getUserAuth(this.options.credentials.tencent_owneruin) try { - const options = { - region: this.options.region - } const invokeHandler = new Invoke(this.options, this.serverless) let context = null if (this.options.data) { diff --git a/package.json b/package.json index d25653c..5f00ddd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "serverless-tencent-scf", - "version": "0.1.33", + "version": "0.1.34", "description": "Provider plugin for the Serverless Framework v1.x which adds support for Tencent Cloud Functions.", "main": "index.js", "author": "Tencent Cloud, Inc.", @@ -44,8 +44,8 @@ "tencentcloud-sdk-nodejs": "^3.0.87", "universal-analytics": "^0.4.20", "tencent-login": "^0.1.6", - "serverless-tencent-tools": "^0.0.10", - "serverless-tencent-auth-tool": "^1.0.13" + "serverless-tencent-tools": "^0.0.11", + "serverless-tencent-auth-tool": "^1.0.18" }, "devDependencies": { "coveralls": "^3.0.5", diff --git a/provider/tencentProvider.js b/provider/tencentProvider.js index 62ec223..c632606 100644 --- a/provider/tencentProvider.js +++ b/provider/tencentProvider.js @@ -7,11 +7,14 @@ const util = require('util') const QRCode = require('qrcode') const TencentLogin = require('tencent-login') const tencentcloud = require('tencentcloud-sdk-nodejs') -const { GetUserAuthInfo } = require('serverless-tencent-tools').Account +const serverlessTencentTools = require('serverless-tencent-tools') +const { GetUserAuthInfo } = serverlessTencentTools.Account +const { DataReport } = serverlessTencentTools.Others.DataReport const ClientProfile = require('tencentcloud-sdk-nodejs/tencentcloud/common/profile/client_profile.js') const HttpProfile = require('tencentcloud-sdk-nodejs/tencentcloud/common/profile/http_profile.js') const AbstractModel = require('tencentcloud-sdk-nodejs/tencentcloud/common/abstract_model') const AbstractClient = require('tencentcloud-sdk-nodejs/tencentcloud/common/abstract_client') + const constants = { providerName: 'tencent' } @@ -50,6 +53,19 @@ class TencentProvider { this.getCredentials(this.serverless, this.options) this.serverless.setProvider(constants.providerName, this) this.provider = this + let commands = '' + const commandsAttr = this.serverless.pluginManager.cliCommands + for (let i = 0; i < commandsAttr.length; i++) { + commands = commands + (i == 0 ? '' : '_') + commandsAttr[i] + } + this.reportInputs = { + name: 'serverless-tencent-scf', + project: this.serverless.service.service, + action: commands + } + try { + new DataReport().report(this.reportInputs) + } catch (e) {} } static getProviderName() { @@ -75,14 +91,19 @@ class TencentProvider { }) options.credentials.tencent_appid = appid.AppId options.credentials.tencent_owneruin = appid.OwnerUin + this.tempUin = appid.OwnerUin } return options } async getUserAuth(uin) { try { + try { + this.reportInputs.uin = uin + new DataReport().report(this.reportInputs) + } catch (e) {} const getUserAuthInfo = new GetUserAuthInfo() - const result = await getUserAuthInfo.isAuth(uin, { client: 'plugin' }) + const result = await getUserAuthInfo.isAuth(uin, this.reportInputs) if (result['Error'] == true) { console.log('Failed to get real name authentication result.') process.exit(-1) diff --git a/rollback/tencentRollback.js b/rollback/tencentRollback.js index ed21f8b..440156a 100644 --- a/rollback/tencentRollback.js +++ b/rollback/tencentRollback.js @@ -88,9 +88,17 @@ class TencentRollback { const oldFunc = await func.deploy('default', funcObject) this.serverless.cli.log(`Rollback function ${funcObject.FuncName}`) + if ((await func.checkStatus('default', funcObject)) == false) { + throw `Function ${funcObject.FuncName} create/update failed` + } + this.serverless.cli.log(`Rollback configure for function ${funcObject.FuncName}`) await func.updateConfiguration('default', oldFunc, funcObject) + if ((await func.checkStatus('default', funcObject)) == false) { + throw `Function ${funcObject.FuncName} create/update failed` + } + this.serverless.cli.log(`Setting tags for function ${funcObject.FuncName}`) await func.createTags('default', funcObject.FuncName, funcObject.Properties.Tags) From 3fe49113746ba3184e5520e4ec842059e3525682 Mon Sep 17 00:00:00 2001 From: dfounderliu Date: Fri, 7 Feb 2020 15:05:18 +0800 Subject: [PATCH 21/24] fix cos_client --- Changelog.md | 2 ++ package.json | 2 +- shared/handler.js | 30 ++++++++++-------------------- 3 files changed, 13 insertions(+), 21 deletions(-) diff --git a/Changelog.md b/Changelog.md index d6298a7..185fea1 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,6 +1,8 @@ # 变更历史 +## 2020-02-06 +* 优化COS实例创建代码 ## 2020-02-06 * 修复rollback操作可能出现函数状态错误问题 diff --git a/package.json b/package.json index 5f00ddd..216d01a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "serverless-tencent-scf", - "version": "0.1.34", + "version": "0.1.35", "description": "Provider plugin for the Serverless Framework v1.x which adds support for Tencent Cloud Functions.", "main": "index.js", "author": "Tencent Cloud, Inc.", diff --git a/shared/handler.js b/shared/handler.js index c352978..149db09 100644 --- a/shared/handler.js +++ b/shared/handler.js @@ -11,7 +11,6 @@ const MonitorClinet = tencentcloud.monitor.v20180724.Client class AbstractHandler { constructor(options, serverless) { - const { credentials, region } = options const { tencent_appid, tencent_secret_id, tencent_secret_key } = credentials this.options = options @@ -98,26 +97,17 @@ class AbstractHandler { const chunkSize = options.chunkSize || 1024 * 1024 * 8 const timeout = options.timeout || 120 - if (!options.token) { - return new tencentcloudCos({ - SecretId: secret_id, - SecretKey: secret_key, - FileParallelLimit: fileParallelLimit, - ChunkParallelLimit: chunkParallelLimit, - ChunkSize: chunkSize, - Timeout: timeout * 1000 - }) - } - return new tencentcloudCos({ - getAuthorization: function(option, callback) { - callback({ - TmpSecretId: secret_id, - TmpSecretKey: secret_key, - XCosSecurityToken: options.token, - ExpiredTime: options.timestamp - }) - } + SecretId: secret_id, + SecretKey: secret_key, + FileParallelLimit: fileParallelLimit, + ChunkParallelLimit: chunkParallelLimit, + ChunkSize: chunkSize, + Timeout: timeout * 1000, + TmpSecretId: secret_id, + TmpSecretKey: secret_key, + XCosSecurityToken: options.token, + ExpiredTime: options.timestamp }) } From ed06754bf02edb48ac32c0ea884095ef0fef6b02 Mon Sep 17 00:00:00 2001 From: dfounderliu Date: Sat, 8 Feb 2020 11:36:07 +0800 Subject: [PATCH 22/24] fix status --- deploy/tencentDeploy.js | 6 ++++++ deploy/tencentDeployFunction.js | 3 +++ package.json | 2 +- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/deploy/tencentDeploy.js b/deploy/tencentDeploy.js index 3e3f28a..01eec4d 100644 --- a/deploy/tencentDeploy.js +++ b/deploy/tencentDeploy.js @@ -112,11 +112,17 @@ class TencentDeploy { if (this.options.function && this.options.function != funcName) { continue } + const funcObject = _.cloneDeep(services.Resources.default[funcName]) + funcObject.Name = funcName + funcObject.FuncName = this.provider.getFunctionName(funcName) const deployFunctionName = this.provider.getFunctionName(funcName) outputInformation = outputInformation + ` ${funcName}: ${deployFunctionName}\n` functionInformation = await func.getFunction('default', deployFunctionName, false) if (functionInformation.Triggers && functionInformation.Triggers.length > 0) { for (let i = 0; i <= functionInformation.Triggers.length; i++) { + if ((await func.checkStatus('default', funcObject)) == false) { + throw `Function ${funcObject.FuncName} create/update failed` + } const thisTrigger = functionInformation.Triggers[i] try { if (thisTrigger.Type == 'apigw') { diff --git a/deploy/tencentDeployFunction.js b/deploy/tencentDeployFunction.js index 137c460..01ed6f2 100644 --- a/deploy/tencentDeployFunction.js +++ b/deploy/tencentDeployFunction.js @@ -130,6 +130,9 @@ class TencentDeployFunction { const functionInformation = await func.getFunction('default', deployFunctionName, false) if (functionInformation.Triggers && functionInformation.Triggers.length > 0) { for (let i = 0; i <= functionInformation.Triggers.length; i++) { + if ((await func.checkStatus('default', funcObject)) == false) { + throw `Function ${funcObject.FuncName} create/update failed` + } const thisTrigger = functionInformation.Triggers[i] try { if (thisTrigger.Type == 'apigw') { diff --git a/package.json b/package.json index 216d01a..144ca26 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "serverless-tencent-scf", - "version": "0.1.35", + "version": "0.1.36", "description": "Provider plugin for the Serverless Framework v1.x which adds support for Tencent Cloud Functions.", "main": "index.js", "author": "Tencent Cloud, Inc.", From a37c7eff620e24e069745a6af6481c27e8a2fb70 Mon Sep 17 00:00:00 2001 From: dfounderliu Date: Mon, 10 Feb 2020 08:37:29 +0800 Subject: [PATCH 23/24] fix status --- package.json | 2 +- provider/tencentProvider.js | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 144ca26..bbdc032 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "serverless-tencent-scf", - "version": "0.1.36", + "version": "0.1.37", "description": "Provider plugin for the Serverless Framework v1.x which adds support for Tencent Cloud Functions.", "main": "index.js", "author": "Tencent Cloud, Inc.", diff --git a/provider/tencentProvider.js b/provider/tencentProvider.js index c632606..3cb97e7 100644 --- a/provider/tencentProvider.js +++ b/provider/tencentProvider.js @@ -105,7 +105,7 @@ class TencentProvider { const getUserAuthInfo = new GetUserAuthInfo() const result = await getUserAuthInfo.isAuth(uin, this.reportInputs) if (result['Error'] == true) { - console.log('Failed to get real name authentication result.') + console.log('未获取到实名认证结果,请重试。') process.exit(-1) } else { if (result['Message']['Authentication'] == 1) { @@ -113,15 +113,15 @@ class TencentProvider { } const verifyUrl = 'https://cloud.tencent.com/verify/identity' console.log( - "You don't have real name authentication yet. You can open the url or scan QR code for real name authentication." + '系统检测您还未进行实名认证,请您扫描二下方二维码或者进入下方的地址,进行实名认证,实名认证之后可重新操作。' ) - console.log('Real name authentication url: ') + console.log('实名认证地址: ') console.log('https://console.cloud.tencent.com/developer/auth') - console.log('Real name authentication QR code: ') + console.log('实名认证二维码: ') QRCode.toString(verifyUrl, { type: 'terminal' }, function(err, url) { console.log(url) }) - console.log('Please re operate after real name authentication.') + console.log('请实名认证之后,重新执行本次操作。') process.exit(-1) } } catch (e) { From b4bd6de5865c942e0163d6182e894c9472827ae7 Mon Sep 17 00:00:00 2001 From: dfounderliu Date: Mon, 24 Feb 2020 18:35:11 +0800 Subject: [PATCH 24/24] fix readme --- index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/index.js b/index.js index feb1846..8aa36de 100755 --- a/index.js +++ b/index.js @@ -27,7 +27,6 @@ class TencentIndex { this.serverless.pluginManager.addPlugin(TencentInfo) this.serverless.pluginManager.addPlugin(TencentLogs) } - } module.exports = TencentIndex