Skip to content

Commit fa4eebd

Browse files
committed
feat: update config & support usageplan+auth
1 parent 24d26cd commit fa4eebd

File tree

5 files changed

+26
-12
lines changed

5 files changed

+26
-12
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
"commitlint": "commitlint -f HEAD@{15}",
1111
"lint": "eslint --ext .js,.ts,.tsx .",
1212
"lint:fix": "eslint --fix --ext .js,.ts,.tsx .",
13-
"prettier": "prettier --check **/*.{css,html,js,json,md,yaml,yml}",
14-
"prettier:fix": "prettier --write **/*.{css,html,js,json,md,yaml,yml}",
13+
"prettier": "prettier --check '**/*.{css,html,js,json,md,yaml,yml}'",
14+
"prettier:fix": "prettier --write '**/*.{css,html,js,json,md,yaml,yml}'",
1515
"release": "semantic-release",
1616
"release-local": "node -r dotenv/config node_modules/semantic-release/bin/semantic-release --no-ci --dry-run",
1717
"check-dependencies": "npx npm-check --skip-unused --update"

src/config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const CONFIGS = {
22
templateUrl: 'https://serverless-templates-1300862921.cos.ap-beijing.myqcloud.com/koa-demo.zip',
3-
framework: 'koa',
4-
frameworkFullname: 'Koa.js',
3+
compName: 'koa',
4+
compFullname: 'Koa.js',
55
handler: 'sl_handler.handler',
66
runtime: 'Nodejs10.15',
77
exclude: ['.git/**', '.gitignore', '.DS_Store'],

src/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"license": "MIT",
1313
"dependencies": {
1414
"download": "^8.0.0",
15-
"tencent-component-toolkit": "^1.8.3",
15+
"tencent-component-toolkit": "^1.11.2",
1616
"type": "^2.0.0"
1717
}
1818
}

src/serverless.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ class ServerlessComponent extends Component {
138138
}
139139

140140
async deploy(inputs) {
141-
console.log(`Deploying ${CONFIGS.frameworkFullname} App...`)
141+
console.log(`Deploying ${CONFIGS.compFullname} App...`)
142142

143143
const credentials = this.getCredentials()
144144

@@ -188,7 +188,7 @@ class ServerlessComponent extends Component {
188188
}
189189

190190
async remove() {
191-
console.log(`Removing ${CONFIGS.frameworkFullname} App...`)
191+
console.log(`Removing ${CONFIGS.compFullname} App...`)
192192

193193
const { state } = this
194194
const { regionList = [] } = state

src/utils.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const generateId = () =>
2222
.substring(6)
2323

2424
const getCodeZipPath = async (instance, inputs) => {
25-
console.log(`Packaging ${CONFIGS.frameworkFullname} application...`)
25+
console.log(`Packaging ${CONFIGS.compFullname} application...`)
2626

2727
// unzip source zip file
2828
let zipPath
@@ -31,7 +31,7 @@ const getCodeZipPath = async (instance, inputs) => {
3131
const downloadPath = `/tmp/${generateId()}`
3232
const filename = 'template'
3333

34-
console.log(`Installing Default ${CONFIGS.frameworkFullname} App...`)
34+
console.log(`Installing Default ${CONFIGS.compFullname} App...`)
3535
await download(CONFIGS.templateUrl, downloadPath, {
3636
filename: `${filename}.zip`
3737
})
@@ -175,7 +175,7 @@ const deleteRecord = (newRecords, historyRcords) => {
175175
const prepareInputs = async (instance, credentials, inputs = {}) => {
176176
// 对function inputs进行标准化
177177
const tempFunctionConf = inputs.functionConf ? inputs.functionConf : {}
178-
const fromClientRemark = `tencent-${CONFIGS.framework}`
178+
const fromClientRemark = `tencent-${CONFIGS.compName}`
179179
const regionList = inputs.region
180180
? typeof inputs.region == 'string'
181181
? [inputs.region]
@@ -197,7 +197,7 @@ const prepareInputs = async (instance, credentials, inputs = {}) => {
197197
name:
198198
ensureString(inputs.functionName, { isOptional: true }) ||
199199
stateFunctionName ||
200-
`${CONFIGS.framework}_component_${generateId()}`,
200+
`${CONFIGS.compName}_component_${generateId()}`,
201201
region: regionList,
202202
handler: ensureString(tempFunctionConf.handler ? tempFunctionConf.handler : inputs.handler, {
203203
default: CONFIGS.handler
@@ -254,7 +254,7 @@ const prepareInputs = async (instance, credentials, inputs = {}) => {
254254
apigatewayConf.fromClientRemark = fromClientRemark
255255
apigatewayConf.serviceName = inputs.serviceName
256256
apigatewayConf.description = `Serverless Framework Tencent-${capitalString(
257-
CONFIGS.framework
257+
CONFIGS.compName
258258
)} Component`
259259
apigatewayConf.serviceId = inputs.serviceId || stateServiceId
260260
apigatewayConf.region = functionConf.region
@@ -272,6 +272,20 @@ const prepareInputs = async (instance, credentials, inputs = {}) => {
272272
}
273273
}
274274
]
275+
if (apigatewayConf.usagePlan) {
276+
apigatewayConf.endpoints[0].usagePlan = {
277+
usagePlanId: apigatewayConf.usagePlan.usagePlanId,
278+
usagePlanName: apigatewayConf.usagePlan.usagePlanName,
279+
usagePlanDesc: apigatewayConf.usagePlan.usagePlanDesc,
280+
maxRequestNum: apigatewayConf.usagePlan.maxRequestNum
281+
}
282+
}
283+
if (apigatewayConf.auth) {
284+
apigatewayConf.endpoints[0].auth = {
285+
secretName: apigatewayConf.auth.secretName,
286+
secretIds: apigatewayConf.auth.secretIds
287+
}
288+
}
275289

276290
// 对cns inputs进行标准化
277291
const tempCnsConf = {}

0 commit comments

Comments
 (0)