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