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 { rgwBucketEncryptionModel } from '../models/rgw-bucket-encryption';
20 import { TableComponent } from '~/app/shared/datatable/table/table.component';
23 selector: 'cd-rgw-configuration-page',
24 templateUrl: './rgw-configuration-page.component.html',
25 styleUrls: ['./rgw-configuration-page.component.scss']
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;
32 kmsProviders: string[];
34 columns: Array<CdTableColumn> = [];
36 configForm: CdFormGroup;
37 permissions: Permissions;
38 encryptionConfigValues: any = [];
39 selection: CdTableSelection = new CdTableSelection();
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;
53 public activeModal: NgbActiveModal,
54 public actionLabels: ActionLabelsI18n,
55 private rgwBucketService: RgwBucketService,
56 public authStorageService: AuthStorageService,
57 private modalService: ModalService
60 this.permissions = this.authStorageService.getPermissions();
66 name: $localize`Encryption Type`,
67 prop: 'encryption_type',
71 name: $localize`Key Management Service Provider`,
76 name: $localize`Address`,
85 name: this.actionLabels.CREATE,
86 click: () => this.openRgwConfigModal(false),
87 disable: () => this.disableCreate
92 name: this.actionLabels.EDIT,
93 click: () => this.openRgwConfigModal(true)
97 this.excludeProps = this.columns.map((column) => column.prop);
98 this.excludeProps.push('unique_id');
101 getBackend(encryptionData: { [x: string]: any[] }, encryptionType: string) {
102 return new Set(encryptionData[encryptionType].map((item) => item.backend));
105 areAllAllowedBackendsPresent(allowedBackends: any[], backendsSet: Set<any>) {
106 return allowedBackends.every((backend) => backendsSet.has(backend));
109 openRgwConfigModal(edit: boolean) {
111 const initialState = {
114 selectedEncryptionConfigValues: this.selection.first(),
117 this.bsModalRef = this.modalService.show(RgwConfigModalComponent, initialState, {
121 const initialState = {
123 allEncryptionConfigValues: this.allEncryptionValues
125 this.bsModalRef = this.modalService.show(RgwConfigModalComponent, initialState, {
131 updateSelection(selection: CdTableSelection) {
132 this.selection = selection;
135 setExpandedRow(expandedRow: any) {
136 super.setExpandedRow(expandedRow);
140 this.rgwBucketService.getEncryptionConfig().subscribe((data: any) => {
141 this.allEncryptionValues = data;
142 const allowedBackends = rgwBucketEncryptionModel.kmsProviders;
144 const kmsBackends = this.getBackend(data, 'SSE_KMS');
145 const s3Backends = this.getBackend(data, 'SSE_S3');
147 const allKmsBackendsPresent = this.areAllAllowedBackendsPresent(allowedBackends, kmsBackends);
148 const allS3BackendsPresent = this.areAllAllowedBackendsPresent(allowedBackends, s3Backends);
150 this.disableCreate = allKmsBackendsPresent && allS3BackendsPresent;
151 this.encryptionConfigValues = Object.values(data).flat();