1 import { HttpClient, HttpParams } from '@angular/common/http';
2 import { Injectable } from '@angular/core';
4 import _ from 'lodash';
5 import { of as observableOf } from 'rxjs';
6 import { catchError, mapTo } from 'rxjs/operators';
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';
16 export class RgwBucketService extends ApiClient {
17 private url = 'api/rgw/bucket';
19 constructor(private http: HttpClient, private rgwDaemonService: RgwDaemonService) {
24 * Get the list of buckets.
25 * @return Observable<Object[]>
27 list(stats: boolean = false, uid: string = '') {
28 return this.rgwDaemonService.request((params: HttpParams) => {
29 params = params.append('stats', stats.toString());
31 params = params.append('uid', uid);
33 return this.http.get(this.url, {
34 headers: { Accept: this.getVersionHeaderValue(1, 1) },
41 return this.rgwDaemonService.request((params: HttpParams) => {
42 return this.http.get(`${this.url}/${bucket}`, { params: params });
50 placementTarget: string,
52 lock_mode: 'GOVERNANCE' | 'COMPLIANCE',
53 lock_retention_period_days: string,
54 encryption_state: boolean,
55 encryption_type: string,
58 return this.rgwDaemonService.request((params: HttpParams) => {
59 return this.http.post(this.url, null, {
60 params: new HttpParams({
65 placement_target: placementTarget,
66 lock_enabled: String(lockEnabled),
68 lock_retention_period_days,
69 encryption_state: String(encryption_state),
72 daemon_name: params.get('daemon_name')
83 versioningState: string,
84 encryptionState: boolean,
85 encryptionType: string,
88 mfaTokenSerial: string,
90 lockMode: 'GOVERNANCE' | 'COMPLIANCE',
91 lockRetentionPeriodDays: string
93 return this.rgwDaemonService.request((params: HttpParams) => {
94 params = params.appendAll({
97 versioning_state: versioningState,
98 encryption_state: String(encryptionState),
99 encryption_type: encryptionType,
101 mfa_delete: mfaDelete,
102 mfa_token_serial: mfaTokenSerial,
103 mfa_token_pin: mfaTokenPin,
105 lock_retention_period_days: lockRetentionPeriodDays
107 return this.http.put(`${this.url}/${bucket}`, null, { params: params });
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 });
119 * Check if the specified bucket exists.
120 * @param {string} bucket The bucket name to check.
121 * @return Observable<boolean>
123 exists(bucket: string) {
124 return this.get(bucket).pipe(
126 catchError((error: Event) => {
127 if (_.isFunction(error.preventDefault)) {
128 error.preventDefault();
130 return observableOf(false);
135 getLockDays(bucketData: object): number {
136 if (bucketData['lock_retention_period_years'] > 0) {
137 return Math.floor(bucketData['lock_retention_period_years'] * 365.242);
140 return bucketData['lock_retention_period_days'] || 0;
144 encryption_type: string,
145 kms_provider: string,
147 secret_engine: string,
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,
169 client_cert: client_cert,
170 client_key: client_key
172 return this.http.put(`${this.url}/setEncryptionConfig`, null, { params: params });
176 getEncryption(bucket: string) {
177 return this.rgwDaemonService.request((params: HttpParams) => {
178 return this.http.get(`${this.url}/${bucket}/getEncryption`, { params: params });
182 deleteEncryption(bucket: string) {
183 return this.rgwDaemonService.request((params: HttpParams) => {
184 return this.http.get(`${this.url}/${bucket}/deleteEncryption`, { params: params });
188 getEncryptionConfig() {
189 return this.rgwDaemonService.request((params: HttpParams) => {
190 return this.http.get(`${this.url}/getEncryptionConfig`, { params: params });