1 import { Component, EventEmitter, OnInit, Output, ViewChild } from '@angular/core';
3 import { NgbActiveModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
4 import _ from 'lodash';
6 import { Permissions } from '~/app/shared/models/permissions';
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 { TableComponent } from '~/app/shared/datatable/table/table.component';
20 import { ENCRYPTION_TYPE } from '../models/rgw-bucket-encryption';
25 } from '~/app/shared/models/rgw-encryption-config-keys';
28 selector: 'cd-rgw-configuration-page',
29 templateUrl: './rgw-configuration-page.component.html',
30 styleUrls: ['./rgw-configuration-page.component.scss']
32 export class RgwConfigurationPageComponent extends ListWithDetails implements OnInit {
33 readonly vaultAddress = /^((https?:\/\/)|(www.))(?:([a-zA-Z]+)|(\d+\.\d+.\d+.\d+)):\d{4}$/;
34 @ViewChild(TableComponent)
35 table: TableComponent;
37 kmsProviders: string[];
39 columns: Array<CdTableColumn> = [];
41 configForm: CdFormGroup;
42 permissions: Permissions;
43 encryptionConfigValues: any = [];
44 selection: CdTableSelection = new CdTableSelection();
47 submitAction = new EventEmitter();
48 authMethods: string[];
49 secretEngines: string[];
50 tableActions: CdTableAction[];
51 bsModalRef: NgbModalRef;
52 filteredEncryptionConfigValues: {};
53 excludeProps: any[] = [];
55 allEncryptionValues: any;
58 public activeModal: NgbActiveModal,
59 public actionLabels: ActionLabelsI18n,
60 private rgwBucketService: RgwBucketService,
61 public authStorageService: AuthStorageService,
62 private modalService: ModalService
65 this.permissions = this.authStorageService.getPermissions();
71 name: $localize`Encryption Type`,
72 prop: 'encryption_type',
76 name: $localize`Key Management Service Provider`,
81 name: $localize`Address`,
90 name: this.actionLabels.CREATE,
91 click: () => this.openRgwConfigModal(false),
92 disable: () => this.disableCreate
97 name: this.actionLabels.EDIT,
98 click: () => this.openRgwConfigModal(true)
102 this.excludeProps = this.columns.map((column) => column.prop);
103 this.excludeProps.push('unique_id');
106 getBackend(encryptionData: encryptionDatafromAPI, encryptionType: ENCRYPTION_TYPE) {
107 const backendSet = new Set(Object.keys(encryptionData[encryptionType]));
109 encryptionType === ENCRYPTION_TYPE.SSE_KMS
110 ? backendSet.has('kmip') && backendSet.has('vault')
111 : backendSet.has('vault');
115 openRgwConfigModal(edit: boolean) {
117 const initialState = {
120 selectedEncryptionConfigValues: this.selection.first(),
123 this.bsModalRef = this.modalService.show(RgwConfigModalComponent, initialState, {
127 const initialState = {
129 allEncryptionConfigValues: this.allEncryptionValues
131 this.bsModalRef = this.modalService.show(RgwConfigModalComponent, initialState, {
137 updateSelection(selection: CdTableSelection) {
138 this.selection = selection;
141 setExpandedRow(expandedRow: VaultConfig | KmipConfig) {
142 super.setExpandedRow(expandedRow);
145 flattenData(data: encryptionDatafromAPI) {
146 const combinedArray = [];
147 for (const kmsData of Object.values(data[ENCRYPTION_TYPE.SSE_KMS])) {
148 combinedArray.push(kmsData);
150 for (const s3Data of Object.values(data[ENCRYPTION_TYPE.SSE_S3])) {
151 combinedArray.push(s3Data);
153 return combinedArray;
157 this.rgwBucketService.getEncryptionConfig().subscribe((data: encryptionDatafromAPI) => {
158 this.allEncryptionValues = data;
159 const kmsBackends = this.getBackend(data, ENCRYPTION_TYPE.SSE_KMS);
160 const s3Backends = this.getBackend(data, ENCRYPTION_TYPE.SSE_S3);
161 this.disableCreate = kmsBackends && s3Backends;
162 this.encryptionConfigValues = this.flattenData(data);