]> git.proxmox.com Git - ceph.git/blame - ceph/src/rgw/rgw_object_lock.h
bump version to 19.2.0-pve1
[ceph.git] / ceph / src / rgw / rgw_object_lock.h
CommitLineData
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
11class DefaultRetention
12{
13protected:
20effc67 14 std::string mode;
eafe8130
TL
15 int days;
16 int years;
17
18public:
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 }
f51cf556 48 void dump(Formatter *f) const;
eafe8130
TL
49 void decode_xml(XMLObj *obj);
50 void dump_xml(Formatter *f) const;
51};
52WRITE_CLASS_ENCODER(DefaultRetention)
53
54class ObjectLockRule
55{
56protected:
57 DefaultRetention defaultRetention;
58public:
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;
f51cf556
TL
85 void dump(Formatter *f) const;
86 static void generate_test_instances(std::list<ObjectLockRule*>& o);
eafe8130
TL
87};
88WRITE_CLASS_ENCODER(ObjectLockRule)
89
90class RGWObjectLock
91{
92protected:
93 bool enabled;
94 bool rule_exist;
95 ObjectLockRule rule;
96
97public:
98 RGWObjectLock():enabled(true), rule_exist(false) {}
99
100 int get_days() const {
101 return rule.get_days();
102 }
103
104 int get_years() const {
105 return rule.get_years();
106 }
107
20effc67 108 std::string get_mode() const {
eafe8130
TL
109 return rule.get_mode();
110 }
111
112 bool retention_period_valid() const {
113 // DefaultRetention requires either Days or Years.
114 // You can't specify both at the same time.
115 // see https://docs.aws.amazon.com/AmazonS3/latest/API/RESTBucketPUTObjectLockConfiguration.html
116 return (get_years() > 0) != (get_days() > 0);
117 }
118
119 bool has_rule() const {
120 return rule_exist;
121 }
122
123 void encode(bufferlist& bl) const {
124 ENCODE_START(1, 1, bl);
125 encode(enabled, bl);
126 encode(rule_exist, bl);
127 if (rule_exist) {
128 encode(rule, bl);
129 }
130 ENCODE_FINISH(bl);
131 }
132
133 void decode(bufferlist::const_iterator& bl) {
134 DECODE_START(1, bl);
135 decode(enabled, bl);
136 decode(rule_exist, bl);
137 if (rule_exist) {
138 decode(rule, bl);
139 }
140 DECODE_FINISH(bl);
141 }
142
143 void decode_xml(XMLObj *obj);
144 void dump_xml(Formatter *f) const;
145 ceph::real_time get_lock_until_date(const ceph::real_time& mtime) const;
f51cf556
TL
146 void dump(Formatter *f) const;
147 static void generate_test_instances(std::list<RGWObjectLock*>& o);
eafe8130
TL
148};
149WRITE_CLASS_ENCODER(RGWObjectLock)
150
151class RGWObjectRetention
152{
153protected:
20effc67 154 std::string mode;
eafe8130
TL
155 ceph::real_time retain_until_date;
156public:
157 RGWObjectRetention() {}
20effc67 158 RGWObjectRetention(std::string _mode, ceph::real_time _date): mode(_mode), retain_until_date(_date) {}
eafe8130 159
20effc67 160 void set_mode(std::string _mode) {
eafe8130
TL
161 mode = _mode;
162 }
163
20effc67 164 std::string get_mode() const {
eafe8130
TL
165 return mode;
166 }
167
168 void set_retain_until_date(ceph::real_time _retain_until_date) {
169 retain_until_date = _retain_until_date;
170 }
171
172 ceph::real_time get_retain_until_date() const {
173 return retain_until_date;
174 }
175
176 void encode(bufferlist& bl) const {
f38dd50b 177 ENCODE_START(2, 1, bl);
eafe8130
TL
178 encode(mode, bl);
179 encode(retain_until_date, bl);
f38dd50b 180 ceph::round_trip_encode(retain_until_date, bl);
eafe8130
TL
181 ENCODE_FINISH(bl);
182 }
183
184 void decode(bufferlist::const_iterator& bl) {
f38dd50b 185 DECODE_START(2, bl);
eafe8130
TL
186 decode(mode, bl);
187 decode(retain_until_date, bl);
f38dd50b
TL
188 if (struct_v >= 2) {
189 ceph::round_trip_decode(retain_until_date, bl);
190 }
eafe8130
TL
191 DECODE_FINISH(bl);
192 }
193
194 void decode_xml(XMLObj *obj);
195 void dump_xml(Formatter *f) const;
196};
197WRITE_CLASS_ENCODER(RGWObjectRetention)
198
199class RGWObjectLegalHold
200{
201protected:
20effc67 202 std::string status;
eafe8130
TL
203public:
204 RGWObjectLegalHold() {}
20effc67
TL
205 RGWObjectLegalHold(std::string _status): status(_status) {}
206 void set_status(std::string _status) {
eafe8130
TL
207 status = _status;
208 }
209
20effc67 210 std::string get_status() const {
eafe8130
TL
211 return status;
212 }
213
214 void encode(bufferlist& bl) const {
215 ENCODE_START(1, 1, bl);
216 encode(status, bl);
217 ENCODE_FINISH(bl);
218 }
219
220 void decode(bufferlist::const_iterator& bl) {
221 DECODE_START(1, bl);
222 decode(status, bl);
223 DECODE_FINISH(bl);
224 }
225
226 void decode_xml(XMLObj *obj);
227 void dump_xml(Formatter *f) const;
228 bool is_enabled() const;
229};
230WRITE_CLASS_ENCODER(RGWObjectLegalHold)