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