]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/api/rgw-bucket.service.ts
import ceph quincy 17.2.6
[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 { ApiClient } from '~/app/shared/api/api-client';
9 import { RgwDaemonService } from '~/app/shared/api/rgw-daemon.service';
10 import { cdEncode } from '~/app/shared/decorators/cd-encode';
11
12 @cdEncode
13 @Injectable({
14 providedIn: 'root'
15 })
16 export class RgwBucketService extends ApiClient {
17 private url = 'api/rgw/bucket';
18
19 constructor(private http: HttpClient, private rgwDaemonService: RgwDaemonService) {
20 super();
21 }
22
23 /**
24 * Get the list of buckets.
25 * @return Observable<Object[]>
26 */
27 list(stats: boolean = false, uid: string = '') {
28 return this.rgwDaemonService.request((params: HttpParams) => {
29 params = params.append('stats', stats.toString());
30 if (uid) {
31 params = params.append('uid', uid);
32 }
33 return this.http.get(this.url, {
34 headers: { Accept: this.getVersionHeaderValue(1, 1) },
35 params: params
36 });
37 });
38 }
39
40 get(bucket: string) {
41 return this.rgwDaemonService.request((params: HttpParams) => {
42 return this.http.get(`${this.url}/${bucket}`, { params: params });
43 });
44 }
45
46 create(
47 bucket: string,
48 uid: string,
49 zonegroup: string,
50 placementTarget: string,
51 lockEnabled: boolean,
52 lock_mode: 'GOVERNANCE' | 'COMPLIANCE',
53 lock_retention_period_days: string,
54 encryption_state: boolean,
55 encryption_type: string,
56 key_id: string
57 ) {
58 return this.rgwDaemonService.request((params: HttpParams) => {
59 return this.http.post(this.url, null, {
60 params: new HttpParams({
61 fromObject: {
62 bucket,
63 uid,
64 zonegroup,
65 placement_target: placementTarget,
66 lock_enabled: String(lockEnabled),
67 lock_mode,
68 lock_retention_period_days,
69 encryption_state: String(encryption_state),
70 encryption_type,
71 key_id,
72 daemon_name: params.get('daemon_name')
73 }
74 })
75 });
76 });
77 }
78
79 update(
80 bucket: string,
81 bucketId: string,
82 uid: string,
83 versioningState: string,
84 encryptionState: boolean,
85 encryptionType: string,
86 keyId: string,
87 mfaDelete: string,
88 mfaTokenSerial: string,
89 mfaTokenPin: string,
90 lockMode: 'GOVERNANCE' | 'COMPLIANCE',
91 lockRetentionPeriodDays: string
92 ) {
93 return this.rgwDaemonService.request((params: HttpParams) => {
94 params = params.appendAll({
95 bucket_id: bucketId,
96 uid: uid,
97 versioning_state: versioningState,
98 encryption_state: String(encryptionState),
99 encryption_type: encryptionType,
100 key_id: keyId,
101 mfa_delete: mfaDelete,
102 mfa_token_serial: mfaTokenSerial,
103 mfa_token_pin: mfaTokenPin,
104 lock_mode: lockMode,
105 lock_retention_period_days: lockRetentionPeriodDays
106 });
107 return this.http.put(`${this.url}/${bucket}`, null, { params: params });
108 });
109 }
110
111 delete(bucket: string, purgeObjects = true) {
112 return this.rgwDaemonService.request((params: HttpParams) => {
113 params = params.append('purge_objects', purgeObjects ? 'true' : 'false');
114 return this.http.delete(`${this.url}/${bucket}`, { params: params });
115 });
116 }
117
118 /**
119 * Check if the specified bucket exists.
120 * @param {string} bucket The bucket name to check.
121 * @return Observable<boolean>
122 */
123 exists(bucket: string) {
124 return this.get(bucket).pipe(
125 mapTo(true),
126 catchError((error: Event) => {
127 if (_.isFunction(error.preventDefault)) {
128 error.preventDefault();
129 }
130 return observableOf(false);
131 })
132 );
133 }
134
135 getLockDays(bucketData: object): number {
136 if (bucketData['lock_retention_period_years'] > 0) {
137 return Math.floor(bucketData['lock_retention_period_years'] * 365.242);
138 }
139
140 return bucketData['lock_retention_period_days'] || 0;
141 }
142
143 setEncryptionConfig(
144 encryption_type: string,
145 kms_provider: string,
146 auth_method: string,
147 secret_engine: string,
148 secret_path: string,
149 namespace: string,
150 address: string,
151 token: string,
152 owner: string,
153 ssl_cert: string,
154 client_cert: string,
155 client_key: string
156 ) {
157 return this.rgwDaemonService.request((params: HttpParams) => {
158 params = params.appendAll({
159 encryption_type: encryption_type,
160 kms_provider: kms_provider,
161 auth_method: auth_method,
162 secret_engine: secret_engine,
163 secret_path: secret_path,
164 namespace: namespace,
165 address: address,
166 token: token,
167 owner: owner,
168 ssl_cert: ssl_cert,
169 client_cert: client_cert,
170 client_key: client_key
171 });
172 return this.http.put(`${this.url}/setEncryptionConfig`, null, { params: params });
173 });
174 }
175
176 getEncryption(bucket: string) {
177 return this.rgwDaemonService.request((params: HttpParams) => {
178 return this.http.get(`${this.url}/${bucket}/getEncryption`, { params: params });
179 });
180 }
181
182 deleteEncryption(bucket: string) {
183 return this.rgwDaemonService.request((params: HttpParams) => {
184 return this.http.get(`${this.url}/${bucket}/deleteEncryption`, { params: params });
185 });
186 }
187
188 getEncryptionConfig() {
189 return this.rgwDaemonService.request((params: HttpParams) => {
190 return this.http.get(`${this.url}/getEncryptionConfig`, { params: params });
191 });
192 }
193 }