@geek-fun/serverlessinsight 0.0.2 → 0.0.3
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geek-fun/serverlessinsight",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
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",
|
|
@@ -50,8 +50,10 @@
|
|
|
50
50
|
],
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"@alicloud/openapi-client": "^0.4.11",
|
|
53
|
+
"@alicloud/ros-cdk-apigateway": "^1.2.0",
|
|
53
54
|
"@alicloud/ros-cdk-core": "^1.2.0",
|
|
54
55
|
"@alicloud/ros-cdk-fc": "^1.2.0",
|
|
56
|
+
"@alicloud/ros-cdk-ram": "^1.2.0",
|
|
55
57
|
"@alicloud/ros20190910": "^3.4.3",
|
|
56
58
|
"ajv": "^8.17.1",
|
|
57
59
|
"chalk": "^4.1.2",
|
|
@@ -54,15 +54,17 @@ const createStack = async (stackName, templateBody, context) => {
|
|
|
54
54
|
console.log(`创建中,资源栈ID:${response.body?.stackId}`);
|
|
55
55
|
return response.body?.stackId;
|
|
56
56
|
};
|
|
57
|
-
const updateStack = async (
|
|
57
|
+
const updateStack = async (stackId, templateBody, context) => {
|
|
58
58
|
const parameters = context.parameters?.map((parameter) => new ros20190910_1.CreateStackRequestParameters({
|
|
59
59
|
parameterKey: tea_util_1.default.assertAsString(parameter.key),
|
|
60
60
|
parameterValue: tea_util_1.default.assertAsString(parameter.value),
|
|
61
61
|
}));
|
|
62
|
-
const createStackRequest = new ros20190910_1.
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
const createStackRequest = new ros20190910_1.UpdateStackRequest({
|
|
63
|
+
regionId: context.region,
|
|
64
|
+
stackId,
|
|
65
|
+
templateBody: JSON.stringify(templateBody),
|
|
65
66
|
parameters,
|
|
67
|
+
tags: context.tags?.map((tag) => new ros20190910_1.CreateStackRequestTags(tag)),
|
|
66
68
|
});
|
|
67
69
|
const response = await client.updateStack(createStackRequest);
|
|
68
70
|
console.log(`更新中,资源栈ID:${response.body?.stackId}`);
|
|
@@ -91,7 +93,7 @@ const rosStackDeploy = async (stackName, templateBody, context) => {
|
|
|
91
93
|
throw new Error(`fail to update stack, because stack status is ${stackStatus}`);
|
|
92
94
|
}
|
|
93
95
|
printer_1.printer.info(`Update stack: ${stackName} deploying... `);
|
|
94
|
-
return await updateStack(
|
|
96
|
+
return await updateStack(stackInfo.stackId, templateBody, context);
|
|
95
97
|
}
|
|
96
98
|
else {
|
|
97
99
|
// create stack
|
|
@@ -82,6 +82,7 @@ const schema = {
|
|
|
82
82
|
'.*': {
|
|
83
83
|
type: 'object',
|
|
84
84
|
properties: {
|
|
85
|
+
name: { type: 'string' },
|
|
85
86
|
type: { type: 'string', enum: ['API_GATEWAY'] },
|
|
86
87
|
triggers: {
|
|
87
88
|
type: 'array',
|
|
@@ -93,7 +94,7 @@ const schema = {
|
|
|
93
94
|
},
|
|
94
95
|
},
|
|
95
96
|
},
|
|
96
|
-
required: ['type', 'triggers'],
|
|
97
|
+
required: ['name', 'type', 'triggers'],
|
|
97
98
|
},
|
|
98
99
|
},
|
|
99
100
|
},
|
package/dist/src/stack/deploy.js
CHANGED
|
@@ -29,6 +29,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
29
29
|
exports.deployStack = exports.IacStack = void 0;
|
|
30
30
|
const ros = __importStar(require("@alicloud/ros-cdk-core"));
|
|
31
31
|
const fc = __importStar(require("@alicloud/ros-cdk-fc"));
|
|
32
|
+
const agw = __importStar(require("@alicloud/ros-cdk-apigateway"));
|
|
33
|
+
const ram = __importStar(require("@alicloud/ros-cdk-ram"));
|
|
34
|
+
const types_1 = require("../types");
|
|
32
35
|
const common_1 = require("../common");
|
|
33
36
|
const node_path_1 = __importDefault(require("node:path"));
|
|
34
37
|
const fs = __importStar(require("node:fs"));
|
|
@@ -38,9 +41,9 @@ const resolveCode = (location) => {
|
|
|
38
41
|
return fileContent.toString('base64');
|
|
39
42
|
};
|
|
40
43
|
class IacStack extends ros.Stack {
|
|
41
|
-
constructor(scope, iac,
|
|
42
|
-
super(scope, iac.service
|
|
43
|
-
new ros.RosInfo(this, ros.RosInfo.description,
|
|
44
|
+
constructor(scope, iac, context) {
|
|
45
|
+
super(scope, iac.service);
|
|
46
|
+
new ros.RosInfo(this, ros.RosInfo.description, `${iac.service} stack`);
|
|
44
47
|
const service = new fc.RosService(this, `${iac.service}-service`, {
|
|
45
48
|
serviceName: `${iac.service}-service`,
|
|
46
49
|
}, true);
|
|
@@ -59,12 +62,80 @@ class IacStack extends ros.Stack {
|
|
|
59
62
|
}, true);
|
|
60
63
|
func.addDependsOn(service);
|
|
61
64
|
});
|
|
65
|
+
const apiGateway = iac.events.find((event) => event.type === types_1.EventTypes.API_GATEWAY);
|
|
66
|
+
if (apiGateway) {
|
|
67
|
+
const gatewayAccessRole = new ram.RosRole(this, `${iac.service}_role`, {
|
|
68
|
+
roleName: `${iac.service}-gateway-access-role`,
|
|
69
|
+
description: `${iac.service} role`,
|
|
70
|
+
assumeRolePolicyDocument: {
|
|
71
|
+
version: '1',
|
|
72
|
+
statement: [
|
|
73
|
+
{
|
|
74
|
+
action: 'sts:AssumeRole',
|
|
75
|
+
effect: 'Allow',
|
|
76
|
+
principal: {
|
|
77
|
+
service: ['apigateway.aliyuncs.com'],
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
],
|
|
81
|
+
},
|
|
82
|
+
policies: [
|
|
83
|
+
{
|
|
84
|
+
policyName: `${iac.service}-policy`,
|
|
85
|
+
policyDocument: {
|
|
86
|
+
version: '1',
|
|
87
|
+
statement: [
|
|
88
|
+
{
|
|
89
|
+
action: ['fc:InvokeFunction'],
|
|
90
|
+
effect: 'Allow',
|
|
91
|
+
// @TODO implement at least permission granting
|
|
92
|
+
resource: ['*'],
|
|
93
|
+
},
|
|
94
|
+
],
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
],
|
|
98
|
+
}, true);
|
|
99
|
+
const apiGatewayGroup = new agw.RosGroup(this, `${iac.service}_apigroup`, {
|
|
100
|
+
groupName: `${iac.service}_apigroup`,
|
|
101
|
+
}, true);
|
|
102
|
+
iac.events
|
|
103
|
+
.filter((event) => event.type === types_1.EventTypes.API_GATEWAY)
|
|
104
|
+
.forEach((event) => {
|
|
105
|
+
event.triggers.forEach((trigger) => {
|
|
106
|
+
const key = `${trigger.method}_${trigger.path}`.toLowerCase().replace(/\//g, '_');
|
|
107
|
+
const api = new agw.RosApi(this, `${event.key}_api_${key}`, {
|
|
108
|
+
apiName: `${event.name}_api_${key}`,
|
|
109
|
+
groupId: apiGatewayGroup.attrGroupId,
|
|
110
|
+
visibility: 'PRIVATE',
|
|
111
|
+
requestConfig: {
|
|
112
|
+
requestProtocol: 'HTTP',
|
|
113
|
+
requestHttpMethod: trigger.method,
|
|
114
|
+
requestPath: trigger.path,
|
|
115
|
+
requestMode: 'PASSTHROUGH',
|
|
116
|
+
},
|
|
117
|
+
serviceConfig: {
|
|
118
|
+
serviceProtocol: 'FunctionCompute',
|
|
119
|
+
functionComputeConfig: {
|
|
120
|
+
fcRegionId: context.region,
|
|
121
|
+
serviceName: service.serviceName,
|
|
122
|
+
functionName: trigger.backend,
|
|
123
|
+
roleArn: gatewayAccessRole.attrArn,
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
resultSample: 'ServerlessInsight resultSample',
|
|
127
|
+
resultType: 'JSON',
|
|
128
|
+
}, true);
|
|
129
|
+
api.addDependsOn(apiGatewayGroup);
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
}
|
|
62
133
|
}
|
|
63
134
|
}
|
|
64
135
|
exports.IacStack = IacStack;
|
|
65
|
-
const generateStackTemplate = (stackName, iac) => {
|
|
136
|
+
const generateStackTemplate = (stackName, iac, context) => {
|
|
66
137
|
const app = new ros.App();
|
|
67
|
-
new IacStack(app, iac);
|
|
138
|
+
new IacStack(app, iac, context);
|
|
68
139
|
const assembly = app.synth();
|
|
69
140
|
const stackArtifact = assembly.getStackByName(stackName);
|
|
70
141
|
const parameters = Object.entries(stackArtifact.parameters).map(([key, value]) => ({
|
|
@@ -75,7 +146,7 @@ const generateStackTemplate = (stackName, iac) => {
|
|
|
75
146
|
};
|
|
76
147
|
const deployStack = async (stackName, iac, context) => {
|
|
77
148
|
common_1.printer.info(`Deploying stack... ${JSON.stringify(iac)}`);
|
|
78
|
-
const { template, parameters } = generateStackTemplate(stackName, iac);
|
|
149
|
+
const { template, parameters } = generateStackTemplate(stackName, iac, context);
|
|
79
150
|
console.log('Generated ROS YAML:', JSON.stringify({ template, parameters }));
|
|
80
151
|
await (0, common_1.rosStackDeploy)(stackName, template, { ...context, parameters });
|
|
81
152
|
common_1.printer.info(`Stack deployed! 🎉`);
|
package/dist/src/types.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geek-fun/serverlessinsight",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
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",
|
|
@@ -50,8 +50,10 @@
|
|
|
50
50
|
],
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"@alicloud/openapi-client": "^0.4.11",
|
|
53
|
+
"@alicloud/ros-cdk-apigateway": "^1.2.0",
|
|
53
54
|
"@alicloud/ros-cdk-core": "^1.2.0",
|
|
54
55
|
"@alicloud/ros-cdk-fc": "^1.2.0",
|
|
56
|
+
"@alicloud/ros-cdk-ram": "^1.2.0",
|
|
55
57
|
"@alicloud/ros20190910": "^3.4.3",
|
|
56
58
|
"ajv": "^8.17.1",
|
|
57
59
|
"chalk": "^4.1.2",
|