]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-config-modal/rgw-config-modal.component.ts
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / rgw / rgw-config-modal / rgw-config-modal.component.ts
1 import { Component, EventEmitter, OnInit, Output } from '@angular/core';
2 import { AbstractControl, Validators } from '@angular/forms';
3 import { Router } from '@angular/router';
4
5 import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
6 import _ from 'lodash';
7
8 import { RgwBucketService } from '~/app/shared/api/rgw-bucket.service';
9 import { ActionLabelsI18n } from '~/app/shared/constants/app.constants';
10 import { NotificationType } from '~/app/shared/enum/notification-type.enum';
11 import { CdFormBuilder } from '~/app/shared/forms/cd-form-builder';
12 import { CdFormGroup } from '~/app/shared/forms/cd-form-group';
13 import { CdValidators } from '~/app/shared/forms/cd-validators';
14 import { NotificationService } from '~/app/shared/services/notification.service';
15 import { RgwBucketEncryptionModel } from '../models/rgw-bucket-encryption';
16
17 @Component({
18 selector: 'cd-rgw-config-modal',
19 templateUrl: './rgw-config-modal.component.html',
20 styleUrls: ['./rgw-config-modal.component.scss'],
21 providers: [RgwBucketEncryptionModel]
22 })
23 export class RgwConfigModalComponent implements OnInit {
24 readonly vaultAddress = /^((https?:\/\/)|(www.))(?:([a-zA-Z]+)|(\d+\.\d+.\d+.\d+)):\d{4}$/;
25
26 kmsProviders: string[];
27
28 configForm: CdFormGroup;
29
30 @Output()
31 submitAction = new EventEmitter();
32 authMethods: string[];
33 secretEngines: string[];
34
35 constructor(
36 private formBuilder: CdFormBuilder,
37 public activeModal: NgbActiveModal,
38 private router: Router,
39 public actionLabels: ActionLabelsI18n,
40 private rgwBucketService: RgwBucketService,
41 private rgwEncryptionModal: RgwBucketEncryptionModel,
42 private notificationService: NotificationService
43 ) {
44 this.createForm();
45 }
46 ngOnInit(): void {
47 this.kmsProviders = this.rgwEncryptionModal.kmsProviders;
48 this.authMethods = this.rgwEncryptionModal.authMethods;
49 this.secretEngines = this.rgwEncryptionModal.secretEngines;
50 }
51
52 createForm() {
53 this.configForm = this.formBuilder.group({
54 address: [
55 null,
56 [
57 Validators.required,
58 CdValidators.custom('vaultPattern', (value: string) => {
59 if (_.isEmpty(value)) {
60 return false;
61 }
62 return !this.vaultAddress.test(value);
63 })
64 ]
65 ],
66 kms_provider: ['vault', Validators.required],
67 encryptionType: ['aws:kms', Validators.required],
68 auth_method: ['token', Validators.required],
69 secret_engine: ['kv', Validators.required],
70 secret_path: ['/'],
71 namespace: [null],
72 token: [
73 null,
74 [
75 CdValidators.requiredIf({
76 auth_method: 'token'
77 })
78 ]
79 ],
80 ssl_cert: [null, CdValidators.sslCert()],
81 client_cert: [null, CdValidators.pemCert()],
82 client_key: [null, CdValidators.sslPrivKey()],
83 kmsEnabled: [{ value: false }],
84 s3Enabled: [{ value: false }]
85 });
86 }
87
88 fileUpload(files: FileList, controlName: string) {
89 const file: File = files[0];
90 const reader = new FileReader();
91 reader.addEventListener('load', () => {
92 const control: AbstractControl = this.configForm.get(controlName);
93 control.setValue(file);
94 control.markAsDirty();
95 control.markAsTouched();
96 control.updateValueAndValidity();
97 });
98 }
99
100 onSubmit() {
101 const values = this.configForm.value;
102 this.rgwBucketService
103 .setEncryptionConfig(
104 values['encryptionType'],
105 values['kms_provider'],
106 values['auth_method'],
107 values['secret_engine'],
108 values['secret_path'],
109 values['namespace'],
110 values['address'],
111 values['token'],
112 values['owner'],
113 values['ssl_cert'],
114 values['client_cert'],
115 values['client_key']
116 )
117 .subscribe({
118 next: () => {
119 this.notificationService.show(
120 NotificationType.success,
121 $localize`Updated RGW Encryption Configuration values`
122 );
123 },
124 error: (error: any) => {
125 this.notificationService.show(NotificationType.error, error);
126 this.configForm.setErrors({ cdSubmitButton: true });
127 },
128 complete: () => {
129 this.activeModal.close();
130 this.router.routeReuseStrategy.shouldReuseRoute = () => false;
131 this.router.onSameUrlNavigation = 'reload';
132 this.router.navigate([this.router.url]);
133 }
134 });
135 }
136 }