Skip to content

Commit

Permalink
fix: optimize apigw trigger remove (#44)
Browse files Browse the repository at this point in the history
* fix: optimize apigw trigger remove

* test: update component version
  • Loading branch information
yugasun authored Nov 24, 2020
1 parent 83630fa commit 639a42b
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 11 deletions.
1 change: 0 additions & 1 deletion docs/configure.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ inputs:
usagePlanDesc: sls create
maxRequestNum: 1000
auth:
serviceTimeout: 15
secretName: secret
secretIds:
- xxx
Expand Down
5 changes: 4 additions & 1 deletion example/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ component: scf
name: scfdemo

inputs:
src: ./src
src:
src: ./src
exclude:
- .env
# 此处注释部分将自动使用默认值
# region: ap-guangzhou
# runtime: Nodejs10.15
Expand Down
2 changes: 1 addition & 1 deletion serverless.component.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: scf
version: 0.1.13
version: 0.1.14
author: Tencent Cloud, Inc.
org: Tencent Cloud, Inc.
description: Deploy a serverless cloud function on Tencent Cloud.
Expand Down
2 changes: 1 addition & 1 deletion src/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"dependencies": {
"download": "^8.0.0",
"tencent-component-toolkit": "^1.18.6",
"tencent-component-toolkit": "^1.18.7",
"type": "^2.0.0"
}
}
2 changes: 1 addition & 1 deletion src/serverless.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class ServerlessComponent extends Component {
const stateApigw = {}
scfOutput.Triggers.forEach((trigger) => {
if (trigger.serviceId) {
stateApigw[trigger.serviceName] = trigger.serviceId
stateApigw[trigger.serviceName] = trigger
trigger.apiList.forEach((endpoint) => {
if (getType(trigger.subDomain) === 'Array') {
trigger.subDomain.forEach((item) => {
Expand Down
21 changes: 16 additions & 5 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,18 +180,22 @@ const prepareInputs = async (instance, credentials, appId, inputs) => {
`API Gateway name must be unique`
)
} else {
currentEvent.parameters.serviceName =
const serviceName =
currentEvent.parameters.serviceName ||
currentEvent.name ||
getDefaultServiceName(instance)

currentEvent.parameters.serviceName = serviceName
currentEvent.parameters.description =
currentEvent.parameters.description || getDefaultServiceDescription(instance)
currentEvent.name = currentEvent.name || getDefaultTriggerName(eventType, instance)
if (stateApigw && stateApigw[currentEvent.parameters.serviceName]) {
if (stateApigw && stateApigw[serviceName]) {
currentEvent.parameters.oldState = stateApigw[serviceName]
currentEvent.parameters.serviceId =
currentEvent.parameters.serviceId || stateApigw[currentEvent.parameters.serviceName]
currentEvent.parameters.serviceId || stateApigw[serviceName].serviceId
currentEvent.parameters.created = stateApigw[serviceName].created
}
apigwName.push(currentEvent.parameters.serviceName)
apigwName.push(serviceName)
}
existApigwTrigger = true
} else {
Expand All @@ -205,8 +209,15 @@ const prepareInputs = async (instance, credentials, appId, inputs) => {
if (inputs.autoCreateApi && !existApigwTrigger) {
triggers.apigw = []
const { defaultApigw } = CONFIGS
defaultApigw.parameters.serviceName = getDefaultServiceName(instance)
const serviceName = getDefaultServiceName(instance)
defaultApigw.parameters.serviceName = serviceName
defaultApigw.parameters.description = getDefaultServiceDescription(instance)
if (stateApigw && stateApigw[serviceName]) {
defaultApigw.parameters.oldState = stateApigw[serviceName]
defaultApigw.parameters.serviceId =
defaultApigw.parameters.serviceId || stateApigw[serviceName].serviceId
defaultApigw.parameters.created = stateApigw[serviceName].created
}
inputs.events.push({
apigw: defaultApigw
})
Expand Down
2 changes: 1 addition & 1 deletion tests/integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jest.setTimeout(600000)
const instanceYaml = {
org: 'orgDemo',
app: 'appDemo',
component: 'scf',
component: 'scf@dev',
name: `scf-integration-tests-${generateId()}`,
stage: 'dev',
inputs: {
Expand Down

0 comments on commit 639a42b

Please sign in to comment.