diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c966e94..ebd10ce 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -43,5 +43,6 @@ jobs: env: SERVERLESS_PLATFORM_VENDOR: tencent GLOBAL_ACCELERATOR_NA: true + TENCENT_APP_ID: ${{ secrets.TENCENT_APP_ID }} TENCENT_SECRET_ID: ${{ secrets.TENCENT_SECRET_ID }} TENCENT_SECRET_KEY: ${{ secrets.TENCENT_SECRET_KEY }} diff --git a/__tests__/index.test.js b/__tests__/index.test.js index 3333441..becd3b1 100644 --- a/__tests__/index.test.js +++ b/__tests__/index.test.js @@ -30,7 +30,7 @@ const credentials = { } // get serverless construct sdk -const sdk = getServerlessSdk(instanceYaml.org) +const sdk = getServerlessSdk(instanceYaml.org, process.env.TENCENT_APP_ID) it('should deploy success', async () => { const instance = await sdk.deploy(instanceYaml, credentials) diff --git a/__tests__/lib/utils.js b/__tests__/lib/utils.js index d047afa..2d9631b 100644 --- a/__tests__/lib/utils.js +++ b/__tests__/lib/utils.js @@ -12,9 +12,10 @@ const generateId = () => * Initializes and returns an instance of the serverless sdk * @param ${string} orgName - the serverless org name. */ -const getServerlessSdk = (orgName) => { +const getServerlessSdk = (orgName, orgUid) => { const sdk = new ServerlessSDK({ context: { + orgUid, orgName } }) diff --git a/package.json b/package.json index 2e5b9fd..8b39680 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@semantic-release/commit-analyzer": "^8.0.1", "@semantic-release/git": "^9.0.0", "@semantic-release/release-notes-generator": "^9.0.1", - "@serverless/platform-client-china": "^2.0.7", + "@serverless/platform-client-china": "^2.1.9", "@ygkit/secure": "^0.0.3", "babel-eslint": "^10.1.0", "dotenv": "^8.2.0", diff --git a/serverless.component.yml b/serverless.component.yml index 79972e9..7354ed2 100644 --- a/serverless.component.yml +++ b/serverless.component.yml @@ -1,5 +1,5 @@ name: websocket -version: 0.4.1 +version: 0.5.0 author: Tencent Cloud, Inc. org: Tencent Cloud, Inc. description: Deploys websocket service on Tencent Cloud. diff --git a/src/package.json b/src/package.json index 0b5c442..0b11535 100644 --- a/src/package.json +++ b/src/package.json @@ -2,6 +2,6 @@ "dependencies": { "@slsplus/migrate": "^0.0.1-beta-4", "download": "^8.0.0", - "tencent-component-toolkit": "^1.19.8" + "tencent-component-toolkit": "^2.5.2" } } diff --git a/src/serverless.js b/src/serverless.js index 1bb8d57..2634b73 100644 --- a/src/serverless.js +++ b/src/serverless.js @@ -1,6 +1,6 @@ const { Component } = require('@serverless/core') -const { Scf, Apigw, Cns } = require('tencent-component-toolkit') -const { TypeError } = require('tencent-component-toolkit/src/utils/error') +const { Scf, Apigw } = require('tencent-component-toolkit') +const { ApiTypeError } = require('tencent-component-toolkit/lib/utils/error') const { migrateFramework } = require('@slsplus/migrate') const { uploadCodeToCos, getDefaultProtocol, initializeInputs, deepClone } = require('./utils') const initConfigs = require('./config') @@ -10,7 +10,7 @@ class ServerlessComponent extends Component { const { tmpSecrets } = this.credentials.tencent if (!tmpSecrets || !tmpSecrets.TmpSecretId) { - throw new TypeError( + throw new ApiTypeError( 'CREDENTIAL', 'Cannot get secretId/Key, your account could be sub-account and does not have the access to use SLS_QcsRole, please make sure the role exists first, then visit https://cloud.tencent.com/document/product/1154/43006, follow the instructions to bind the role to your account.' ) @@ -81,34 +81,6 @@ class ServerlessComponent extends Component { return faasOutputs } - // try to add dns record - async tryToAddDnsRecord(credentials, customDomains) { - try { - const cns = new Cns(credentials) - for (let i = 0; i < customDomains.length; i++) { - const item = customDomains[i] - if (item.domainPrefix) { - await cns.deploy({ - domain: item.subDomain.replace(`${item.domainPrefix}.`, ''), - records: [ - { - subDomain: item.domainPrefix, - recordType: 'CNAME', - recordLine: '默认', - value: item.cname, - ttl: 600, - mx: 10, - status: 'enable' - } - ] - }) - } - } - } catch (e) { - console.log('METHOD_tryToAddDnsRecord', e.message) - } - } - async deployApigw(credentials, inputs) { if (inputs.isDisabled) { return {} @@ -147,10 +119,6 @@ class ServerlessComponent extends Component { } if (apigwOutput.customDomains) { - // TODO: need confirm add cns authentication - if (inputs.autoAddDnsRecord === true) { - // await this.tryToAddDnsRecord(credentials, apigwOutput.customDomains) - } outputs.customDomains = apigwOutput.customDomains } return outputs @@ -171,7 +139,7 @@ class ServerlessComponent extends Component { inputs.environment.variables.wsBackUrl = wsBackUrl const scf = new Scf(credentials, inputs.region) - await scf.updatefunctionConfigure(inputs) + await scf.scf.updateConfigure(inputs) console.log(`Add wsBackUrl environment variable for function ${inputs.name} successfully`) } diff --git a/src/utils.js b/src/utils.js index 397558a..2f0d342 100644 --- a/src/utils.js +++ b/src/utils.js @@ -2,7 +2,7 @@ const path = require('path') const fs = require('fs') const { Cos } = require('tencent-component-toolkit') const download = require('download') -const { TypeError } = require('tencent-component-toolkit/src/utils/error') +const { ApiTypeError } = require('tencent-component-toolkit/lib/utils/error') /* * Generates a random id @@ -79,7 +79,7 @@ const getCodeZipPath = async (instance, inputs) => { filename: `${filename}.zip` }) } catch (e) { - throw new TypeError(`DOWNLOAD_TEMPLATE`, 'Download default template failed.') + throw new ApiTypeError(`DOWNLOAD_TEMPLATE`, 'Download default template failed.') } zipPath = `${downloadPath}/${filename}.zip` } else {