Skip to content

Commit 00a36a9

Browse files
committed
feat: add layer module
1 parent ef0a06f commit 00a36a9

38 files changed

+265
-37
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@
7070
"semantic-release": "^17.0.4"
7171
},
7272
"dependencies": {
73-
"@tencent-sdk/capi": "0.2.15",
73+
"@tencent-sdk/capi": "^0.2.17",
7474
"@ygkit/request": "^0.0.6",
7575
"klaw-sync": "^6.0.0",
7676
"moment": "^2.25.3",
77-
"tencent-cloud-sdk": "^0.1.5"
77+
"tencent-cloud-sdk": "^0.1.6"
7878
}
7979
}

src/index.js

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
const Apigw = require('./baas/apigw');
2-
const Cdn = require('./baas/cdn');
3-
const Cns = require('./baas/cns');
4-
const Cos = require('./baas/cos');
5-
const Domain = require('./baas/domain');
6-
const MultiApigw = require('./baas/multi-apigw');
7-
const MultiScf = require('./baas/multi-scf');
8-
const Scf = require('./baas/scf');
9-
const Tag = require('./baas/tag');
10-
const Postgresql = require('./baas/postgresql');
11-
const Vpc = require('./baas/vpc');
12-
const Cam = require('./baas/cam');
13-
const Metrics = require('./baas/metrics');
1+
const Apigw = require('./modules/apigw');
2+
const Cdn = require('./modules/cdn');
3+
const Cns = require('./modules/cns');
4+
const Cos = require('./modules/cos');
5+
const Domain = require('./modules/domain');
6+
const MultiApigw = require('./modules/multi-apigw');
7+
const MultiScf = require('./modules/multi-scf');
8+
const Scf = require('./modules/scf');
9+
const Tag = require('./modules/tag');
10+
const Postgresql = require('./modules/postgresql');
11+
const Vpc = require('./modules/vpc');
12+
const Cam = require('./modules/cam');
13+
const Metrics = require('./modules/metrics');
14+
const Layer = require('./modules/layer');
15+
1416
module.exports = {
1517
Apigw,
1618
Cdn,
@@ -25,4 +27,5 @@ module.exports = {
2527
Vpc,
2628
Cam,
2729
Metrics,
30+
Layer,
2831
};
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/baas/cdn/apis.js renamed to src/modules/cdn/apis.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function apiFactory(actions) {
4545
}
4646
return Response;
4747
} catch (e) {
48-
throw new TypeError(`API_CDN_${action}`, JSON.stringify(e), e.stack);
48+
throw new TypeError(`API_CDN_${action}`, e.message, e.stack);
4949
}
5050
};
5151
});
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/baas/cns/index.js renamed to src/modules/cns/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ class Cns {
133133
throw new TypeError(`API_CNS_RecordModify`, JSON.stringify(modifyResult));
134134
}
135135
} catch (e) {
136-
throw new TypeError(`API_CNS_RecordModify`, JSON.stringify(e), e.stack);
136+
throw new TypeError(`API_CNS_RecordModify`, e.message, e.stack);
137137
}
138138
console.log(`Modified (recordId is ${tempInputs.recordId}) `);
139139
} else {
@@ -177,7 +177,7 @@ class Cns {
177177
throw new TypeError(`API_CNS_RecordStatus`, JSON.stringify(statusResult));
178178
}
179179
} catch (e) {
180-
throw new TypeError(`API_CNS_RecordStatus`, JSON.stringify(e), e.stack);
180+
throw new TypeError(`API_CNS_RecordStatus`, e.message, e.stack);
181181
}
182182
console.log(`Modified status to ${tempInputs.status} `);
183183
}
File renamed without changes.

src/baas/cos/index.js renamed to src/modules/cos/index.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ class Cos {
147147
try {
148148
await setTagsHandler(setTagsParams);
149149
} catch (e) {
150-
throw new TypeError(`API_COS_putBucketTagging`, JSON.stringify(e), e.stack);
150+
throw new TypeError(`API_COS_putBucketTagging`, e.message, e.stack);
151151
}
152152
}
153153

@@ -162,7 +162,7 @@ class Cos {
162162
Region: this.region,
163163
});
164164
} catch (e) {
165-
throw new TypeError(`API_COS_deleteBucketTagging`, JSON.stringify(e), e.stack);
165+
throw new TypeError(`API_COS_deleteBucketTagging`, e.message, e.stack);
166166
}
167167
}
168168

