]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi-target-discovery-modal/iscsi-target-discovery-modal.component.ts
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / block / iscsi-target-discovery-modal / iscsi-target-discovery-modal.component.ts
1 import { Component, OnInit } from '@angular/core';
2 import { FormControl, Validators } from '@angular/forms';
3
4 import { I18n } from '@ngx-translate/i18n-polyfill';
5 import { BsModalRef } from 'ngx-bootstrap/modal';
6
7 import { IscsiService } from '../../../shared/api/iscsi.service';
8 import { NotificationType } from '../../../shared/enum/notification-type.enum';
9 import { CdFormGroup } from '../../../shared/forms/cd-form-group';
10 import { CdValidators } from '../../../shared/forms/cd-validators';
11 import { NotificationService } from '../../../shared/services/notification.service';
12
13 @Component({
14 selector: 'cd-iscsi-target-discovery-modal',
15 templateUrl: './iscsi-target-discovery-modal.component.html',
16 styleUrls: ['./iscsi-target-discovery-modal.component.scss']
17 })
18 export class IscsiTargetDiscoveryModalComponent implements OnInit {
19 discoveryForm: CdFormGroup;
20
21 USER_REGEX = /[\w\.:@_-]{8,64}/;
22 PASSWORD_REGEX = /[\w@\-_\/]{12,16}/;
23
24 constructor(
25 public bsModalRef: BsModalRef,
26 private iscsiService: IscsiService,
27 private notificationService: NotificationService,
28 private i18n: I18n
29 ) {
30 this.discoveryForm = new CdFormGroup({
31 user: new FormControl(''),
32 password: new FormControl(''),
33 mutual_user: new FormControl(''),
34 mutual_password: new FormControl('')
35 });
36
37 CdValidators.validateIf(
38 this.discoveryForm.get('user'),
39 () =>
40 this.discoveryForm.getValue('password') ||
41 this.discoveryForm.getValue('mutual_user') ||
42 this.discoveryForm.getValue('mutual_password'),
43 [Validators.required],
44 [Validators.pattern(this.USER_REGEX)],
45 [
46 this.discoveryForm.get('password'),
47 this.discoveryForm.get('mutual_user'),
48 this.discoveryForm.get('mutual_password')
49 ]
50 );
51
52 CdValidators.validateIf(
53 this.discoveryForm.get('password'),
54 () =>
55 this.discoveryForm.getValue('user') ||
56 this.discoveryForm.getValue('mutual_user') ||
57 this.discoveryForm.getValue('mutual_password'),
58 [Validators.required],
59 [Validators.pattern(this.PASSWORD_REGEX)],
60 [
61 this.discoveryForm.get('user'),
62 this.discoveryForm.get('mutual_user'),
63 this.discoveryForm.get('mutual_password')
64 ]
65 );
66
67 CdValidators.validateIf(
68 this.discoveryForm.get('mutual_user'),
69 () => this.discoveryForm.getValue('mutual_password'),
70 [Validators.required],
71 [Validators.pattern(this.USER_REGEX)],
72 [
73 this.discoveryForm.get('user'),
74 this.discoveryForm.get('password'),
75 this.discoveryForm.get('mutual_password')
76 ]
77 );
78
79 CdValidators.validateIf(
80 this.discoveryForm.get('mutual_password'),
81 () => this.discoveryForm.getValue('mutual_user'),
82 [Validators.required],
83 [Validators.pattern(this.PASSWORD_REGEX)],
84 [
85 this.discoveryForm.get('user'),
86 this.discoveryForm.get('password'),
87 this.discoveryForm.get('mutual_user')
88 ]
89 );
90 }
91
92 ngOnInit() {
93 this.iscsiService.getDiscovery().subscribe((auth) => {
94 this.discoveryForm.patchValue(auth);
95 });
96 }
97
98 submitAction() {
99 this.iscsiService.updateDiscovery(this.discoveryForm.value).subscribe(
100 () => {
101 this.notificationService.show(
102 NotificationType.success,
103 this.i18n('Updated discovery authentication')
104 );
105 this.bsModalRef.hide();
106 },
107 () => {
108 this.bsModalRef.hide();
109 }
110 );
111 }
112 }