]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_object_lock.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab ft=cpp
4 #include "rgw_object_lock.h"
6 void DefaultRetention::decode_xml(XMLObj
*obj
) {
7 RGWXMLDecoder::decode_xml("Mode", mode
, obj
, true);
8 if (mode
.compare("GOVERNANCE") != 0 && mode
.compare("COMPLIANCE") != 0) {
9 throw RGWXMLDecoder::err("bad Mode in lock rule");
11 bool days_exist
= RGWXMLDecoder::decode_xml("Days", days
, obj
);
12 bool years_exist
= RGWXMLDecoder::decode_xml("Years", years
, obj
);
13 if ((days_exist
&& years_exist
) || (!days_exist
&& !years_exist
)) {
14 throw RGWXMLDecoder::err("either Days or Years must be specified, but not both");
18 void DefaultRetention::dump_xml(Formatter
*f
) const {
19 encode_xml("Mode", mode
, f
);
21 encode_xml("Days", days
, f
);
23 encode_xml("Years", years
, f
);
27 void ObjectLockRule::decode_xml(XMLObj
*obj
) {
28 RGWXMLDecoder::decode_xml("DefaultRetention", defaultRetention
, obj
, true);
31 void ObjectLockRule::dump_xml(Formatter
*f
) const {
32 encode_xml("DefaultRetention", defaultRetention
, f
);
35 void RGWObjectLock::decode_xml(XMLObj
*obj
) {
37 RGWXMLDecoder::decode_xml("ObjectLockEnabled", enabled_str
, obj
, true);
38 if (enabled_str
.compare("Enabled") != 0) {
39 throw RGWXMLDecoder::err("invalid ObjectLockEnabled value");
43 rule_exist
= RGWXMLDecoder::decode_xml("Rule", rule
, obj
);
46 void RGWObjectLock::dump_xml(Formatter
*f
) const {
48 encode_xml("ObjectLockEnabled", "Enabled", f
);
51 encode_xml("Rule", rule
, f
);
55 ceph::real_time
RGWObjectLock::get_lock_until_date(const ceph::real_time
& mtime
) const {
57 return ceph::real_time();
59 int days
= get_days();
61 days
= get_years()*365;
63 return mtime
+ make_timespan(days
*24*60*60);
66 void RGWObjectRetention::decode_xml(XMLObj
*obj
) {
67 RGWXMLDecoder::decode_xml("Mode", mode
, obj
, true);
68 if (mode
.compare("GOVERNANCE") != 0 && mode
.compare("COMPLIANCE") != 0) {
69 throw RGWXMLDecoder::err("bad Mode in retention");
72 RGWXMLDecoder::decode_xml("RetainUntilDate", date_str
, obj
, true);
73 boost::optional
<ceph::real_time
> date
= ceph::from_iso_8601(date_str
);
74 if (boost::none
== date
) {
75 throw RGWXMLDecoder::err("invalid RetainUntilDate value");
77 retain_until_date
= *date
;
80 void RGWObjectRetention::dump_xml(Formatter
*f
) const {
81 encode_xml("Mode", mode
, f
);
82 string date
= ceph::to_iso_8601(retain_until_date
);
83 encode_xml("RetainUntilDate", date
, f
);
86 void RGWObjectLegalHold::decode_xml(XMLObj
*obj
) {
87 RGWXMLDecoder::decode_xml("Status", status
, obj
, true);
88 if (status
.compare("ON") != 0 && status
.compare("OFF") != 0) {
89 throw RGWXMLDecoder::err("bad status in legal hold");
93 void RGWObjectLegalHold::dump_xml(Formatter
*f
) const {
94 encode_xml("Status", status
, f
);
97 bool RGWObjectLegalHold::is_enabled() const {
98 return status
.compare("ON") == 0;