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