@geek-fun/serverlessinsight 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/package.json +1 -1
- package/dist/src/common/iacHelper.js +9 -5
- package/dist/src/stack/iacStack.js +22 -22
- package/package.json +1 -1
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geek-fun/serverlessinsight",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"description": "Full life cycle cross providers serverless application management for your fast-growing business.",
|
|
5
5
|
"homepage": "https://serverlessinsight.geekfun.club",
|
|
6
6
|
"main": "dist/src/index.js",
|
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.
|
|
29
|
+
exports.replaceReference = exports.resolveCode = void 0;
|
|
30
30
|
const node_path_1 = __importDefault(require("node:path"));
|
|
31
31
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
32
32
|
const ros = __importStar(require("@alicloud/ros-cdk-core"));
|
|
@@ -36,18 +36,22 @@ const resolveCode = (location) => {
|
|
|
36
36
|
return fileContent.toString('base64');
|
|
37
37
|
};
|
|
38
38
|
exports.resolveCode = resolveCode;
|
|
39
|
-
const
|
|
39
|
+
const replaceReference = (value, stage) => {
|
|
40
40
|
if (typeof value === 'string') {
|
|
41
41
|
const matchVar = value.match(/^\$\{vars\.(\w+)}$/);
|
|
42
42
|
const containsVar = value.match(/\$\{vars\.(\w+)}/);
|
|
43
43
|
const matchMap = value.match(/^\$\{stages\.(\w+)}$/);
|
|
44
44
|
const containsMap = value.match(/\$\{stages\.(\w+)}/);
|
|
45
|
+
const matchFn = value.match(/^\$\{functions\.(\w+(\.\w+)?)}$/);
|
|
45
46
|
if (matchVar?.length) {
|
|
46
47
|
return ros.Fn.ref(matchVar[1]);
|
|
47
48
|
}
|
|
48
49
|
if (matchMap?.length) {
|
|
49
50
|
return ros.Fn.findInMap('stages', '', matchMap[1]);
|
|
50
51
|
}
|
|
52
|
+
if (matchFn?.length) {
|
|
53
|
+
return ros.Fn.getAtt(matchFn[1], 'FunctionName');
|
|
54
|
+
}
|
|
51
55
|
if (containsMap?.length && containsVar?.length) {
|
|
52
56
|
return ros.Fn.sub(value.replace(/\$\{stages\.(\w+)}/g, '${$1}').replace(/\$\{vars\.(\w+)}/g, '${$1}'));
|
|
53
57
|
}
|
|
@@ -60,11 +64,11 @@ const replaceVars = (value, stage) => {
|
|
|
60
64
|
return value;
|
|
61
65
|
}
|
|
62
66
|
if (Array.isArray(value)) {
|
|
63
|
-
return value.map((item) => (0, exports.
|
|
67
|
+
return value.map((item) => (0, exports.replaceReference)(item, stage));
|
|
64
68
|
}
|
|
65
69
|
if (typeof value === 'object' && value !== null) {
|
|
66
|
-
return Object.fromEntries(Object.entries(value).map(([key, val]) => [key, (0, exports.
|
|
70
|
+
return Object.fromEntries(Object.entries(value).map(([key, val]) => [key, (0, exports.replaceReference)(val, stage)]));
|
|
67
71
|
}
|
|
68
72
|
return value;
|
|
69
73
|
};
|
|
70
|
-
exports.
|
|
74
|
+
exports.replaceReference = replaceReference;
|
|
@@ -36,7 +36,7 @@ class IacStack extends ros.Stack {
|
|
|
36
36
|
super(scope, iac.service, {
|
|
37
37
|
stackName: context.stackName,
|
|
38
38
|
tags: iac.tags.reduce((acc, tag) => {
|
|
39
|
-
acc[tag.key] = (0, common_1.
|
|
39
|
+
acc[tag.key] = (0, common_1.replaceReference)(tag.value, context.stage);
|
|
40
40
|
return acc;
|
|
41
41
|
}, {}),
|
|
42
42
|
});
|
|
@@ -46,16 +46,16 @@ class IacStack extends ros.Stack {
|
|
|
46
46
|
defaultValue: value,
|
|
47
47
|
}));
|
|
48
48
|
// Define Mappings
|
|
49
|
-
new ros.RosMapping(this, 'stages', { mapping: (0, common_1.
|
|
50
|
-
new ros.RosInfo(this, ros.RosInfo.description, (0, common_1.
|
|
49
|
+
new ros.RosMapping(this, 'stages', { mapping: (0, common_1.replaceReference)(iac.stages, context.stage) });
|
|
50
|
+
new ros.RosInfo(this, ros.RosInfo.description, (0, common_1.replaceReference)(`${iac.service} stack`, context.stage));
|
|
51
51
|
iac.functions.forEach((fnc) => {
|
|
52
52
|
new fc.RosFunction(this, fnc.key, {
|
|
53
|
-
functionName: (0, common_1.
|
|
54
|
-
handler: (0, common_1.
|
|
55
|
-
runtime: (0, common_1.
|
|
56
|
-
memorySize: (0, common_1.
|
|
57
|
-
timeout: (0, common_1.
|
|
58
|
-
environmentVariables: (0, common_1.
|
|
53
|
+
functionName: (0, common_1.replaceReference)(fnc.name, context.stage),
|
|
54
|
+
handler: (0, common_1.replaceReference)(fnc.handler, context.stage),
|
|
55
|
+
runtime: (0, common_1.replaceReference)(fnc.runtime, context.stage),
|
|
56
|
+
memorySize: (0, common_1.replaceReference)(fnc.memory, context.stage),
|
|
57
|
+
timeout: (0, common_1.replaceReference)(fnc.timeout, context.stage),
|
|
58
|
+
environmentVariables: (0, common_1.replaceReference)(fnc.environment, context.stage),
|
|
59
59
|
code: {
|
|
60
60
|
zipFile: (0, common_1.resolveCode)(fnc.code),
|
|
61
61
|
},
|
|
@@ -63,9 +63,9 @@ class IacStack extends ros.Stack {
|
|
|
63
63
|
});
|
|
64
64
|
const apiGateway = iac.events?.filter((event) => event.type === types_1.EventTypes.API_GATEWAY);
|
|
65
65
|
if (apiGateway?.length) {
|
|
66
|
-
const gatewayAccessRole = new ram.RosRole(this, (0, common_1.
|
|
67
|
-
roleName: (0, common_1.
|
|
68
|
-
description: (0, common_1.
|
|
66
|
+
const gatewayAccessRole = new ram.RosRole(this, (0, common_1.replaceReference)(`${iac.service}_role`, context.stage), {
|
|
67
|
+
roleName: (0, common_1.replaceReference)(`${iac.service}-gateway-access-role`, context.stage),
|
|
68
|
+
description: (0, common_1.replaceReference)(`${iac.service} role`, context.stage),
|
|
69
69
|
assumeRolePolicyDocument: {
|
|
70
70
|
version: '1',
|
|
71
71
|
statement: [
|
|
@@ -80,7 +80,7 @@ class IacStack extends ros.Stack {
|
|
|
80
80
|
},
|
|
81
81
|
policies: [
|
|
82
82
|
{
|
|
83
|
-
policyName: (0, common_1.
|
|
83
|
+
policyName: (0, common_1.replaceReference)(`${iac.service}-policy`, context.stage),
|
|
84
84
|
policyDocument: {
|
|
85
85
|
version: '1',
|
|
86
86
|
statement: [
|
|
@@ -95,9 +95,9 @@ class IacStack extends ros.Stack {
|
|
|
95
95
|
},
|
|
96
96
|
],
|
|
97
97
|
}, true);
|
|
98
|
-
const apiGatewayGroup = new agw.RosGroup(this, (0, common_1.
|
|
99
|
-
groupName: (0, common_1.
|
|
100
|
-
tags: (0, common_1.
|
|
98
|
+
const apiGatewayGroup = new agw.RosGroup(this, (0, common_1.replaceReference)(`${iac.service}_apigroup`, context.stage), {
|
|
99
|
+
groupName: (0, common_1.replaceReference)(`${iac.service}_apigroup`, context.stage),
|
|
100
|
+
tags: (0, common_1.replaceReference)(iac.tags, context.stage),
|
|
101
101
|
}, true);
|
|
102
102
|
// new agw.RosCustomDomain(
|
|
103
103
|
// this,
|
|
@@ -114,28 +114,28 @@ class IacStack extends ros.Stack {
|
|
|
114
114
|
apiGateway.forEach((event) => {
|
|
115
115
|
event.triggers.forEach((trigger) => {
|
|
116
116
|
const key = `${trigger.method}_${trigger.path}`.toLowerCase().replace(/\//g, '_');
|
|
117
|
-
const api = new agw.RosApi(this, (0, common_1.
|
|
118
|
-
apiName: (0, common_1.
|
|
117
|
+
const api = new agw.RosApi(this, (0, common_1.replaceReference)(`${event.key}_api_${key}`, context.stage), {
|
|
118
|
+
apiName: (0, common_1.replaceReference)(`${event.name}_api_${key}`, context.stage),
|
|
119
119
|
groupId: apiGatewayGroup.attrGroupId,
|
|
120
120
|
visibility: 'PRIVATE',
|
|
121
121
|
requestConfig: {
|
|
122
122
|
requestProtocol: 'HTTP',
|
|
123
|
-
requestHttpMethod: (0, common_1.
|
|
124
|
-
requestPath: (0, common_1.
|
|
123
|
+
requestHttpMethod: (0, common_1.replaceReference)(trigger.method, context.stage),
|
|
124
|
+
requestPath: (0, common_1.replaceReference)(trigger.path, context.stage),
|
|
125
125
|
requestMode: 'PASSTHROUGH',
|
|
126
126
|
},
|
|
127
127
|
serviceConfig: {
|
|
128
128
|
serviceProtocol: 'FunctionCompute',
|
|
129
129
|
functionComputeConfig: {
|
|
130
130
|
fcRegionId: context.region,
|
|
131
|
-
functionName: trigger.backend,
|
|
131
|
+
functionName: (0, common_1.replaceReference)(trigger.backend, trigger.backend),
|
|
132
132
|
roleArn: gatewayAccessRole.attrArn,
|
|
133
133
|
fcVersion: '3.0',
|
|
134
134
|
},
|
|
135
135
|
},
|
|
136
136
|
resultSample: 'ServerlessInsight resultSample',
|
|
137
137
|
resultType: 'JSON',
|
|
138
|
-
tags: (0, common_1.
|
|
138
|
+
tags: (0, common_1.replaceReference)(iac.tags, context.stage),
|
|
139
139
|
}, true);
|
|
140
140
|
api.addDependsOn(apiGatewayGroup);
|
|
141
141
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geek-fun/serverlessinsight",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"description": "Full life cycle cross providers serverless application management for your fast-growing business.",
|
|
5
5
|
"homepage": "https://serverlessinsight.geekfun.club",
|
|
6
6
|
"main": "dist/src/index.js",
|