1 import { Component, Input, OnChanges } from '@angular/core';
3 import { RgwBucketService } from '~/app/shared/api/rgw-bucket.service';
5 import * as xml2js from 'xml2js';
6 import { RgwRateLimitConfig } from '../models/rgw-rate-limit';
9 selector: 'cd-rgw-bucket-details',
10 templateUrl: './rgw-bucket-details.component.html',
11 styleUrls: ['./rgw-bucket-details.component.scss']
13 export class RgwBucketDetailsComponent implements OnChanges {
16 lifecycleProgress: { bucket: string; status: string; started: string };
17 lifecycleProgressMap = new Map<string, { description: string; color: string }>([
18 ['UNINITIAL', { description: $localize`The process has not run yet`, color: 'cool-gray' }],
19 ['PROCESSING', { description: $localize`The process is currently running`, color: 'cyan' }],
20 ['COMPLETE', { description: $localize`The process has completed`, color: 'green' }]
22 lifecycleFormat: 'json' | 'xml' = 'json';
23 aclPermissions: Record<string, string[]> = {};
24 replicationStatus = $localize`Disabled`;
25 bucketRateLimit: RgwRateLimitConfig;
27 constructor(private rgwBucketService: RgwBucketService) {}
30 this.updateBucketDetails(this.extraxtDetailsfromResponse.bind(this));
33 parseXmlAcl(xml: any, bucketOwner: string): Record<string, string[]> {
34 const parser = new xml2js.Parser({ explicitArray: false, trim: true });
35 let data: Record<string, string[]> = {
38 AuthenticatedUsers: ['-']
40 parser.parseString(xml, (err, result) => {
43 const xmlGrantees: any = result['AccessControlPolicy']['AccessControlList']['Grant'];
44 if (Array.isArray(xmlGrantees)) {
45 for (let i = 0; i < xmlGrantees.length; i++) {
46 const grantee = xmlGrantees[i];
47 if (grantee?.Grantee?.URI) {
48 const granteeGroup = grantee.Grantee.URI.split('/').pop();
49 if (data[granteeGroup].includes('-')) {
50 data[granteeGroup] = [grantee?.Permission];
52 data[granteeGroup].push(grantee?.Permission);
55 if (grantee?.Grantee?.ID && bucketOwner === grantee?.Grantee?.ID) {
56 data['Owner'] = grantee?.Permission;
60 if (xmlGrantees?.Grantee?.ID && bucketOwner === xmlGrantees?.Grantee?.ID) {
61 data['Owner'] = xmlGrantees?.Permission;
68 updateBucketDetails(cbFn: Function) {
70 this.rgwBucketService.get(this.selection.bid).subscribe((bucket: object) => {
71 bucket['lock_retention_period_days'] = this.rgwBucketService.getLockDays(bucket);
72 this.selection = bucket;
78 extraxtDetailsfromResponse() {
79 this.aclPermissions = this.parseXmlAcl(this.selection.acl, this.selection.owner);
80 if (this.selection.replication?.['Rule']?.['Status']) {
81 this.replicationStatus = this.selection.replication?.['Rule']?.['Status'];
83 this.rgwBucketService.getBucketRateLimit(this.selection.bid).subscribe((resp: any) => {
84 if (resp && resp.bucket_ratelimit !== undefined) {
85 this.bucketRateLimit = resp.bucket_ratelimit;
88 this.extractLifecycleDetails();
91 extractLifecycleDetails() {
92 if (this.lifecycleFormat === 'json' && !this.selection.lifecycle) {
93 this.selection.lifecycle = {};
95 if (this.selection.lifecycle_progress?.length > 0) {
96 this.selection.lifecycle_progress.forEach(
97 (progress: { bucket: string; status: string; started: string }) => {
98 if (progress.bucket.includes(this.selection.bucket)) {
99 this.lifecycleProgress = progress;