]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/blob
451a7dd381118bb7c870176ea6004ffe4e9aa718
[ceph-ci.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
18   constructor(private rgwBucketService: RgwBucketService) {}
19
20   ngOnChanges() {
21     if (this.selection) {
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);
26       });
27     }
28   }
29
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[]> = {
33       Owner: ['-'],
34       AllUsers: ['-'],
35       AuthenticatedUsers: ['-']
36     };
37     parser.parseString(xml, (err, result) => {
38       if (err) return null;
39
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];
48             } else {
49               data[granteeGroup].push(grantee?.Permission);
50             }
51           }
52           if (grantee?.Grantee?.ID && bucketOwner === grantee?.Grantee?.ID) {
53             data['Owner'] = grantee?.Permission;
54           }
55         }
56       } else {
57         if (xmlGrantees?.Grantee?.ID && bucketOwner === xmlGrantees?.Grantee?.ID) {
58           data['Owner'] = xmlGrantees?.Permission;
59         }
60       }
61     });
62     return data;
63   }
64 }