]>
Commit | Line | Data |
---|---|---|
9f95a23c TL |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab ft=cpp | |
3 | ||
1e59de90 | 4 | #pragma once |
eafe8130 TL |
5 | |
6 | #include <string> | |
7 | #include "common/ceph_time.h" | |
8 | #include "common/iso_8601.h" | |
9 | #include "rgw_xml.h" | |
10 | ||
11 | class DefaultRetention | |
12 | { | |
13 | protected: | |
20effc67 | 14 | std::string mode; |
eafe8130 TL |
15 | int days; |
16 | int years; | |
17 | ||
18 | public: | |
19 | DefaultRetention(): days(0), years(0) {}; | |
20 | ||
21 | int get_days() const { | |
22 | return days; | |
23 | } | |
24 | ||
25 | int get_years() const { | |
26 | return years; | |
27 | } | |
28 | ||
20effc67 | 29 | std::string get_mode() const { |
eafe8130 TL |
30 | return mode; |
31 | } | |
32 | ||
33 | void encode(bufferlist& bl) const { | |
34 | ENCODE_START(1, 1, bl); | |
35 | encode(mode, bl); | |
36 | encode(days, bl); | |
37 | encode(years, bl); | |
38 | ENCODE_FINISH(bl); | |
39 | } | |
40 | ||
41 | void decode(bufferlist::const_iterator& bl) { | |
42 | DECODE_START(1, bl); | |
43 | decode(mode, bl); | |
44 | decode(days, bl); | |
45 | decode(years, bl); | |
46 | DECODE_FINISH(bl); | |
47 | } | |
48 | ||
49 | void decode_xml(XMLObj *obj); | |
50 | void dump_xml(Formatter *f) const; | |
51 | }; | |
52 | WRITE_CLASS_ENCODER(DefaultRetention) | |
53 | ||
54 | class ObjectLockRule | |
55 | { | |
56 | protected: | |
57 | DefaultRetention defaultRetention; | |
58 | public: | |
59 | int get_days() const { | |
60 | return defaultRetention.get_days(); | |
61 | } | |
62 | ||
63 | int get_years() const { | |
64 | return defaultRetention.get_years(); | |
65 | } | |
66 | ||
20effc67 | 67 | std::string get_mode() const { |
eafe8130 TL |
68 | return defaultRetention.get_mode(); |
69 | } | |
70 | ||
71 | void encode(bufferlist& bl) const { | |
72 | ENCODE_START(1, 1, bl); | |
73 | encode(defaultRetention, bl); | |
74 | ENCODE_FINISH(bl); | |
75 | } | |
76 | ||
77 | void decode(bufferlist::const_iterator& bl) { | |
78 | DECODE_START(1, bl); | |
79 | decode(defaultRetention, bl); | |
80 | DECODE_FINISH(bl); | |
81 | } | |
82 | ||
83 | void decode_xml(XMLObj *obj); | |
84 | void dump_xml(Formatter *f) const; | |
85 | }; | |
86 | WRITE_CLASS_ENCODER(ObjectLockRule) | |
87 | ||
88 | class RGWObjectLock | |
89 | { | |
90 | protected: | |
91 | bool enabled; | |
92 | bool rule_exist; | |
93 | ObjectLockRule rule; | |
94 | ||
95 | public: | |
96 | RGWObjectLock():enabled(true), rule_exist(false) {} | |
97 | ||
98 | int get_days() const { | |
99 | return rule.get_days(); | |
100 | } | |
101 | ||
102 | int get_years() const { | |
103 | return rule.get_years(); | |
104 | } | |
105 | ||
20effc67 | 106 | std::string get_mode() const { |
eafe8130 TL |
107 | return rule.get_mode(); |
108 | } | |
109 | ||
110 | bool retention_period_valid() const { | |
111 | // DefaultRetention requires either Days or Years. | |
112 | // You can't specify both at the same time. | |
113 | // see https://docs.aws.amazon.com/AmazonS3/latest/API/RESTBucketPUTObjectLockConfiguration.html | |
114 | return (get_years() > 0) != (get_days() > 0); | |
115 | } | |
116 | ||
117 | bool has_rule() const { | |
118 | return rule_exist; | |
119 | } | |
120 | ||
121 | void encode(bufferlist& bl) const { | |
122 | ENCODE_START(1, 1, bl); | |
123 | encode(enabled, bl); | |
124 | encode(rule_exist, bl); | |
125 | if (rule_exist) { | |
126 | encode(rule, bl); | |
127 | } | |
128 | ENCODE_FINISH(bl); | |
129 | } | |
130 | ||
131 | void decode(bufferlist::const_iterator& bl) { | |
132 | DECODE_START(1, bl); | |
133 | decode(enabled, bl); | |
134 | decode(rule_exist, bl); | |
135 | if (rule_exist) { | |
136 | decode(rule, bl); | |
137 | } | |
138 | DECODE_FINISH(bl); | |
139 | } | |
140 | ||
141 | void decode_xml(XMLObj *obj); | |
142 | void dump_xml(Formatter *f) const; | |
143 | ceph::real_time get_lock_until_date(const ceph::real_time& mtime) const; | |
144 | }; | |
145 | WRITE_CLASS_ENCODER(RGWObjectLock) | |
146 | ||
147 | class RGWObjectRetention | |
148 | { | |
149 | protected: | |
20effc67 | 150 | std::string mode; |
eafe8130 TL |
151 | ceph::real_time retain_until_date; |
152 | public: | |
153 | RGWObjectRetention() {} | |
20effc67 | 154 | RGWObjectRetention(std::string _mode, ceph::real_time _date): mode(_mode), retain_until_date(_date) {} |
eafe8130 | 155 | |
20effc67 | 156 | void set_mode(std::string _mode) { |
eafe8130 TL |
157 | mode = _mode; |
158 | } | |
159 | ||
20effc67 | 160 | std::string get_mode() const { |
eafe8130 TL |
161 | return mode; |
162 | } | |
163 | ||
164 | void set_retain_until_date(ceph::real_time _retain_until_date) { | |
165 | retain_until_date = _retain_until_date; | |
166 | } | |
167 | ||
168 | ceph::real_time get_retain_until_date() const { | |
169 | return retain_until_date; | |
170 | } | |
171 | ||
172 | void encode(bufferlist& bl) const { | |
f38dd50b | 173 | ENCODE_START(2, 1, bl); |
eafe8130 TL |
174 | encode(mode, bl); |
175 | encode(retain_until_date, bl); | |
f38dd50b | 176 | ceph::round_trip_encode(retain_until_date, bl); |
eafe8130 TL |
177 | ENCODE_FINISH(bl); |
178 | } | |
179 | ||
180 | void decode(bufferlist::const_iterator& bl) { | |
f38dd50b | 181 | DECODE_START(2, bl); |
eafe8130 TL |
182 | decode(mode, bl); |
183 | decode(retain_until_date, bl); | |
f38dd50b TL |
184 | if (struct_v >= 2) { |
185 | ceph::round_trip_decode(retain_until_date, bl); | |
186 | } | |
eafe8130 TL |
187 | DECODE_FINISH(bl); |
188 | } | |
189 | ||
190 | void decode_xml(XMLObj *obj); | |
191 | void dump_xml(Formatter *f) const; | |
192 | }; | |
193 | WRITE_CLASS_ENCODER(RGWObjectRetention) | |
194 | ||
195 | class RGWObjectLegalHold | |
196 | { | |
197 | protected: | |
20effc67 | 198 | std::string status; |
eafe8130 TL |
199 | public: |
200 | RGWObjectLegalHold() {} | |
20effc67 TL |
201 | RGWObjectLegalHold(std::string _status): status(_status) {} |
202 | void set_status(std::string _status) { | |
eafe8130 TL |
203 | status = _status; |
204 | } | |
205 | ||
20effc67 | 206 | std::string get_status() const { |
eafe8130 TL |
207 | return status; |
208 | } | |
209 | ||
210 | void encode(bufferlist& bl) const { | |
211 | ENCODE_START(1, 1, bl); | |
212 | encode(status, bl); | |
213 | ENCODE_FINISH(bl); | |
214 | } | |
215 | ||
216 | void decode(bufferlist::const_iterator& bl) { | |
217 | DECODE_START(1, bl); | |
218 | decode(status, bl); | |
219 | DECODE_FINISH(bl); | |
220 | } | |
221 | ||
222 | void decode_xml(XMLObj *obj); | |
223 | void dump_xml(Formatter *f) const; | |
224 | bool is_enabled() const; | |
225 | }; | |
226 | WRITE_CLASS_ENCODER(RGWObjectLegalHold) |