1 import { Component, Input, OnChanges } from '@angular/core';
3 import { RgwBucketService } from '~/app/shared/api/rgw-bucket.service';
5 import * as xml2js from 'xml2js';
8 selector: 'cd-rgw-bucket-details',
9 templateUrl: './rgw-bucket-details.component.html',
10 styleUrls: ['./rgw-bucket-details.component.scss']
12 export class RgwBucketDetailsComponent implements OnChanges {
16 aclPermissions: Record<string, string[]> = {};
17 replicationStatus = $localize`Disabled`;
19 constructor(private rgwBucketService: RgwBucketService) {}
23 this.rgwBucketService.get(this.selection.bid).subscribe((bucket: object) => {
24 bucket['lock_retention_period_days'] = this.rgwBucketService.getLockDays(bucket);
25 this.selection = bucket;
26 this.aclPermissions = this.parseXmlAcl(this.selection.acl, this.selection.owner);
27 if (this.selection.replication?.['Rule']?.['Status'])
28 this.replicationStatus = this.selection.replication?.['Rule']?.['Status'];
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;