Skip to content

Commit 00b1152

Browse files
lsongsusexingzhang-suse
authored andcommitted
NVSHAS-10168 Add remote export option to system configurations page
1 parent 4530666 commit 00b1152

10 files changed

Lines changed: 123 additions & 67 deletions

File tree

admin/webapp/websrc/app/common/api/config-http.service.ts

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -75,27 +75,13 @@ export class ConfigHttpService {
7575
);
7676
}
7777

78-
getFedSystemConfig() {
78+
getFedSystemConfig(payload) {
7979
return GlobalVariable.http
80-
.post(
81-
PathConstant.EXPORT_SYSTEM_CONFIG_FED_URL,
82-
{},
83-
{
84-
observe: 'response',
85-
responseType: 'text',
86-
}
87-
)
88-
.pipe(
89-
catchError(error => {
90-
const textDecoder = new TextDecoder();
91-
let errorRes = textDecoder.decode(error.error);
92-
error.error =
93-
error.headers.get('Content-type') === 'application/json'
94-
? JSON.parse(errorRes).message
95-
: errorRes;
96-
return throwError(error);
97-
})
98-
);
80+
.post(PathConstant.EXPORT_SYSTEM_CONFIG_FED_URL, payload, {
81+
observe: 'response',
82+
responseType: 'text',
83+
})
84+
.pipe();
9985
}
10086

10187
getUsageReport(): Observable<UsageReport> {

admin/webapp/websrc/app/common/constants/global.constant.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ export class GlobalConstant {
283283
COMPLIANCE_PROFILE: 'cfgComplianceProfileExport.yaml',
284284
VUL_PROFILE: 'cfgVulProfileExport.yaml',
285285
RESPONSE_RULES: 'cfgReponseRulesExport.yaml',
286+
FED_SYSTEM_CONFIG: 'cfgFedSystemConfigExport.yaml',
286287
};
287288

288289
public static SIGSTORE_ATTRIBUTE = {

admin/webapp/websrc/app/common/services/settings.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ export class SettingsService {
7777
return this.configHttpService.getSystemConfig(exportMode);
7878
}
7979

80-
getFedSystemConfig() {
81-
return this.configHttpService.getFedSystemConfig();
80+
getFedSystemConfig(payload) {
81+
return this.configHttpService.getFedSystemConfig(payload);
8282
}
8383

8484
getServer() {

admin/webapp/websrc/app/routes/components/export-options-modal/export-options-modal.component.html

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,6 @@ <h4 mat-dialog-title class="mb-2">
1919
[page]="data.page"
2020
[source]="data.source"></app-export-options>
2121
<div class="d-flex justify-content-end mt-2">
22-
<!-- <button mat-button-->
23-
<!-- [color]="'primary'"-->
24-
<!-- (click)="onCancel()"-->
25-
<!-- class="mr-2">-->
26-
<!-- {{'general.CANCEL' | translate}}-->
27-
<!-- </button>-->
2822
<app-loading-button
2923
[appearance]="'mat-raised-button'"
3024
[color]="'primary'"

admin/webapp/websrc/app/routes/components/export-options/export-options.component.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export class ExportOptionsComponent implements OnInit {
4444
GlobalConstant.REMOTE_EXPORT_FILENAME.ADMISSION_RULES,
4545
GlobalConstant.REMOTE_EXPORT_FILENAME.DLP,
4646
GlobalConstant.REMOTE_EXPORT_FILENAME.WAF,
47+
GlobalConstant.REMOTE_EXPORT_FILENAME.FED_SYSTEM_CONFIG,
4748
].includes(this.exportFileName);
4849
this.exportOptions?.addControl('export_options', this.exportOptionsForm);
4950
this.getRemoteRepositories();

admin/webapp/websrc/app/routes/settings/configuration/export-form/export-form.component.html

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,50 @@
22
<ng-container *ngIf="isExportAuthorized">
33
<div class="ml-3 my-md-4">
44
<h1 class="h4 font-weight-normal">{{ 'setting.EXPORT' | translate }}</h1>
5-
<div class="ml-3 my-md-2 d-flex align-items-center">
5+
<div class="ml-3 my-md-2 d-flex flex-column">
66
<mat-radio-group
77
*ngIf="source !== GlobalConstant['NAV_SOURCE']['FED_POLICY']"
8-
class="mx-3"
8+
class="mb-3"
99
aria-label="Export Type"
1010
formControlName="export">
11-
<mat-radio-button value="all">{{
11+
<mat-radio-button value="all" class="mr-3">{{
1212
'setting.ALL' | translate
1313
}}</mat-radio-button>
1414
<mat-radio-button value="policy">{{
1515
'setting.POLICY' | translate
1616
}}</mat-radio-button>
1717
</mat-radio-group>
18+
1819
<div
1920
*ngIf="source === GlobalConstant['NAV_SOURCE']['FED_POLICY']"
20-
class="text-muted">
21-
{{ 'setting.EXPORT_FED_CONFIG_HINT' | translate }}
21+
class="mb-3">
22+
<div class="text-muted mb-2">
23+
{{ 'setting.EXPORT_FED_CONFIG_HINT' | translate }}
24+
</div>
25+
26+
<app-export-options
27+
[exportOptions]="exportForm"
28+
[exportFileName]="exportFileName"
29+
[page]="'system_fed_config'"
30+
[source]="source">
31+
</app-export-options>
32+
</div>
33+
<div class="mt-2 d-flex justify-content-end">
34+
<app-loading-button
35+
[appearance]="'mat-raised-button'"
36+
[color]="'primary'"
37+
[disabled]="
38+
source !== GlobalConstant['NAV_SOURCE']['FED_POLICY'] &&
39+
(!exportForm.valid || submittingForm)
40+
"
41+
[loading]="
42+
source !== GlobalConstant['NAV_SOURCE']['FED_POLICY'] &&
43+
submittingForm
44+
"
45+
[text]="'setting.SUBMIT' | translate"
46+
[type]="'submit'">
47+
</app-loading-button>
2248
</div>
23-
<app-loading-button
24-
[appearance]="'mat-raised-button'"
25-
[color]="'primary'"
26-
[disabled]="
27-
source !== GlobalConstant['NAV_SOURCE']['FED_POLICY'] &&
28-
(!exportForm.valid || submittingForm)
29-
"
30-
[loading]="
31-
source !== GlobalConstant['NAV_SOURCE']['FED_POLICY'] &&
32-
submittingForm
33-
"
34-
[text]="'setting.SUBMIT' | translate"
35-
[type]="'submit'"
36-
class="ml-auto">
37-
</app-loading-button>
3849
</div>
3950
<div *ngIf="errorMsg" class="ml-4 text-danger">{{ errorMsg }}</div>
4051
</div>

admin/webapp/websrc/app/routes/settings/configuration/export-form/export-form.component.ts

Lines changed: 74 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Component, OnInit, Input } from '@angular/core';
22
import { FormControl, FormGroup, Validators } from '@angular/forms';
3-
import { ErrorResponse } from '@common/types';
43
import { UtilsService } from '@common/utils/app.utils';
54
import { NotificationService } from '@services/notification.service';
65
import { SettingsService } from '@services/settings.service';
@@ -12,6 +11,7 @@ import { GlobalVariable } from '@common/variables/global.variable';
1211
import { MapConstant } from '@common/constants/map.constant';
1312
import { AuthUtilsService } from '@common/utils/auth.utils';
1413
import { GlobalConstant } from '@common/constants/global.constant';
14+
import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
1515

1616
@Component({
1717
selector: 'app-export-form',
@@ -20,9 +20,11 @@ import { GlobalConstant } from '@common/constants/global.constant';
2020
})
2121
export class ExportFormComponent implements OnInit {
2222
@Input() source = GlobalConstant.NAV_SOURCE.SELF;
23+
serverErrorMessage: SafeHtml = '';
2324
GlobalConstant = GlobalConstant;
2425
submittingForm = false;
2526
errorMsg: string = '';
27+
exportFileName: string = '';
2628
exportForm = new FormGroup({
2729
export: new FormControl(null, Validators.required),
2830
as_standalone: new FormControl(false),
@@ -45,7 +47,8 @@ export class ExportFormComponent implements OnInit {
4547
private tr: TranslateService,
4648
private utils: UtilsService,
4749
private authUtilsService: AuthUtilsService,
48-
private notificationService: NotificationService
50+
private notificationService: NotificationService,
51+
private domSanitizer: DomSanitizer
4952
) {}
5053

5154
get importUrl(): string {
@@ -68,26 +71,21 @@ export class ExportFormComponent implements OnInit {
6871
: this.tr.instant('setting.message.UPLOAD_FINISH'),
6972
error: this.tr.instant('setting.IMPORT_FAILED'),
7073
};
74+
if (this.source === GlobalConstant.NAV_SOURCE.FED_POLICY) {
75+
this.exportFileName =
76+
GlobalConstant.REMOTE_EXPORT_FILENAME.FED_SYSTEM_CONFIG;
77+
}
7178
}
7279

7380
submitExport(): void {
74-
const exportMode: string = this.exportForm.get('export')?.value || '';
7581
this.submittingForm = true;
7682
this.errorMsg = '';
77-
if (this.source === GlobalConstant.NAV_SOURCE.FED_POLICY) {
78-
this.settingsService.getFedSystemConfig().subscribe(response => {
79-
let fileName = this.utils.getExportedFileName(response);
80-
let blob = new Blob([response.body || ''], {
81-
type: 'text/plain;charset=utf-8',
82-
});
83-
saveAs(blob, fileName);
84-
this.notificationService.open(
85-
this.tr.instant('waf.msg.EXPORT_SENSOR_OK')
86-
);
87-
});
88-
} else {
83+
84+
if (this.source !== GlobalConstant.NAV_SOURCE.FED_POLICY) {
85+
const exportType: string = this.exportForm.get('export')?.value || '';
86+
8987
this.settingsService
90-
.getSystemConfig(exportMode)
88+
.getSystemConfig(exportType)
9189
.pipe(
9290
finalize(() => {
9391
this.submittingForm = false;
@@ -99,7 +97,7 @@ export class ExportFormComponent implements OnInit {
9997
type: 'application/zip',
10098
});
10199
let fileName =
102-
exportMode && exportMode.toLowerCase() === 'all'
100+
exportType && exportType.toLowerCase() === 'all'
103101
? `NV${this.utils.parseDatetimeStr(new Date())}.conf.gz`
104102
: `NV${this.utils.parseDatetimeStr(new Date())}_policy.conf.gz`;
105103
saveAs(exportUrl, fileName);
@@ -110,6 +108,65 @@ export class ExportFormComponent implements OnInit {
110108
this.errorMsg = error.error;
111109
}
112110
);
111+
} else {
112+
const exportOptions: any =
113+
this.exportForm.get('export_options')?.value || {};
114+
const isRemote = exportOptions.export_mode === 'remote';
115+
116+
let payload = {};
117+
118+
if (isRemote) {
119+
payload = {
120+
remote_export_options: exportOptions,
121+
};
122+
this.settingsService.getFedSystemConfig(payload).subscribe(
123+
response => {
124+
this.notificationService.open(
125+
this.tr.instant('setting.message.EXPORT_OK')
126+
);
127+
},
128+
error => {
129+
if (
130+
error.message &&
131+
error.message.length > GlobalConstant.MAX_ERROR_MESSAGE_LENGTH
132+
) {
133+
this.serverErrorMessage =
134+
this.domSanitizer.bypassSecurityTrustHtml(error.message);
135+
}
136+
this.notificationService.open(
137+
this.serverErrorMessage
138+
? this.tr.instant('setting.message.EXPORT_NG')
139+
: this.utils.getAlertifyMsg(error, '', false),
140+
GlobalConstant.NOTIFICATION_TYPE.ERROR
141+
);
142+
}
143+
);
144+
} else {
145+
this.settingsService.getFedSystemConfig(payload).subscribe(
146+
response => {
147+
let fileName = this.utils.getExportedFileName(response);
148+
let blob = new Blob([response.body || ''], {
149+
type: 'text/plain;charset=utf-8',
150+
});
151+
saveAs(blob, fileName);
152+
this.notificationService.open(
153+
this.tr.instant('setting.message.EXPORT_OK')
154+
);
155+
},
156+
error => {
157+
if (!MapConstant.USER_TIMEOUT.includes(error.status)) {
158+
this.notificationService.open(
159+
this.utils.getAlertifyMsg(
160+
error.error,
161+
this.tr.instant('setting.message.EXPORT_NG'),
162+
false
163+
),
164+
GlobalConstant.NOTIFICATION_TYPE.ERROR
165+
);
166+
}
167+
}
168+
);
169+
}
113170
}
114171
}
115172
}

admin/webapp/websrc/app/routes/settings/configuration/export-form/export-form.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { ImportFileModule } from '@components/ui/import-file/import-file.module'
1010
import { NvCommonModule } from '@common/nvCommon.module';
1111
import { LoadingButtonModule } from '@components/ui/loading-button/loading-button.module';
1212
import { LoadingTemplateModule } from '@components/ui/loading-template/loading-template.module';
13+
import { ExportOptionsModule } from '@components/export-options/export-options.module';
1314

1415
@NgModule({
1516
declarations: [ExportFormComponent],
@@ -25,6 +26,7 @@ import { LoadingTemplateModule } from '@components/ui/loading-template/loading-t
2526
MatCheckboxModule,
2627
LoadingButtonModule,
2728
LoadingTemplateModule,
29+
ExportOptionsModule,
2830
],
2931
exports: [ExportFormComponent],
3032
})

admin/webapp/websrc/assets/i18n/en-common.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3305,7 +3305,9 @@
33053305
"URL_INVALID": "That doesn't look like a valid url.",
33063306
"GET_SYS_LOG_ERR": "Error happened when getting system settings",
33073307
"UPLOAD_FINISH": "File uploaded successfully. System will logout automatically. please login again after it finished.",
3308-
"UPLOAD_FINISH_FED": "File uploaded successfully."
3308+
"UPLOAD_FINISH_FED": "File uploaded successfully.",
3309+
"EXPORT_OK": "System configurations file is exported successfully.",
3310+
"EXPORT_NG": "Error happens when exporting system configuration file."
33093311
},
33103312
"description": {
33113313
"PROFILE": "Update information about you.",

admin/webapp/websrc/assets/i18n/zh_cn-common.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3301,7 +3301,9 @@
33013301
"URL_INVALID": "这看起来不是一个有效的网址.",
33023302
"GET_SYS_LOG_ERR": "获取系统设置时发生错误",
33033303
"UPLOAD_FINISH": "文件上传成功. 系统将自动登出. 请在数据导入完成后再次登录.",
3304-
"UPLOAD_FINISH_FED": "文件上传成功."
3304+
"UPLOAD_FINISH_FED": "文件上传成功.",
3305+
"EXPORT_OK": "系统配置文件已成功导出。",
3306+
"EXPORT_NG": "导出系统配置文件时发生错误。"
33053307
},
33063308
"description": {
33073309
"PROFILE": "请更新您的个人资料.",

0 commit comments

Comments
 (0)