Skip to content

Commit

Permalink
pub: [email protected], [email protected], parse-spec…
Browse files Browse the repository at this point in the history
…@0.0.28-beta.9

Signed-off-by: zxypro1 <[email protected]>
  • Loading branch information
zxypro1 committed Jul 29, 2024
1 parent 358a85b commit d7b8119
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 13 deletions.
3 changes: 2 additions & 1 deletion packages/engine/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@serverless-devs/engine",
"version": "0.1.4-beta.9",
"version": "0.1.4-beta.10",
"description": "a engine lib for serverless-devs",
"main": "lib/index.js",
"scripts": {
Expand Down Expand Up @@ -28,6 +28,7 @@
"@serverless-devs/parse-spec": "workspace:^",
"@serverless-devs/utils": "workspace:^",
"@serverless-devs/load-application": "workspace:^",
"@serverless-devs/secret": "workspace:^",
"ajv": "^8.12.0",
"chalk": "4.x",
"flatted": "^3.2.7",
Expand Down
10 changes: 10 additions & 0 deletions packages/engine/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Actions from './actions';
import Credential from '@serverless-devs/credential';
import loadComponent from '@serverless-devs/load-component';
import Logger, { ILoggerInstance } from '@serverless-devs/logger';
import SecretManager from '@serverless-devs/secret';
import { DevsError, ETrackerType, emoji, getAbsolutePath, getRootHome, getUserAgent, traceid, isDevsDebugMode } from '@serverless-devs/utils';
import { EXIT_CODE, INFO_EXP_PATTERN, COMPONENT_EXP_PATTERN } from './constants';
import assert from 'assert';
Expand Down Expand Up @@ -39,6 +40,7 @@ class Engine {
private globalActionInstance!: Actions; // 全局的 action
private actionInstance!: Actions; // 项目的 action
private info: Record<string, any> = {}; // 存储全局变量
private secretManager!: SecretManager; // 敏感参数管理

constructor(private options: IEngineOptions) {
debug('engine start');
Expand All @@ -56,6 +58,14 @@ class Engine {
// 初始化 logger
this.glog = this.getLogger() as Logger;
this.logger = this.glog.__generate('engine');
// 初始化 secretManager
this.secretManager = SecretManager.getInstance();
// 加密所有敏感值
const secrets = this.secretManager.getAllSecrets();
for (const i of keys(secrets)) {
this.glog.__setSecret([i, secrets[i]]);
this.glog.__setSecret([i, this.secretManager.getSecret(i)]);
}
// 初始化 spec
this.parseSpecInstance = new ParseSpec(get(this.options, 'template'), {
argv: this.options.args,
Expand Down
5 changes: 3 additions & 2 deletions packages/load-application/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@serverless-devs/load-application",
"version": "0.0.14-beta.5",
"version": "0.0.14-beta.6",
"description": "load application for serverless-devs",
"main": "lib/index.js",
"scripts": {
Expand All @@ -18,10 +18,11 @@
},
"dependencies": {
"@serverless-cd/debug": "^4.3.4",
"@serverless-devs/art-template": "^4.13.16-beta.12",
"@serverless-devs/art-template": "^4.13.16-beta.17",
"@serverless-devs/credential": "workspace:^",
"@serverless-devs/downloads": "workspace:^",
"@serverless-devs/utils": "workspace:^",
"@serverless-devs/secret": "workspace:^",
"art-template": "^4.13.2",
"axios": "^1.6.0",
"chalk": "^4.1.2",
Expand Down
4 changes: 4 additions & 0 deletions packages/load-application/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ export interface IOptions {
* Whether overwrite all files in the destination directory
*/
overwrite?: boolean;
/**
* Whether to use for inner apis
*/
inner?: boolean;
}

export enum IProvider {
Expand Down
6 changes: 6 additions & 0 deletions packages/load-application/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { keys, replace, split } from 'lodash';
import { RANDOM_PATTERN, REGISTRY, GITHUB_REGISTRY } from '../constant';
import Credential from '@serverless-devs/credential';
import SecretManager from '@serverless-devs/secret';

export { default as getInputs } from './get-inputs';

Expand Down Expand Up @@ -32,3 +33,8 @@ export const getDefaultValue = (value: any) => {
if (typeof value !== 'string') return;
return replace(value, RANDOM_PATTERN, randomId());
};

export const getSecretManager = () => {
const secretManager = SecretManager.getInstance();
return secretManager;
};
12 changes: 10 additions & 2 deletions packages/load-application/src/v3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { isEmpty, includes, split, get, has, set, sortBy, map, concat, keys, sta
import axios from 'axios';
import parse from './parse';
import { IOptions } from './types';
import { getInputs, getUrlWithLatest, getUrlWithVersion, getAllCredential, getDefaultValue } from './utils';
import { getInputs, getUrlWithLatest, getUrlWithVersion, getAllCredential, getDefaultValue, getSecretManager } from './utils';
import YAML from 'yaml';
import inquirer from 'inquirer';
import chalk from 'chalk';
Expand Down Expand Up @@ -343,6 +343,13 @@ class LoadApplication {
const ele = properties[key];
if (has(parameters, key)) {
set(data, key, parameters[key]);
} else if (ele.type === 'secret') {
// support ${secret()}
set(data, key, `\${secret('${key}')`);
if (ele.hasOwnProperty('default') && getDefaultValue(ele.default)) {
const manager = getSecretManager();
manager.addSecret(key, getDefaultValue(ele.default) as string);
}
} else if (ele.hasOwnProperty('default')) {
set(data, key, getDefaultValue(ele.default));
} else if (includes(requiredList, key)) {
Expand Down Expand Up @@ -385,6 +392,7 @@ class LoadApplication {
'User-Agent': 'Serverless-Devs (https://github.com/Serverless-Devs/Serverless-Devs)',
...registry.getSignHeaders(),
devs_mock_env: process.env.DEVS_MOCK_ENV || 'false',
use_oss_internal_endpoint: this.options.inner ? 'true' : 'false',
},
// use final element as filename
filename: split(this.name, '/')[-1],
Expand All @@ -395,7 +403,7 @@ class LoadApplication {
if (startsWith(zipball_url, 'https')) {
logger.debug('https error, try http');
const newZipballUrl = zipball_url.replace('https://', 'http://');
await download(zipball_url, {
await download(newZipballUrl, {
dest: this.tempPath,
logger,
extract: true,
Expand Down
4 changes: 2 additions & 2 deletions packages/parse-spec/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@serverless-devs/parse-spec",
"version": "0.0.28-beta.8",
"version": "0.0.28-beta.9",
"description": "a parse yaml spec lib for serverless-devs",
"main": "lib/index.js",
"scripts": {
Expand All @@ -22,7 +22,7 @@
},
"dependencies": {
"@serverless-cd/debug": "^4.3.4",
"@serverless-devs/art-template": "^4.13.16-beta.12",
"@serverless-devs/art-template": "^4.13.16-beta.17",
"@serverless-devs/credential": "workspace:^",
"@serverless-devs/utils": "workspace:^",
"chalk": "^4.1.2",
Expand Down
40 changes: 34 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d7b8119

Please sign in to comment.