]> git.apps.os.sepia.ceph.com Git - ceph.git/blob
1a709f8644f00dc48cfe84b0ba8acfeded61fcf7
[ceph.git] /
1 import { Component, Input, OnChanges } from '@angular/core';
2
3 import { RgwBucketService } from '~/app/shared/api/rgw-bucket.service';
4
5 import * as xml2js from 'xml2js';
6
7 @Component({
8   selector: 'cd-rgw-bucket-details',
9   templateUrl: './rgw-bucket-details.component.html',
10   styleUrls: ['./rgw-bucket-details.component.scss']
11 })
12 export class RgwBucketDetailsComponent implements OnChanges {
13   @Input()
14   selection: any;
15
16   aclPermissions: Record<string, string[]> = {};
17   replicationStatus = $localize`Disabled`;
18
19   constructor(private rgwBucketService: RgwBucketService) {}
20
21   ngOnChanges() {
22     if (this.selection) {
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'];
29       });
30     }
31   }
32
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[]> = {
36       Owner: ['-'],
37       AllUsers: ['-'],
38       AuthenticatedUsers: ['-']
39     };
40     parser.parseString(xml, (err, result) => {
41       if (err) return null;
42
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];
51             } else {
52               data[granteeGroup].push(grantee?.Permission);
53             }
54           }
55           if (grantee?.Grantee?.ID && bucketOwner === grantee?.Grantee?.ID) {
56             data['Owner'] = grantee?.Permission;
57           }
58         }
59       } else {
60         if (xmlGrantees?.Grantee?.ID && bucketOwner === xmlGrantees?.Grantee?.ID) {
61           data['Owner'] = xmlGrantees?.Permission;
62         }
63       }
64     });
65     return data;
66   }
67 }