]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/api/rgw-bucket.service.ts
import ceph pacific 16.2.5
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / shared / api / rgw-bucket.service.ts
1 import { HttpClient, HttpParams } from '@angular/common/http';
2 import { Injectable } from '@angular/core';
3
4 import _ from 'lodash';
5 import { of as observableOf } from 'rxjs';
6 import { catchError, mapTo } from 'rxjs/operators';
7
8 import { RgwDaemonService } from '~/app/shared/api/rgw-daemon.service';
9 import { cdEncode } from '~/app/shared/decorators/cd-encode';
10
11 @cdEncode
12 @Injectable({
13 providedIn: 'root'
14 })
15 export class RgwBucketService {
16 private url = 'api/rgw/bucket';
17
18 constructor(private http: HttpClient, private rgwDaemonService: RgwDaemonService) {}
19
20 /**
21 * Get the list of buckets.
22 * @return Observable<Object[]>
23 */
24 list() {
25 return this.rgwDaemonService.request((params: HttpParams) => {
26 params = params.append('stats', 'true');
27 return this.http.get(this.url, { params: params });
28 });
29 }
30
31 get(bucket: string) {
32 return this.rgwDaemonService.request((params: HttpParams) => {
33 return this.http.get(`${this.url}/${bucket}`, { params: params });
34 });
35 }
36
37 create(
38 bucket: string,
39 uid: string,
40 zonegroup: string,
41 placementTarget: string,
42 lockEnabled: boolean,
43 lock_mode: 'GOVERNANCE' | 'COMPLIANCE',
44 lock_retention_period_days: string
45 ) {
46 return this.rgwDaemonService.request((params: HttpParams) => {
47 return this.http.post(this.url, null, {
48 params: new HttpParams({
49 fromObject: {
50 bucket,
51 uid,
52 zonegroup,
53 placement_target: placementTarget,
54 lock_enabled: String(lockEnabled),
55 lock_mode,
56 lock_retention_period_days,
57 daemon_name: params.get('daemon_name')
58 }
59 })
60 });
61 });
62 }
63
64 update(
65 bucket: string,
66 bucketId: string,
67 uid: string,
68 versioningState: string,
69 mfaDelete: string,
70 mfaTokenSerial: string,
71 mfaTokenPin: string,
72 lockMode: 'GOVERNANCE' | 'COMPLIANCE',
73 lockRetentionPeriodDays: string
74 ) {
75 return this.rgwDaemonService.request((params: HttpParams) => {
76 params = params.append('bucket_id', bucketId);
77 params = params.append('uid', uid);
78 params = params.append('versioning_state', versioningState);
79 params = params.append('mfa_delete', mfaDelete);
80 params = params.append('mfa_token_serial', mfaTokenSerial);
81 params = params.append('mfa_token_pin', mfaTokenPin);
82 params = params.append('lock_mode', lockMode);
83 params = params.append('lock_retention_period_days', lockRetentionPeriodDays);
84 return this.http.put(`${this.url}/${bucket}`, null, { params: params });
85 });
86 }
87
88 delete(bucket: string, purgeObjects = true) {
89 return this.rgwDaemonService.request((params: HttpParams) => {
90 params = params.append('purge_objects', purgeObjects ? 'true' : 'false');
91 return this.http.delete(`${this.url}/${bucket}`, { params: params });
92 });
93 }
94
95 /**
96 * Check if the specified bucket exists.
97 * @param {string} bucket The bucket name to check.
98 * @return Observable<boolean>
99 */
100 exists(bucket: string) {
101 return this.get(bucket).pipe(
102 mapTo(true),
103 catchError((error: Event) => {
104 if (_.isFunction(error.preventDefault)) {
105 error.preventDefault();
106 }
107 return observableOf(false);
108 })
109 );
110 }
111
112 getLockDays(bucketData: object): number {
113 if (bucketData['lock_retention_period_years'] > 0) {
114 return Math.floor(bucketData['lock_retention_period_years'] * 365.242);
115 }
116
117 return bucketData['lock_retention_period_days'] || 0;
118 }
119 }