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[]> = {};
18 constructor(private rgwBucketService: RgwBucketService) {}
22 this.rgwBucketService.get(this.selection.bid).subscribe((bucket: object) => {
23 bucket['lock_retention_period_days'] = this.rgwBucketService.getLockDays(bucket);
24 this.selection = bucket;
25 this.aclPermissions = this.parseXmlAcl(this.selection.acl, this.selection.owner);
30 parseXmlAcl(xml: any, bucketOwner: string): Record<string, string[]> {
31 const parser = new xml2js.Parser({ explicitArray: false, trim: true });
32 let data: Record<string, string[]> = {
35 AuthenticatedUsers: ['-']
37 parser.parseString(xml, (err, result) => {
40 const xmlGrantees: any = result['AccessControlPolicy']['AccessControlList']['Grant'];
41 if (Array.isArray(xmlGrantees)) {
42 for (let i = 0; i < xmlGrantees.length; i++) {
43 const grantee = xmlGrantees[i];
44 if (grantee?.Grantee?.URI) {
45 const granteeGroup = grantee.Grantee.URI.split('/').pop();
46 if (data[granteeGroup].includes('-')) {
47 data[granteeGroup] = [grantee?.Permission];
49 data[granteeGroup].push(grantee?.Permission);
52 if (grantee?.Grantee?.ID && bucketOwner === grantee?.Grantee?.ID) {
53 data['Owner'] = grantee?.Permission;
57 if (xmlGrantees?.Grantee?.ID && bucketOwner === xmlGrantees?.Grantee?.ID) {
58 data['Owner'] = xmlGrantees?.Permission;