Skip to content

Commit b067a14

Browse files
committed
feat: update config and support usageplan+auth
1 parent d0466ee commit b067a14

File tree

4 files changed

+21
-11
lines changed

4 files changed

+21
-11
lines changed

src/config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
const CONFIGS = {
22
templateUrl:
33
'https://serverless-templates-1300862921.cos.ap-beijing.myqcloud.com/express-demo.zip',
4-
framework: 'express',
5-
frameworkFullname: 'Express.js',
4+
compName: 'express',
5+
compFullname: 'Express.js',
66
handler: 'sl_handler.handler',
77
runtime: 'Nodejs10.15',
88
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.10.1",
15+
"tencent-component-toolkit": "^1.11.2",
1616
"type": "^2.0.0"
1717
}
1818
}

src/serverless.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ class ServerlessComponent extends Component {
152152
}
153153

154154
async deploy(inputs) {
155-
console.log(`Deploying ${CONFIGS.frameworkFullname} App...`)
155+
console.log(`Deploying ${CONFIGS.compFullname} App...`)
156156

157157
const credentials = this.getCredentials()
158158

@@ -202,7 +202,7 @@ class ServerlessComponent extends Component {
202202
}
203203

204204
async remove() {
205-
console.log(`Removing ${CONFIGS.frameworkFullname} App...`)
205+
console.log(`Removing ${CONFIGS.compFullname} App...`)
206206

207207
const { state } = this
208208
const { regionList = [] } = state
@@ -247,7 +247,7 @@ class ServerlessComponent extends Component {
247247
}
248248

249249
async metrics(inputs = {}) {
250-
console.log(`Get ${CONFIGS.frameworkFullname} Metrics Datas...`)
250+
console.log(`Get ${CONFIGS.compFullname} Metrics Datas...`)
251251
if (!inputs.rangeStart || !inputs.rangeEnd) {
252252
throw new TypeError('PARAMETER_METRICS', 'rangeStart and rangeEnd are require inputs')
253253
}

src/utils.js

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

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

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

35-
console.log(`Installing Default ${CONFIGS.frameworkFullname} App...`)
35+
console.log(`Installing Default ${CONFIGS.compFullname} App...`)
3636
try {
3737
await download(CONFIGS.templateUrl, downloadPath, {
3838
filename: `${filename}.zip`
@@ -180,7 +180,7 @@ const deleteRecord = (newRecords, historyRcords) => {
180180
const prepareInputs = async (instance, credentials, inputs = {}) => {
181181
// 对function inputs进行标准化
182182
const tempFunctionConf = inputs.functionConf ? inputs.functionConf : {}
183-
const fromClientRemark = `tencent-${CONFIGS.framework}`
183+
const fromClientRemark = `tencent-${CONFIGS.compName}`
184184
const regionList = inputs.region
185185
? typeof inputs.region == 'string'
186186
? [inputs.region]
@@ -202,7 +202,7 @@ const prepareInputs = async (instance, credentials, inputs = {}) => {
202202
name:
203203
ensureString(inputs.functionName, { isOptional: true }) ||
204204
stateFunctionName ||
205-
`${CONFIGS.framework}_component_${generateId()}`,
205+
`${CONFIGS.compName}_component_${generateId()}`,
206206
region: regionList,
207207
role: ensureString(tempFunctionConf.role ? tempFunctionConf.role : inputs.role, {
208208
default: ''
@@ -261,7 +261,7 @@ const prepareInputs = async (instance, credentials, inputs = {}) => {
261261
apigatewayConf.fromClientRemark = fromClientRemark
262262
apigatewayConf.serviceName = inputs.serviceName
263263
apigatewayConf.description = `Serverless Framework Tencent-${capitalString(
264-
CONFIGS.framework
264+
CONFIGS.compName
265265
)} Component`
266266
apigatewayConf.serviceId = inputs.serviceId || stateServiceId
267267
apigatewayConf.region = functionConf.region
@@ -277,6 +277,16 @@ const prepareInputs = async (instance, credentials, inputs = {}) => {
277277
isIntegratedResponse: apigatewayConf.isIntegratedResponse === false ? false : true,
278278
functionName: functionConf.name,
279279
functionNamespace: functionConf.namespace
280+
},
281+
usagePlan: {
282+
usagePlanId: apigatewayConf.usagePlan && apigatewayConf.usagePlan.usagePlanId,
283+
usagePlanName: apigatewayConf.usagePlan && apigatewayConf.usagePlan.usagePlanName,
284+
usagePlanDesc: apigatewayConf.usagePlan && apigatewayConf.usagePlan.usagePlanDesc,
285+
maxRequestNum: apigatewayConf.usagePlan && apigatewayConf.usagePlan.maxRequestNum
286+
},
287+
auth: {
288+
secretName: apigatewayConf.auth && apigatewayConf.auth.secretName,
289+
secretIds: apigatewayConf.auth && apigatewayConf.auth.secretIds
280290
}
281291
}
282292
]

0 commit comments

Comments
 (0)