]> git.apps.os.sepia.ceph.com Git - ceph.git/blob
fabf8f6697db5fc9e139dbab71d40a87000c0f39
[ceph.git] /
1 import { Component, EventEmitter, OnInit, Output, ViewChild } from '@angular/core';
2
3 import { NgbActiveModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
4 import _ from 'lodash';
5
6 import { Permissions } from '~/app/shared/models/permissions';
7
8 import { RgwBucketService } from '~/app/shared/api/rgw-bucket.service';
9 import { ActionLabelsI18n } from '~/app/shared/constants/app.constants';
10 import { CdFormGroup } from '~/app/shared/forms/cd-form-group';
11 import { CdTableColumn } from '~/app/shared/models/cd-table-column';
12 import { CdTableSelection } from '~/app/shared/models/cd-table-selection';
13 import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
14 import { ListWithDetails } from '~/app/shared/classes/list-with-details.class';
15 import { CdTableAction } from '~/app/shared/models/cd-table-action';
16 import { Icons } from '~/app/shared/enum/icons.enum';
17 import { ModalService } from '~/app/shared/services/modal.service';
18 import { RgwConfigModalComponent } from '../rgw-config-modal/rgw-config-modal.component';
19 import { rgwBucketEncryptionModel } from '../models/rgw-bucket-encryption';
20 import { TableComponent } from '~/app/shared/datatable/table/table.component';
21
22 @Component({
23   selector: 'cd-rgw-configuration-page',
24   templateUrl: './rgw-configuration-page.component.html',
25   styleUrls: ['./rgw-configuration-page.component.scss']
26 })
27 export class RgwConfigurationPageComponent extends ListWithDetails implements OnInit {
28   readonly vaultAddress = /^((https?:\/\/)|(www.))(?:([a-zA-Z]+)|(\d+\.\d+.\d+.\d+)):\d{4}$/;
29   @ViewChild(TableComponent)
30   table: TableComponent;
31
32   kmsProviders: string[];
33
34   columns: Array<CdTableColumn> = [];
35
36   configForm: CdFormGroup;
37   permissions: Permissions;
38   encryptionConfigValues: any = [];
39   selection: CdTableSelection = new CdTableSelection();
40
41   @Output()
42   submitAction = new EventEmitter();
43   authMethods: string[];
44   secretEngines: string[];
45   tableActions: CdTableAction[];
46   bsModalRef: NgbModalRef;
47   filteredEncryptionConfigValues: {};
48   excludeProps: any[] = [];
49   disableCreate = false;
50   allEncryptionValues: any;
51
52   constructor(
53     public activeModal: NgbActiveModal,
54     public actionLabels: ActionLabelsI18n,
55     private rgwBucketService: RgwBucketService,
56     public authStorageService: AuthStorageService,
57     private modalService: ModalService
58   ) {
59     super();
60     this.permissions = this.authStorageService.getPermissions();
61   }
62
63   ngOnInit() {
64     this.columns = [
65       {
66         name: $localize`Encryption Type`,
67         prop: 'encryption_type',
68         flexGrow: 1
69       },
70       {
71         name: $localize`Key Management Service Provider`,
72         prop: 'backend',
73         flexGrow: 1
74       },
75       {
76         name: $localize`Address`,
77         prop: 'addr',
78         flexGrow: 1
79       }
80     ];
81     this.tableActions = [
82       {
83         permission: 'create',
84         icon: Icons.add,
85         name: this.actionLabels.CREATE,
86         click: () => this.openRgwConfigModal(false),
87         disable: () => this.disableCreate
88       },
89       {
90         permission: 'update',
91         icon: Icons.edit,
92         name: this.actionLabels.EDIT,
93         click: () => this.openRgwConfigModal(true)
94       }
95     ];
96
97     this.excludeProps = this.columns.map((column) => column.prop);
98     this.excludeProps.push('unique_id');
99   }
100
101   getBackend(encryptionData: { [x: string]: any[] }, encryptionType: string) {
102     return new Set(encryptionData[encryptionType].map((item) => item.backend));
103   }
104
105   areAllAllowedBackendsPresent(allowedBackends: any[], backendsSet: Set<any>) {
106     return allowedBackends.every((backend) => backendsSet.has(backend));
107   }
108
109   openRgwConfigModal(edit: boolean) {
110     if (edit) {
111       const initialState = {
112         action: 'edit',
113         editing: true,
114         selectedEncryptionConfigValues: this.selection.first(),
115         table: this.table
116       };
117       this.bsModalRef = this.modalService.show(RgwConfigModalComponent, initialState, {
118         size: 'lg'
119       });
120     } else {
121       const initialState = {
122         action: 'create',
123         allEncryptionConfigValues: this.allEncryptionValues
124       };
125       this.bsModalRef = this.modalService.show(RgwConfigModalComponent, initialState, {
126         size: 'lg'
127       });
128     }
129   }
130
131   updateSelection(selection: CdTableSelection) {
132     this.selection = selection;
133   }
134
135   setExpandedRow(expandedRow: any) {
136     super.setExpandedRow(expandedRow);
137   }
138
139   fetchData() {
140     this.rgwBucketService.getEncryptionConfig().subscribe((data: any) => {
141       this.allEncryptionValues = data;
142       const allowedBackends = rgwBucketEncryptionModel.kmsProviders;
143
144       const kmsBackends = this.getBackend(data, 'SSE_KMS');
145       const s3Backends = this.getBackend(data, 'SSE_S3');
146
147       const allKmsBackendsPresent = this.areAllAllowedBackendsPresent(allowedBackends, kmsBackends);
148       const allS3BackendsPresent = this.areAllAllowedBackendsPresent(allowedBackends, s3Backends);
149
150       this.disableCreate = allKmsBackendsPresent && allS3BackendsPresent;
151       this.encryptionConfigValues = Object.values(data).flat();
152     });
153   }
154 }