@@ -197,7 +197,7 @@ class Cos {
197197
try {
198198
await setCorsHandler(setCorsParams);
199199
} catch (e) {
200-
throw new TypeError(`API_COS_putBucketCors`, JSON.stringify(e), e.stack);
200+
throw new TypeError(`API_COS_putBucketCors`, e.message, e.stack);
201201
}
202202
}
203203

@@ -210,7 +210,7 @@ class Cos {
210210
Region: this.region,
211211
});
212212
} catch (e) {
213-
throw new TypeError(`API_COS_deleteBucketCors`, JSON.stringify(e), e.stack);
213+
throw new TypeError(`API_COS_deleteBucketCors`, e.message, e.stack);
214214
}
215215
}
216216

@@ -266,7 +266,7 @@ class Cos {
266266
try {
267267
await setLifecycleHandler(JSON.parse(JSON.stringify(setLifecycleParams)));
268268
} catch (e) {
269-
throw new TypeError(`API_COS_putBucketLifecycle`, JSON.stringify(e), e.stack);
269+
throw new TypeError(`API_COS_putBucketLifecycle`, e.message, e.stack);
270270
}
271271
}
272272

@@ -281,7 +281,7 @@ class Cos {
281281
Region: this.region,
282282
});
283283
} catch (e) {
284-
throw new TypeError(`API_COS_deleteBucketLifecycle`, JSON.stringify(e), e.stack);
284+
throw new TypeError(`API_COS_deleteBucketLifecycle`, e.message, e.stack);
285285
}
286286
}
287287

@@ -301,7 +301,7 @@ class Cos {
301301
try {
302302
await setVersioningHandler(setVersioningParams);
303303
} catch (e) {
304-
throw new TypeError(`API_COS_putBucketVersioning`, JSON.stringify(e), e.stack);
304+
throw new TypeError(`API_COS_putBucketVersioning`, e.message, e.stack);
305305
}
306306
}
307307

@@ -332,7 +332,7 @@ class Cos {
332332
try {
333333
await setWebsiteHandler(staticHostParams);
334334
} catch (e) {
335-
throw new TypeError(`API_COS_putBucketWebsite`, JSON.stringify(e), e.stack);
335+
throw new TypeError(`API_COS_putBucketWebsite`, e.message, e.stack);
336336
}
337337
}
338338

@@ -345,7 +345,7 @@ class Cos {
345345
});
346346
return res;
347347
} catch (e) {
348-
throw new TypeError(`API_COS_getBucket`, JSON.stringify(e), e.stack);
348+
throw new TypeError(`API_COS_getBucket`, e.message, e.stack);
349349
}
350350
}
351351

@@ -365,7 +365,7 @@ class Cos {
365365
});
366366
return Url;
367367
} catch (e) {
368-
throw new TypeError(`API_COS_getObjectUrl`, JSON.stringify(e), e.stack);
368+
throw new TypeError(`API_COS_getObjectUrl`, e.message, e.stack);
369369
}
370370
}
371371

