Skip to content

Commit 77cc223

Browse files
Jominjap_kaiyuzeng
andauthored
feat: add listAlias/deleteAlias (#146)
* feat: add listAlias/deleteAlias * feat: add createAlias/updateAlias/listAlias/deleteAlias Co-authored-by: p_kaiyuzeng <p_kaiyuzeng@tencent.com>
1 parent 2188784 commit 77cc223

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

src/modules/scf/apis.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ const ACTIONS = [
99
'CreateTrigger',
1010
'DeleteTrigger',
1111
'PublishVersion',
12+
'ListAliases',
1213
'CreateAlias',
1314
'UpdateAlias',
15+
'DeleteAlias',
1416
'GetAlias',
1517
'Invoke',
1618
];

src/modules/scf/index.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,44 @@ class Scf {
298298
return Response;
299299
}
300300

301+
async createAlias(inputs) {
302+
const publishInputs = {
303+
Action: 'CreateAlias',
304+
FunctionName: inputs.functionName,
305+
FunctionVersion: inputs.functionVersion,
306+
Name: inputs.aliasName,
307+
Namespace: inputs.namespace || 'default',
308+
RoutingConfig: {
309+
AdditionalVersionWeights: [{ Version: inputs.lastVersion, Weight: inputs.traffic }],
310+
},
311+
Description: inputs.description || 'Published by Serverless Component',
312+
};
313+
const Response = await this.request(publishInputs);
314+
return Response;
315+
}
316+
317+
async updateAlias(inputs) {
318+
console.log(
319+
`Config function ${inputs.functionName} traffic ${inputs.traffic} for version ${inputs.lastVersion}`,
320+
);
321+
const publishInputs = {
322+
Action: 'UpdateAlias',
323+
FunctionName: inputs.functionName,
324+
FunctionVersion: inputs.functionVersion || '$LATEST',
325+
Name: inputs.aliasName || '$DEFAULT',
326+
Namespace: inputs.namespace || 'default',
327+
RoutingConfig: {
328+
AdditionalVersionWeights: [{ Version: inputs.lastVersion, Weight: inputs.traffic }],
329+
},
330+
Description: inputs.description || 'Configured by Serverless Component',
331+
};
332+
const Response = await this.request(publishInputs);
333+
console.log(
334+
`Config function ${inputs.functionName} traffic ${inputs.traffic} for version ${inputs.lastVersion} success`,
335+
);
336+
return Response;
337+
}
338+
301339
async getAlias(inputs) {
302340
const publishInputs = {
303341
Action: 'GetAlias',
@@ -309,6 +347,28 @@ class Scf {
309347
return Response;
310348
}
311349

350+
async deleteAlias(inputs) {
351+
const publishInputs = {
352+
Action: 'DeleteAlias',
353+
FunctionName: inputs.functionName,
354+
Name: inputs.aliasName || '$DEFAULT',
355+
Namespace: inputs.namespace || 'default',
356+
};
357+
const Response = await this.request(publishInputs);
358+
return Response;
359+
}
360+
361+
async listAlias(inputs) {
362+
const publishInputs = {
363+
Action: 'ListAliases',
364+
FunctionName: inputs.functionName,
365+
Namespace: inputs.namespace || 'default',
366+
FunctionVersion: inputs.functionVersion,
367+
};
368+
const Response = await this.request(publishInputs);
369+
return Response;
370+
}
371+
312372
/**
313373
* check whether function status is operational, mostly for asynchronous operation
314374
* @param {string} namespace

0 commit comments

Comments
 (0)