@geek-fun/serverlessinsight 0.0.6 → 0.2.0
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 +24 -14
- package/dist/src/commands/deploy.js +2 -1
- package/dist/src/commands/destroy.js +10 -0
- package/dist/src/commands/index.js +28 -13
- package/dist/src/commands/template.js +26 -0
- package/dist/src/commands/validate.js +4 -5
- package/dist/src/common/actionContext.js +13 -7
- package/dist/src/common/base64.js +5 -0
- package/dist/src/common/constants.js +4 -0
- package/dist/src/common/iacHelper.js +48 -12
- package/dist/src/common/imsClient.js +52 -0
- package/dist/src/common/index.d.ts +4 -1
- package/dist/src/common/index.js +4 -1
- package/dist/src/common/providerEnum.js +11 -0
- package/dist/src/common/rosClient.js +92 -9
- package/dist/src/parser/databaseParser.js +33 -0
- package/dist/src/parser/eventParser.js +15 -0
- package/dist/src/parser/functionParser.js +20 -0
- package/dist/src/parser/index.d.ts +2 -0
- package/dist/src/parser/index.js +36 -0
- package/dist/src/parser/tagParser.js +10 -0
- package/dist/src/stack/deploy.js +57 -13
- package/dist/src/stack/index.d.ts +0 -2
- package/dist/src/stack/index.js +0 -16
- package/dist/src/stack/rfsStack/function.js +32 -0
- package/dist/src/stack/rfsStack/index.d.ts +9 -0
- package/dist/src/stack/rfsStack/index.js +39 -0
- package/dist/src/stack/rosStack/bootstrap.js +40 -0
- package/dist/src/stack/rosStack/database.js +314 -0
- package/dist/src/stack/rosStack/event.js +136 -0
- package/dist/src/stack/rosStack/function.js +108 -0
- package/dist/src/stack/rosStack/index.d.ts +7 -0
- package/dist/src/stack/rosStack/index.js +69 -0
- package/dist/src/stack/rosStack/stage.js +46 -0
- package/dist/src/stack/rosStack/tag.js +11 -0
- package/dist/src/stack/rosStack/vars.js +49 -0
- package/dist/src/types/assets.js +2 -0
- package/dist/src/types/domains/context.js +8 -0
- package/dist/src/types/domains/database.js +2 -0
- package/dist/src/types/domains/function.js +2 -0
- package/dist/src/types/domains/provider.js +2 -0
- package/dist/src/types/domains/tag.js +2 -0
- package/dist/src/types/domains/vars.js +2 -0
- package/dist/src/types/index.d.ts +44 -0
- package/dist/src/types/index.js +23 -0
- package/dist/src/validator/databaseSchema.js +83 -0
- package/dist/src/validator/eventSchema.js +41 -0
- package/dist/src/validator/functionSchema.js +45 -0
- package/dist/src/validator/iacSchema.js +42 -0
- package/dist/src/validator/index.d.ts +1 -0
- package/dist/src/validator/index.js +5 -0
- package/dist/src/validator/rootSchema.js +52 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +24 -14
- package/samples/aliyun-poc-es.yml +30 -0
- package/samples/aliyun-poc-fc.yml +60 -0
- package/samples/aliyun-poc-rds.yml +24 -0
- package/samples/huawei-poc-fc.yml +60 -0
- package/dist/src/common/provider.js +0 -11
- package/dist/src/stack/iacSchema.js +0 -145
- package/dist/src/stack/iacStack.js +0 -146
- package/dist/src/stack/parse.js +0 -46
- /package/dist/src/{types.js → types/domains/event.js} +0 -0
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geek-fun/serverlessinsight",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.2.0",
|
|
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",
|
|
@@ -49,35 +49,45 @@
|
|
|
49
49
|
"function"
|
|
50
50
|
],
|
|
51
51
|
"dependencies": {
|
|
52
|
+
"@alicloud/ims20190815": "^2.1.4",
|
|
52
53
|
"@alicloud/openapi-client": "^0.4.12",
|
|
53
54
|
"@alicloud/ros-cdk-apigateway": "^1.4.0",
|
|
54
55
|
"@alicloud/ros-cdk-core": "^1.4.0",
|
|
56
|
+
"@alicloud/ros-cdk-elasticsearchserverless": "^1.4.0",
|
|
55
57
|
"@alicloud/ros-cdk-fc3": "^1.4.0",
|
|
58
|
+
"@alicloud/ros-cdk-oss": "^1.4.0",
|
|
59
|
+
"@alicloud/ros-cdk-ossdeployment": "^1.4.0",
|
|
56
60
|
"@alicloud/ros-cdk-ram": "^1.4.0",
|
|
57
|
-
"@alicloud/
|
|
61
|
+
"@alicloud/ros-cdk-rds": "^1.5.0",
|
|
62
|
+
"@alicloud/ros-cdk-sls": "^1.5.0",
|
|
63
|
+
"@alicloud/ros20190910": "^3.5.2",
|
|
58
64
|
"ajv": "^8.17.1",
|
|
65
|
+
"ali-oss": "^6.22.0",
|
|
59
66
|
"chalk": "^5.3.0",
|
|
60
67
|
"commander": "^12.1.0",
|
|
61
68
|
"i18n": "^0.15.1",
|
|
62
|
-
"
|
|
63
|
-
"pino
|
|
64
|
-
"
|
|
69
|
+
"lodash": "^4.17.21",
|
|
70
|
+
"pino": "^9.5.0",
|
|
71
|
+
"pino-pretty": "^13.0.0",
|
|
72
|
+
"yaml": "^2.6.1"
|
|
65
73
|
},
|
|
66
74
|
"devDependencies": {
|
|
75
|
+
"@types/ali-oss": "^6.16.11",
|
|
67
76
|
"@types/i18n": "^0.13.12",
|
|
68
|
-
"@types/jest": "^29.5.
|
|
69
|
-
"@types/
|
|
70
|
-
"@
|
|
71
|
-
"@typescript-eslint/
|
|
72
|
-
"eslint": "^8.
|
|
77
|
+
"@types/jest": "^29.5.14",
|
|
78
|
+
"@types/lodash": "^4.17.13",
|
|
79
|
+
"@types/node": "^22.10.1",
|
|
80
|
+
"@typescript-eslint/eslint-plugin": "^8.17.0",
|
|
81
|
+
"@typescript-eslint/parser": "^8.17.0",
|
|
82
|
+
"eslint": "^9.16.0",
|
|
73
83
|
"eslint-config-prettier": "^9.1.0",
|
|
74
84
|
"eslint-plugin-prettier": "^5.2.1",
|
|
75
|
-
"globals": "^15.
|
|
76
|
-
"husky": "^9.1.
|
|
85
|
+
"globals": "^15.13.0",
|
|
86
|
+
"husky": "^9.1.7",
|
|
77
87
|
"jest": "^29.7.0",
|
|
78
|
-
"prettier": "^3.
|
|
88
|
+
"prettier": "^3.4.2",
|
|
79
89
|
"ts-jest": "^29.2.5",
|
|
80
90
|
"ts-node": "^10.9.2",
|
|
81
|
-
"typescript": "^5.
|
|
91
|
+
"typescript": "^5.7.2"
|
|
82
92
|
}
|
|
83
93
|
}
|
|
@@ -3,10 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.deploy = void 0;
|
|
4
4
|
const stack_1 = require("../stack");
|
|
5
5
|
const common_1 = require("../common");
|
|
6
|
+
const parser_1 = require("../parser");
|
|
6
7
|
const deploy = async (stackName, options) => {
|
|
7
8
|
const context = (0, common_1.constructActionContext)({ ...options, stackName });
|
|
8
9
|
common_1.logger.info('Validating yaml...');
|
|
9
|
-
const iac = (0,
|
|
10
|
+
const iac = (0, parser_1.parseYaml)(context.iacLocation);
|
|
10
11
|
common_1.logger.info('Yaml is valid! 🎉');
|
|
11
12
|
common_1.logger.info('Deploying stack...');
|
|
12
13
|
await (0, stack_1.deployStack)(stackName, iac, context);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.destroyStack = void 0;
|
|
4
|
+
const common_1 = require("../common");
|
|
5
|
+
const destroyStack = async (stackName) => {
|
|
6
|
+
const context = (0, common_1.constructActionContext)({ stackName });
|
|
7
|
+
common_1.logger.info(`Destroying stack ${stackName}...`);
|
|
8
|
+
await (0, common_1.rosStackDelete)(context);
|
|
9
|
+
};
|
|
10
|
+
exports.destroyStack = destroyStack;
|
|
@@ -2,42 +2,57 @@
|
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
const commander_1 = require("commander");
|
|
5
|
-
const lang_1 = require("../lang");
|
|
6
5
|
const common_1 = require("../common");
|
|
7
6
|
const validate_1 = require("./validate");
|
|
8
7
|
const deploy_1 = require("./deploy");
|
|
8
|
+
const template_1 = require("./template");
|
|
9
|
+
const destroy_1 = require("./destroy");
|
|
10
|
+
const common_2 = require("../common");
|
|
9
11
|
const program = new commander_1.Command();
|
|
10
12
|
program.name('si').description('CLI for ServerlessInsight').version((0, common_1.getVersion)());
|
|
11
13
|
program
|
|
12
14
|
.command('show')
|
|
13
15
|
.description('show string')
|
|
14
|
-
.
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
.
|
|
18
|
-
const limit = options.first ? 1 : undefined;
|
|
19
|
-
common_1.logger.debug({ limit, first: options.first, separator: options.separator }, 'log command info');
|
|
20
|
-
console.log(`${str} ${options.first} ${options.separator} ${lang_1.lang.__('hello')}`);
|
|
16
|
+
.action(async (options) => {
|
|
17
|
+
const context = (0, common_1.constructActionContext)({ ...options });
|
|
18
|
+
const result = await (0, common_2.getIamInfo)(context);
|
|
19
|
+
console.log('result:', JSON.stringify(result));
|
|
21
20
|
});
|
|
22
21
|
program
|
|
23
22
|
.command('validate [stackName]')
|
|
24
23
|
.description('validate serverless Iac yaml')
|
|
25
24
|
.option('-f, --file <path>', 'specify the yaml file')
|
|
26
|
-
.
|
|
25
|
+
.option('-s, --stage <stage>', 'specify the stage')
|
|
26
|
+
.action((stackName, { file, stage }) => {
|
|
27
27
|
common_1.logger.debug('log command info');
|
|
28
|
-
(0, validate_1.validate)(
|
|
28
|
+
(0, validate_1.validate)(file, stage);
|
|
29
29
|
});
|
|
30
30
|
program
|
|
31
31
|
.command('deploy <stackName>')
|
|
32
32
|
.description('deploy serverless Iac yaml')
|
|
33
33
|
.option('-f, --file <path>', 'specify the yaml file')
|
|
34
|
+
.option('-s, --stage <stage>', 'specify the stage')
|
|
34
35
|
.option('-p, --parameter <key=value>', 'override parameters', (value, previous) => {
|
|
35
36
|
const [key, val] = value.split('=');
|
|
36
37
|
previous[key] = val;
|
|
37
38
|
return previous;
|
|
38
39
|
}, {})
|
|
39
|
-
.action(async (stackName,
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
.action(async (stackName, { file, parameter, stage }) => {
|
|
41
|
+
await (0, deploy_1.deploy)(stackName, { location: file, parameters: parameter, stage });
|
|
42
|
+
});
|
|
43
|
+
program
|
|
44
|
+
.command('template <stackName>')
|
|
45
|
+
.description('print ROS template')
|
|
46
|
+
.option('-f, --file <path>', 'specify the yaml file')
|
|
47
|
+
.option('-s, --stage <stage>', 'specify the stage')
|
|
48
|
+
.option('-t, --format <type>', 'output content type (JSON or YAML)', 'JSON')
|
|
49
|
+
.action((stackName, { format, file, stage }) => {
|
|
50
|
+
(0, template_1.template)(stackName, { format, location: file, stage });
|
|
51
|
+
});
|
|
52
|
+
program
|
|
53
|
+
.command('destroy <stackName>')
|
|
54
|
+
.description('destroy serverless stack')
|
|
55
|
+
.action(async (stackName) => {
|
|
56
|
+
await (0, destroy_1.destroyStack)(stackName);
|
|
42
57
|
});
|
|
43
58
|
program.parse();
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.template = void 0;
|
|
7
|
+
const types_1 = require("../types");
|
|
8
|
+
const yaml_1 = __importDefault(require("yaml"));
|
|
9
|
+
const deploy_1 = require("../stack/deploy");
|
|
10
|
+
const common_1 = require("../common");
|
|
11
|
+
const parser_1 = require("../parser");
|
|
12
|
+
const template = (stackName, options) => {
|
|
13
|
+
const iac = (0, parser_1.parseYaml)((0, common_1.getIacLocation)(options.location));
|
|
14
|
+
const context = (0, common_1.constructActionContext)({ ...options, stackName, provider: iac.provider.name });
|
|
15
|
+
const { template } = (0, deploy_1.generateStackTemplate)(stackName, iac, context);
|
|
16
|
+
if (typeof template === 'string') {
|
|
17
|
+
common_1.logger.info(`\n${template}`);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
const output = options.format === types_1.TemplateFormat.JSON
|
|
21
|
+
? JSON.stringify(template, null, 2)
|
|
22
|
+
: yaml_1.default.stringify(template);
|
|
23
|
+
common_1.logger.info(`\n${output}`);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
exports.template = template;
|
|
@@ -2,11 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.validate = void 0;
|
|
4
4
|
const common_1 = require("../common");
|
|
5
|
-
const
|
|
6
|
-
const validate = (location) => {
|
|
7
|
-
const context = (0, common_1.constructActionContext)({ location });
|
|
8
|
-
(0,
|
|
5
|
+
const parser_1 = require("../parser");
|
|
6
|
+
const validate = (location, stage) => {
|
|
7
|
+
const context = (0, common_1.constructActionContext)({ location, stage });
|
|
8
|
+
(0, parser_1.parseYaml)(context.iacLocation);
|
|
9
9
|
common_1.logger.info('Yaml is valid! 🎉');
|
|
10
|
-
common_1.logger.debug('Yaml is valid! debug🎉');
|
|
11
10
|
};
|
|
12
11
|
exports.validate = validate;
|
|
@@ -3,8 +3,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.constructActionContext = void 0;
|
|
6
|
+
exports.constructActionContext = exports.getIacLocation = void 0;
|
|
7
7
|
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
+
const getIacLocation = (location) => {
|
|
9
|
+
const projectRoot = node_path_1.default.resolve(process.cwd());
|
|
10
|
+
return location
|
|
11
|
+
? node_path_1.default.resolve(projectRoot, location)
|
|
12
|
+
: node_path_1.default.resolve(projectRoot, 'serverlessinsight.yml') ||
|
|
13
|
+
node_path_1.default.resolve(projectRoot, 'serverlessInsight.yml') ||
|
|
14
|
+
node_path_1.default.resolve(projectRoot, 'ServerlessInsight.yml') ||
|
|
15
|
+
node_path_1.default.resolve(projectRoot, 'serverless-insight.yml');
|
|
16
|
+
};
|
|
17
|
+
exports.getIacLocation = getIacLocation;
|
|
8
18
|
const constructActionContext = (config) => {
|
|
9
19
|
return {
|
|
10
20
|
stage: config?.stage ?? 'default',
|
|
@@ -13,13 +23,9 @@ const constructActionContext = (config) => {
|
|
|
13
23
|
accessKeyId: config?.accessKeyId ?? process.env.ALIYUN_ACCESS_KEY_ID,
|
|
14
24
|
accessKeySecret: config?.accessKeySecret ?? process.env.ALIYUN_ACCESS_KEY_SECRET,
|
|
15
25
|
securityToken: config?.securityToken ?? process.env.ALIYUN_SECURITY_TOKEN,
|
|
16
|
-
iacLocation: (()
|
|
17
|
-
const projectRoot = node_path_1.default.resolve(process.cwd());
|
|
18
|
-
return config?.location
|
|
19
|
-
? node_path_1.default.resolve(projectRoot, config?.location)
|
|
20
|
-
: node_path_1.default.resolve(projectRoot, 'serverless-insight.yml');
|
|
21
|
-
})(),
|
|
26
|
+
iacLocation: (0, exports.getIacLocation)(config?.location),
|
|
22
27
|
parameters: Object.entries(config?.parameters ?? {}).map(([key, value]) => ({ key, value })),
|
|
28
|
+
provider: config?.provider,
|
|
23
29
|
};
|
|
24
30
|
};
|
|
25
31
|
exports.constructActionContext = constructActionContext;
|
|
@@ -15,39 +15,75 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
37
|
};
|
|
28
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.replaceReference = exports.resolveCode = void 0;
|
|
39
|
+
exports.replaceReference = exports.getFileSource = exports.readCodeSize = exports.resolveCode = void 0;
|
|
30
40
|
const node_path_1 = __importDefault(require("node:path"));
|
|
31
41
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
32
42
|
const ros = __importStar(require("@alicloud/ros-cdk-core"));
|
|
43
|
+
const ossDeployment = __importStar(require("@alicloud/ros-cdk-ossdeployment"));
|
|
44
|
+
const node_crypto_1 = __importDefault(require("node:crypto"));
|
|
33
45
|
const resolveCode = (location) => {
|
|
34
46
|
const filePath = node_path_1.default.resolve(process.cwd(), location);
|
|
35
47
|
const fileContent = node_fs_1.default.readFileSync(filePath);
|
|
36
48
|
return fileContent.toString('base64');
|
|
37
49
|
};
|
|
38
50
|
exports.resolveCode = resolveCode;
|
|
39
|
-
const
|
|
51
|
+
const readCodeSize = (location) => {
|
|
52
|
+
const filePath = node_path_1.default.resolve(process.cwd(), location);
|
|
53
|
+
const stats = node_fs_1.default.statSync(filePath);
|
|
54
|
+
return stats.size;
|
|
55
|
+
};
|
|
56
|
+
exports.readCodeSize = readCodeSize;
|
|
57
|
+
const getFileSource = (fcName, location) => {
|
|
58
|
+
const filePath = node_path_1.default.resolve(process.cwd(), location);
|
|
59
|
+
if (node_fs_1.default.lstatSync(filePath).isDirectory()) {
|
|
60
|
+
throw new Error('The provided path is a directory, not a file.');
|
|
61
|
+
}
|
|
62
|
+
const hash = node_crypto_1.default.createHash('md5').update(node_fs_1.default.readFileSync(filePath)).digest('hex');
|
|
63
|
+
const objectKey = `${fcName}/${hash}-${filePath.split('/').pop()}`;
|
|
64
|
+
const source = ossDeployment.Source.asset(filePath, {}, `${fcName}/${hash}-`);
|
|
65
|
+
return { source, objectKey };
|
|
66
|
+
};
|
|
67
|
+
exports.getFileSource = getFileSource;
|
|
68
|
+
const evalCtx = (value, ctx) => {
|
|
69
|
+
const containsStage = value.match(/\$\{ctx.\w+}/);
|
|
70
|
+
return containsStage ? value.replace(/\$\{ctx.stage}/g, ctx.stage) : value;
|
|
71
|
+
};
|
|
72
|
+
const replaceReference = (value, ctx) => {
|
|
40
73
|
if (typeof value === 'string') {
|
|
41
74
|
const matchVar = value.match(/^\$\{vars\.(\w+)}$/);
|
|
42
75
|
const containsVar = value.match(/\$\{vars\.(\w+)}/);
|
|
43
76
|
const matchMap = value.match(/^\$\{stages\.(\w+)}$/);
|
|
44
77
|
const containsMap = value.match(/\$\{stages\.(\w+)}/);
|
|
45
78
|
const matchFn = value.match(/^\$\{functions\.(\w+(\.\w+)?)}$/);
|
|
79
|
+
if (value.match(/\$\{ctx.\w+}/)) {
|
|
80
|
+
return evalCtx(value, ctx);
|
|
81
|
+
}
|
|
46
82
|
if (matchVar?.length) {
|
|
47
83
|
return ros.Fn.ref(matchVar[1]);
|
|
48
84
|
}
|
|
49
85
|
if (matchMap?.length) {
|
|
50
|
-
return ros.Fn.findInMap('stages',
|
|
86
|
+
return ros.Fn.findInMap('stages', ctx.stage, matchMap[1]);
|
|
51
87
|
}
|
|
52
88
|
if (matchFn?.length) {
|
|
53
89
|
return ros.Fn.getAtt(matchFn[1], 'FunctionName');
|
|
@@ -64,10 +100,10 @@ const replaceReference = (value, stage) => {
|
|
|
64
100
|
return value;
|
|
65
101
|
}
|
|
66
102
|
if (Array.isArray(value)) {
|
|
67
|
-
return value.map((item) => (0, exports.replaceReference)(item,
|
|
103
|
+
return value.map((item) => (0, exports.replaceReference)(item, ctx));
|
|
68
104
|
}
|
|
69
105
|
if (typeof value === 'object' && value !== null) {
|
|
70
|
-
return Object.fromEntries(Object.entries(value).map(([key, val]) => [key, (0, exports.replaceReference)(val,
|
|
106
|
+
return Object.fromEntries(Object.entries(value).map(([key, val]) => [key, (0, exports.replaceReference)(val, ctx)]));
|
|
71
107
|
}
|
|
72
108
|
return value;
|
|
73
109
|
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.getIamInfo = void 0;
|
|
37
|
+
const ims20190815_1 = __importStar(require("@alicloud/ims20190815")), ims20190815 = ims20190815_1;
|
|
38
|
+
const openApi = __importStar(require("@alicloud/openapi-client"));
|
|
39
|
+
const getIamInfo = async (context) => {
|
|
40
|
+
const imsClient = new ims20190815_1.default(new openApi.Config({
|
|
41
|
+
accessKeyId: context.accessKeyId,
|
|
42
|
+
accessKeySecret: context.accessKeySecret,
|
|
43
|
+
}));
|
|
44
|
+
const { body } = await imsClient.getUser(new ims20190815.GetUserRequest({ userAccessKeyId: context.accessKeyId }));
|
|
45
|
+
return body?.user
|
|
46
|
+
? {
|
|
47
|
+
...body.user,
|
|
48
|
+
accountId: body.user.userPrincipalName?.match(/@(\d+)\.onaliyun\.com/)?.pop(),
|
|
49
|
+
}
|
|
50
|
+
: undefined;
|
|
51
|
+
};
|
|
52
|
+
exports.getIamInfo = getIamInfo;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './providerEnum';
|
|
2
2
|
export * from './logger';
|
|
3
3
|
export * from './getVersion';
|
|
4
4
|
export * from './rosClient';
|
|
5
5
|
export * from './actionContext';
|
|
6
6
|
export * from './iacHelper';
|
|
7
|
+
export * from './constants';
|
|
8
|
+
export * from './imsClient';
|
|
9
|
+
export * from './base64';
|
package/dist/src/common/index.js
CHANGED
|
@@ -14,9 +14,12 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./
|
|
17
|
+
__exportStar(require("./providerEnum"), exports);
|
|
18
18
|
__exportStar(require("./logger"), exports);
|
|
19
19
|
__exportStar(require("./getVersion"), exports);
|
|
20
20
|
__exportStar(require("./rosClient"), exports);
|
|
21
21
|
__exportStar(require("./actionContext"), exports);
|
|
22
22
|
__exportStar(require("./iacHelper"), exports);
|
|
23
|
+
__exportStar(require("./constants"), exports);
|
|
24
|
+
__exportStar(require("./imsClient"), exports);
|
|
25
|
+
__exportStar(require("./base64"), exports);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ProviderEnum = void 0;
|
|
4
|
+
var ProviderEnum;
|
|
5
|
+
(function (ProviderEnum) {
|
|
6
|
+
ProviderEnum["HUAWEI"] = "huawei";
|
|
7
|
+
ProviderEnum["ALIYUN"] = "aliyun";
|
|
8
|
+
// TENCENT = 'TENCENT',
|
|
9
|
+
// AWS = 'AZURE',
|
|
10
|
+
// AZURE = 'AZURE',
|
|
11
|
+
})(ProviderEnum || (exports.ProviderEnum = ProviderEnum = {}));
|
|
@@ -15,23 +15,36 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
37
|
};
|
|
28
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.rosStackDeploy = void 0;
|
|
39
|
+
exports.publishAssets = exports.rosStackDelete = exports.rosStackDeploy = void 0;
|
|
30
40
|
const tea_util_1 = __importDefault(require("@alicloud/tea-util"));
|
|
31
41
|
const ros20190910_1 = __importStar(require("@alicloud/ros20190910"));
|
|
32
42
|
const openapi_client_1 = require("@alicloud/openapi-client");
|
|
43
|
+
const ali_oss_1 = __importDefault(require("ali-oss"));
|
|
33
44
|
const logger_1 = require("./logger");
|
|
34
45
|
const lang_1 = require("../lang");
|
|
46
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
47
|
+
const lodash_1 = require("lodash");
|
|
35
48
|
const client = new ros20190910_1.default(new openapi_client_1.Config({
|
|
36
49
|
accessKeyId: process.env.ALIYUN_ACCESS_KEY_ID,
|
|
37
50
|
accessKeySecret: process.env.ALIYUN_ACCESS_KEY_SECRET,
|
|
@@ -70,7 +83,7 @@ const updateStack = async (stackId, templateBody, context) => {
|
|
|
70
83
|
});
|
|
71
84
|
try {
|
|
72
85
|
const response = await client.updateStack(updateStackRequest);
|
|
73
|
-
logger_1.logger.info(`更新中,资源栈ID
|
|
86
|
+
logger_1.logger.info(`更新中,资源栈ID: ${response.body?.stackId}`);
|
|
74
87
|
// wait for stack update complete
|
|
75
88
|
return await getStackActionResult(response.body?.stackId || '', context.region);
|
|
76
89
|
}
|
|
@@ -163,3 +176,73 @@ const rosStackDeploy = async (stackName, templateBody, context) => {
|
|
|
163
176
|
}
|
|
164
177
|
};
|
|
165
178
|
exports.rosStackDeploy = rosStackDeploy;
|
|
179
|
+
const rosStackDelete = async ({ stackName, region, }) => {
|
|
180
|
+
const stackInfo = await getStackByName(stackName, region);
|
|
181
|
+
if (!stackInfo) {
|
|
182
|
+
logger_1.logger.warn(`Stack: ${stackName} not exists, skipped! 🚫`);
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
try {
|
|
186
|
+
const deleteStackRequest = new ros20190910_1.DeleteStackRequest({
|
|
187
|
+
regionId: region,
|
|
188
|
+
stackId: stackInfo.stackId,
|
|
189
|
+
});
|
|
190
|
+
await client.deleteStack(deleteStackRequest);
|
|
191
|
+
await getStackActionResult(stackInfo.stackId, region);
|
|
192
|
+
logger_1.logger.info(`Stack: ${stackName} deleted! ♻️`);
|
|
193
|
+
}
|
|
194
|
+
catch (err) {
|
|
195
|
+
logger_1.logger.error(`Stack: ${stackName} delete failed! ❌, error: ${JSON.stringify(err)}`);
|
|
196
|
+
throw new Error(JSON.stringify(err));
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
exports.rosStackDelete = rosStackDelete;
|
|
200
|
+
const ensureBucketExits = async (bucketName, ossClient) => await ossClient.getBucketInfo(bucketName).catch((err) => {
|
|
201
|
+
if (err.code === 'NoSuchBucket') {
|
|
202
|
+
logger_1.logger.info(`Bucket: ${bucketName} not exists, creating...`);
|
|
203
|
+
return ossClient.putBucket(bucketName, {
|
|
204
|
+
storageClass: 'Standard',
|
|
205
|
+
acl: 'private',
|
|
206
|
+
dataRedundancyType: 'LRS',
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
throw err;
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
const getZipAssets = ({ files, rootPath }, region) => {
|
|
214
|
+
const zipAssets = Object.entries(files)
|
|
215
|
+
.filter(([, fileItem]) => fileItem.source.path.endsWith('zip'))
|
|
216
|
+
.map(([, fileItem]) => ({
|
|
217
|
+
bucketName: (0, lodash_1.get)(fileItem, 'destinations.current_account-current_region.bucketName', '').replace('${ALIYUN::Region}', region),
|
|
218
|
+
source: `${rootPath}/${fileItem.source.path}`,
|
|
219
|
+
objectKey: (0, lodash_1.get)(fileItem, 'destinations.current_account-current_region.objectKey'),
|
|
220
|
+
}));
|
|
221
|
+
return !(0, lodash_1.isEmpty)(zipAssets) ? zipAssets : undefined;
|
|
222
|
+
};
|
|
223
|
+
const publishAssets = async (assets, context) => {
|
|
224
|
+
const zipAssets = getZipAssets(assets, context.region);
|
|
225
|
+
if (!zipAssets) {
|
|
226
|
+
logger_1.logger.info('No assets to publish, skipped!');
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
const bucketName = zipAssets[0].bucketName;
|
|
230
|
+
const client = new ali_oss_1.default({
|
|
231
|
+
region: `oss-${context.region}`,
|
|
232
|
+
accessKeyId: context.accessKeyId,
|
|
233
|
+
accessKeySecret: context.accessKeySecret,
|
|
234
|
+
bucket: bucketName,
|
|
235
|
+
});
|
|
236
|
+
await ensureBucketExits(bucketName, client);
|
|
237
|
+
const headers = {
|
|
238
|
+
'x-oss-storage-class': 'Standard',
|
|
239
|
+
'x-oss-object-acl': 'private',
|
|
240
|
+
'x-oss-forbid-overwrite': 'false',
|
|
241
|
+
};
|
|
242
|
+
await Promise.all(zipAssets.map(async ({ source, objectKey }) => {
|
|
243
|
+
await client.put(objectKey, node_path_1.default.normalize(source), { headers });
|
|
244
|
+
logger_1.logger.info(`Upload file: ${source}) to bucket: ${bucketName} successfully!`);
|
|
245
|
+
}));
|
|
246
|
+
return bucketName;
|
|
247
|
+
};
|
|
248
|
+
exports.publishAssets = publishAssets;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseDatabase = void 0;
|
|
4
|
+
const lodash_1 = require("lodash");
|
|
5
|
+
const parseDatabase = (databases) => {
|
|
6
|
+
if ((0, lodash_1.isEmpty)(databases)) {
|
|
7
|
+
return undefined;
|
|
8
|
+
}
|
|
9
|
+
return Object.entries(databases)?.map(([key, database]) => ({
|
|
10
|
+
key: key,
|
|
11
|
+
name: database.name,
|
|
12
|
+
type: database.type,
|
|
13
|
+
version: database.version,
|
|
14
|
+
security: {
|
|
15
|
+
basicAuth: {
|
|
16
|
+
username: (0, lodash_1.get)(database, 'security.basic_auth.master_user'),
|
|
17
|
+
password: (0, lodash_1.get)(database, 'security.basic_auth.password'),
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
cu: {
|
|
21
|
+
min: database.cu?.min ?? 0,
|
|
22
|
+
max: database.cu?.max ?? 6,
|
|
23
|
+
},
|
|
24
|
+
storage: {
|
|
25
|
+
min: database.storage?.min ?? 20,
|
|
26
|
+
},
|
|
27
|
+
network: {
|
|
28
|
+
type: database.network?.type ?? 'PRIVATE',
|
|
29
|
+
ingressRules: database.network?.ingress_rules ?? ['0.0.0.0/0'],
|
|
30
|
+
},
|
|
31
|
+
}));
|
|
32
|
+
};
|
|
33
|
+
exports.parseDatabase = parseDatabase;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseEvent = void 0;
|
|
4
|
+
const parseEvent = (events) => {
|
|
5
|
+
if (!events) {
|
|
6
|
+
return undefined;
|
|
7
|
+
}
|
|
8
|
+
return Object.entries(events).map(([key, event]) => ({
|
|
9
|
+
key,
|
|
10
|
+
name: event.name,
|
|
11
|
+
type: event.type,
|
|
12
|
+
triggers: event.triggers,
|
|
13
|
+
}));
|
|
14
|
+
};
|
|
15
|
+
exports.parseEvent = parseEvent;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseFunction = void 0;
|
|
4
|
+
const lodash_1 = require("lodash");
|
|
5
|
+
const parseFunction = (functions) => {
|
|
6
|
+
if ((0, lodash_1.isEmpty)(functions)) {
|
|
7
|
+
return undefined;
|
|
8
|
+
}
|
|
9
|
+
return Object.entries(functions).map(([key, func]) => ({
|
|
10
|
+
key,
|
|
11
|
+
name: func.name,
|
|
12
|
+
runtime: func.runtime,
|
|
13
|
+
handler: func.handler,
|
|
14
|
+
memory: func.memory,
|
|
15
|
+
timeout: func.timeout,
|
|
16
|
+
environment: func.environment,
|
|
17
|
+
code: func.code,
|
|
18
|
+
}));
|
|
19
|
+
};
|
|
20
|
+
exports.parseFunction = parseFunction;
|