Skip to content

feat: Add ignoreKey configuration, support setting key to hide the entire line of info information #4221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/info/src/config.default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export const info = {
title: 'Midway Info',
infoPath: '/_info',
hiddenKey: DefaultHiddenKey,
ignoreKey: [],
} as InfoConfigOptions;
40 changes: 27 additions & 13 deletions packages/info/src/infoService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ export class InfoService {
@Config('info.hiddenKey')
defaultHiddenKey: string[];

@Config('info.ignoreKey')
ignoreKey: string[];

secretMatchList: Array<any>;

@ApplicationContext()
Expand All @@ -59,22 +62,33 @@ export class InfoService {
}

info(infoValueType?: InfoValueType) {
const info: TypeInfo[] = [];
info.push(this.projectInfo());
info.push(this.systemInfo());
info.push(this.resourceOccupationInfo());
info.push(this.softwareInfo());
info.push(this.midwayConfig());
info.push(this.midwayService());
info.push(this.timeInfo());
info.push(this.envInfo());
info.push(this.dependenciesInfo());
info.push(this.networkInfo());
const allInfo: TypeInfo[] = [];
allInfo.push(this.projectInfo());
allInfo.push(this.systemInfo());
allInfo.push(this.resourceOccupationInfo());
allInfo.push(this.softwareInfo());
allInfo.push(this.midwayConfig());
allInfo.push(this.midwayService());
allInfo.push(this.timeInfo());
allInfo.push(this.envInfo());
allInfo.push(this.dependenciesInfo());
allInfo.push(this.networkInfo());

// 过滤自定义隐藏的key
const newInfo = allInfo.map(({ type, info }) => {
const infoKeys = Object.keys(info);
const keys = infoKeys.filter(k => !this.ignoreKey.includes(k));
const infoByIgnore = {};
for (const key of keys) {
infoByIgnore[key] = info[key];
}
return { type, info: infoByIgnore };
});

if (infoValueType === 'html') {
return renderToHtml(info, this.titleConfig);
return renderToHtml(newInfo, this.titleConfig);
}
return info;
return newInfo;
}

projectInfo(): TypeInfo {
Expand Down
1 change: 1 addition & 0 deletions packages/info/src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ export interface InfoConfigOptions {
title: string;
infoPath: string;
hiddenKey: Array<string>;
ignoreKey: Array<string>
}
2 changes: 1 addition & 1 deletion packages/info/test/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ exports[`test/index.test.ts should test get config and filter secret 1`] = `
"core": "{"healthCheckTimeout":1000}",
"cos": "{"default":{"SecretId":"df******af","SecretKey":"te******vc","SecurityToken":"fj*********af"}}",
"debug": "{"recordConfigMergeOrder":true}",
"info": "{"title":"Midway Info","infoPath":"/_info","hiddenKey":["k***","****","*****n","********","p****"]}",
"info": "{"title":"Midway Info","infoPath":"/_info","hiddenKey":["k***","****","*****n","********","p****"],"ignoreKey":[]}",
"keys": "["1*******5"]",
"oss": "{"clients":{"default":{"accessKeyId":"123","accessKeySecret":"f*****f"}}}",
},
Expand Down
2 changes: 1 addition & 1 deletion packages/info/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('test/index.test.ts', () => {
SecretKey: 'tewqtewqvc',
SecurityToken: 'fjkdlsajfdsaf'
}
}
},
},
imports: [
info
Expand Down
Loading