From 64d275d2f0caaa78b249cc30b0c387df74671ea0 Mon Sep 17 00:00:00 2001 From: dfounderliu Date: Tue, 4 Feb 2020 15:24:18 +0800 Subject: [PATCH 1/4] update version --- package.json | 2 +- src/index.js | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 4b76cd6..f4efcb4 100755 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@serverless/tencent-flask", "description": "Tencent Cloud Flask Serverless Component", - "version": "0.1.7", + "version": "0.1.8", "main": "serverless.js", "publishConfig": { "access": "public" diff --git a/src/index.js b/src/index.js index fb68a78..c2f778a 100644 --- a/src/index.js +++ b/src/index.js @@ -83,6 +83,7 @@ class TencentFlask extends Component { const tencentCloudFunction = await this.load('@serverless/tencent-scf') const tencentApiGateway = await this.load('@serverless/tencent-apigateway') + inputs.fromClientRemark = inputs.fromClientRemark || 'tencent-flask' const tencentCloudFunctionOutputs = await tencentCloudFunction(inputs) const apigwParam = { serviceName: inputs.serviceName, @@ -113,6 +114,7 @@ class TencentFlask extends Component { apigwParam.endpoints[0].auth = inputs.apigatewayConf.auth } + apigwParam.fromClientRemark = inputs.fromClientRemark || 'tencent-flask' const tencentApiGatewayOutputs = await tencentApiGateway(apigwParam) const outputs = { region: inputs.region, @@ -130,12 +132,15 @@ class TencentFlask extends Component { return outputs } - async remove() { + async remove(inputs = {}) { + const removeInput = { + fromClientRemark: inputs.fromClientRemark || 'tencent-flask' + } const tencentCloudFunction = await this.load('@serverless/tencent-scf') const tencentApiGateway = await this.load('@serverless/tencent-apigateway') - await tencentCloudFunction.remove() - await tencentApiGateway.remove() + await tencentCloudFunction.remove(removeInput) + await tencentApiGateway.remove(removeInput) return {} } From 5caa2feb329283506ff30a82dacfc0c41b2087b3 Mon Sep 17 00:00:00 2001 From: dfounderliu Date: Tue, 4 Feb 2020 16:26:38 +0800 Subject: [PATCH 2/4] update dependencies and add component name --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index f4efcb4..134a19d 100755 --- a/package.json +++ b/package.json @@ -47,8 +47,8 @@ }, "dependencies": { "@serverless/core": "^1.1.1", - "@serverless/tencent-apigateway": "^2.0.0", - "@serverless/tencent-scf": "^2.0.2", + "@serverless/tencent-apigateway": "^2.0.4", + "@serverless/tencent-scf": "^2.0.9", "@yugasun/python-requirements": "^0.1.2", "ext": "^1.4.0", "type": "^2.0.0" From 1d362b22441fcaf1f8ae6e9f648545fce093e10c Mon Sep 17 00:00:00 2001 From: dfounderliu Date: 2020年3月17日 12:14:03 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=A4=9A=E5=9C=B0?= =?UTF-8?q?=E5=9F=9F=E9=83=A8=E7=BD=B2=E8=83=BD=E5=8A=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- package.json | 11 +--- src/index.js | 143 +++++++++++---------------------------------------- 3 files changed, 32 insertions(+), 124 deletions(-) diff --git a/README.md b/README.md index d621d70..11d8f38 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ app = Flask(__name__) @app.route("/") def index(): - return "Hello Flash" + return "Hello Flask" @app.route("/users") def users(): diff --git a/package.json b/package.json index 134a19d..d474ce8 100755 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@serverless/tencent-flask", "description": "Tencent Cloud Flask Serverless Component", - "version": "0.1.8", + "version": "0.1.10", "main": "serverless.js", "publishConfig": { "access": "public" @@ -24,12 +24,6 @@ }, "author": "Tencent Cloud, Inc.", "license": "Apache-2.0", - "husky": { - "hooks": { - "pre-commit": "lint-staged", - "commit-msg": "commitlint -E HUSKY_GIT_PARAMS" - } - }, "lint-staged": { "**/*.{js,ts,tsx}": [ "eslint --fix --ext .js,.ts,.tsx .", @@ -47,8 +41,7 @@ }, "dependencies": { "@serverless/core": "^1.1.1", - "@serverless/tencent-apigateway": "^2.0.4", - "@serverless/tencent-scf": "^2.0.9", + "@serverless/tencent-framework": "^0.0.1", "@yugasun/python-requirements": "^0.1.2", "ext": "^1.4.0", "type": "^2.0.0" diff --git a/src/index.js b/src/index.js index c2f778a..75ccc93 100644 --- a/src/index.js +++ b/src/index.js @@ -1,7 +1,4 @@ const ensureIterable = require('type/iterable/ensure') -const ensurePlainObject = require('type/plain-object/ensure') -const ensureString = require('type/string/ensure') -const random = require('ext/string/random') const path = require('path') const { Component, utils } = require('@serverless/core') @@ -19,129 +16,47 @@ class TencentFlask extends Component { return 'http' } - /** - * prepare create function inputs - * @param {object} inputs inputs - */ - async prepareInputs(inputs = {}) { - inputs.name = - ensureString(inputs.functionName, { isOptional: true }) || - this.state.functionName || - `FlaskComponent_${random({ length: 6 })}` - inputs.codeUri = ensureString(inputs.code, { isOptional: true }) || process.cwd() - inputs.region = ensureString(inputs.region, { default: 'ap-guangzhou' }) - inputs.include = ensureIterable(inputs.include, { default: [], ensureItem: ensureString }) - inputs.exclude = ensureIterable(inputs.exclude, { default: [], ensureItem: ensureString }) - inputs.apigatewayConf = ensurePlainObject(inputs.apigatewayConf, { default: {} }) - - const shimsDir = path.join(__dirname, 'shims') - inputs.include = [ - path.join(shimsDir, 'severless_wsgi.py'), - path.join(shimsDir, 'api_service.py') - ] - inputs.exclude.push('.git/**', '.gitignore', '.serverless', '.DS_Store') - - inputs.handler = ensureString(inputs.handler, { default: DEFAULTS.handler }) - inputs.runtime = ensureString(inputs.runtime, { default: DEFAULTS.runtime }) - inputs.apigatewayConf = ensurePlainObject(inputs.apigatewayConf, { default: {} }) - - const appFile = path.join(path.resolve(inputs.codeUri), 'app.py') + async default(inputs = {}) { + const appFile = path.join(path.resolve(inputs.code), 'app.py') if (!(await utils.fileExists(appFile))) { - throw new Error(`app.py not found in ${inputs.codeUri}`) + throw new Error(`app.py not found in ${inputs.code}`) } - if (inputs.functionConf) { - inputs.timeout = inputs.functionConf.timeout ? inputs.functionConf.timeout : 3 - inputs.memorySize = inputs.functionConf.memorySize ? inputs.functionConf.memorySize : 128 - if (inputs.functionConf.environment) { - inputs.environment = inputs.functionConf.environment - } - if (inputs.functionConf.vpcConfig) { - inputs.vpcConfig = inputs.functionConf.vpcConfig - } - } - - inputs.requirements = ensurePlainObject(inputs.apigatewayConf, { default: {} }) - inputs.requirements.include = inputs.include - inputs.requirements.runtime = inputs.runtime.toLowerCase() - inputs.requirements.codeUri = inputs.codeUri - if (!inputs.requirements.dockerizePip) { - inputs.requirements.pythonBin = 'python' - } - - return inputs - } - - async default(inputs = {}) { - inputs = await this.prepareInputs(inputs) - const pyRequirements = await this.load('@yugasun/python-requirements', 'pyRequirements') const pyRequirementsOutput = await pyRequirements(inputs.requirements) + const shimsDir = path.join(__dirname, 'shims') + inputs.include = ensureIterable(inputs.include, { default: pyRequirementsOutput.include }) + inputs.include.push(path.join(shimsDir, 'severless_wsgi.py')) + inputs.include.push(path.join(shimsDir, 'api_service.py')) + inputs.exclude = ensureIterable(inputs.exclude, { default: [] }) + inputs.exclude.push('.git/**', '.gitignore', '.serverless', '.DS_Store') + inputs.handler = DEFAULTS.handler + inputs.runtime = DEFAULTS.runtime - inputs.include = pyRequirementsOutput.include - - const tencentCloudFunction = await this.load('@serverless/tencent-scf') - const tencentApiGateway = await this.load('@serverless/tencent-apigateway') - - inputs.fromClientRemark = inputs.fromClientRemark || 'tencent-flask' - const tencentCloudFunctionOutputs = await tencentCloudFunction(inputs) - const apigwParam = { - serviceName: inputs.serviceName, - description: 'Serverless Framework tencent-flask Component', - serviceId: inputs.serviceId, - region: inputs.region, - protocols: inputs.apigatewayConf.protocols || ['http'], - environment: - inputs.apigatewayConf && inputs.apigatewayConf.environment - ? inputs.apigatewayConf.environment - : 'release', - endpoints: [ - { - path: '/', - method: 'ANY', - function: { - isIntegratedResponse: true, - functionName: tencentCloudFunctionOutputs.Name - } - } - ] - } - - if (inputs.apigatewayConf && inputs.apigatewayConf.auth) { - apigwParam.endpoints[0].usagePlan = inputs.apigatewayConf.usagePlan - } - if (inputs.apigatewayConf && inputs.apigatewayConf.auth) { - apigwParam.endpoints[0].auth = inputs.apigatewayConf.auth - } - - apigwParam.fromClientRemark = inputs.fromClientRemark || 'tencent-flask' - const tencentApiGatewayOutputs = await tencentApiGateway(apigwParam) - const outputs = { - region: inputs.region, - functionName: inputs.name, - apiGatewayServiceId: tencentApiGatewayOutputs.serviceId, - url: `${this.getDefaultProtocol(tencentApiGatewayOutputs.protocols)}://${ - tencentApiGatewayOutputs.subDomain - }/${tencentApiGatewayOutputs.environment}/` - } + const Framework = await this.load('@serverless/tencent-framework') - this.state = outputs + const framworkOutpus = await Framework({ + ...inputs, + ...{ + framework: 'flask' + } + }) + this.state = framworkOutpus await this.save() - - return outputs + return framworkOutpus } async remove(inputs = {}) { - const removeInput = { - fromClientRemark: inputs.fromClientRemark || 'tencent-flask' - } - const tencentCloudFunction = await this.load('@serverless/tencent-scf') - const tencentApiGateway = await this.load('@serverless/tencent-apigateway') - - await tencentCloudFunction.remove(removeInput) - await tencentApiGateway.remove(removeInput) - + const Framework = await this.load('@serverless/tencent-framework') + await Framework.remove({ + ...inputs, + ...{ + framework: 'flask' + } + }) + this.state = {} + await this.save() return {} } } From 6aa3a5170649448bce23c2e36c91f733bab1aa87 Mon Sep 17 00:00:00 2001 From: dfounderliu Date: 2020年3月17日 12:43:33 +0800 Subject: [PATCH 4/4] update version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d474ce8..6b66340 100755 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@serverless/tencent-flask", "description": "Tencent Cloud Flask Serverless Component", - "version": "0.1.10", + "version": "1.0.0", "main": "serverless.js", "publishConfig": { "access": "public"

AltStyle によって変換されたページ (->オリジナル) /