@@ -421,7 +421,7 @@ class Cos {
421421
try {
422422
await Promise.all(uploadItems);
423423
} catch (e) {
424-
throw new TypeError(`API_COS_putObject`, JSON.stringify(e), e.stack);
424+
throw new TypeError(`API_COS_putObject`, e.message, e.stack);
425425
}
426426
} else if (inputs.file && (await fs.existsSync(inputs.file))) {
427427
const itemParams = {
@@ -434,7 +434,7 @@ class Cos {
434434
try {
435435
await handler(itemParams);
436436
} catch (e) {
437-
throw new TypeError(`API_COS_putObject`, JSON.stringify(e), e.stack);
437+
throw new TypeError(`API_COS_putObject`, e.message, e.stack);
438438
}
439439
}
440440
}
@@ -472,7 +472,7 @@ class Cos {
472472
try {
473473
await fs.writeFileSync(envFilePath, script);
474474
} catch (e) {
475-
throw new TypeError(`DEPLOY_COS_CREATE_ENV_FILE`, JSON.stringify(e), e.stack);
475+
throw new TypeError(`DEPLOY_COS_CREATE_ENV_FILE`, e.message, e.stack);
476476
}
477477
}
478478

@@ -592,7 +592,7 @@ class Cos {
592592
if (e.error && e.error.Code && e.error.Code === 'NoSuchBucket') {
593593
console.log(`Bucket ${inputs.bucket} not exist`);
594594
} else {
595-
throw new TypeError(`DEPLOY_COS_EXEC_HOOK`, JSON.stringify(e), e.stack);
595+
throw new TypeError(`DEPLOY_COS_EXEC_HOOK`, e.message, e.stack);
596596
}
597597
}
598598
}
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/modules/layer/apis/apis.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
const { TypeError } = require('../../../utils/error');
2+
3+
function apiFactory(actions) {
4+
const apis = {};
5+
actions.forEach((action) => {
6+
apis[action] = async (capi, inputs) => {
7+
const data = {
8+
Version: '2018-04-16',
9+
Action: action,
10+
// RequestClient: 'ServerlessComponent',
11+
...inputs,
12+
};
13+
if (capi.options.Token) {
14+
data.Token = capi.options.Token;
15+
}
16+
try {
17+
const { Response } = await capi.request(
18+
data,
19+
// this is preset options for capiateway
20+
{
21+
debug: false,
22+
ServiceType: 'scf',
23+
// baseHost: 'tencentcloudapi.com'
24+
host: 'scf.tencentcloudapi.com',
25+
},
26+
true,
27+
);
28+
29+
if (Response && Response.Error && Response.Error.Code) {
30+
throw new TypeError(
31+
`API_LAYER_${action}`,
32+
Response.Error.Message,
33+
null,
34+
Response.RequestId,
35+
);
36+
}
37+
return Response;
38+
} catch (e) {
39+
throw new TypeError(`API_LAYER_${action}`, e.message, e.stack);
40+
}
41+
};
42+
});
43+
44+
return apis;
45+
}
46+
47+
const ACTIONS = [
48+
'PublishLayerVersion',
49+
'DeleteLayerVersion',
50+
'GetLayerVersion',
51+
'ListLayers',
52+
'ListLayerVersions',
53+
];
54+
const APIS = apiFactory(ACTIONS);
55+
56+
module.exports = APIS;

src/modules/layer/apis/index.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
const {
2+
PublishLayerVersion,
3+
DeleteLayerVersion,
4+
GetLayerVersion,
5+
ListLayerVersions,
6+
} = require('./apis');
7+
8+
const utils = {
9+
/**
10+
* get target version layer detail
11+
* @param {object} capi capi instance
12+
* @param {string} LayerName
13+
* @param {string} LayerVersion
14+
*/
15+
async getLayerDetail(capi, LayerName, LayerVersion) {
16+
// get instance detail
17+
try {
18+
const res = await GetLayerVersion(capi, {
19+
LayerName,
20+
LayerVersion,
21+
});
22+
return res;
23+
} catch (e) {
24+
return {};
25+
}
26+
},
27+
28+
/**
29+
* get layer versiosn
30+
* @param {object} capi capi instance
31+
* @param {string} LayerName
32+
*/
33+
async getLayerVersions(capi, LayerName) {
34+
// get instance detail
35+
const res = await ListLayerVersions(capi, {
36+
LayerName,
37+
});
38+
if (res.LayerVersions) {
39+
const { LayerVersions } = res;
40+
return LayerVersions;
41+
}
42+
return null;
43+
},
44+
45+
/**
46+
*
47+
* @param {object} capi capi instance
48+
* @param {object} params publish layer parameters
49+
*/
50+
async publishLayer(capi, params) {
51+
const res = await PublishLayerVersion(capi, {
52+
LayerName: params.LayerName,
53+
CompatibleRuntimes: params.CompatibleRuntimes,
54+
Content: params.Content,
55+
Description: params.Description,
56+
LicenseInfo: params.licenseInfo || '',
57+
});
58+
return res.LayerVersion ? res.LayerVersion : null;
59+
},
60+
61+
/**
62+
* delete layer version
63+
* @param {object} capi capi instance
64+
* @param {*} LayerName layer name
65+
* @param {*} LayerVersion layer version
66+
*/
67+
async deleteLayerVersion(capi, LayerName, LayerVersion) {
68+
await DeleteLayerVersion(capi, {
69+
LayerName,
70+
LayerVersion,
71+
});
72+
},
73+
};
74+
75+
module.exports = utils;

0 commit comments

Comments
 (0)