]>
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"
8 void DefaultRetention::decode_xml(XMLObj
*obj
) {
9 RGWXMLDecoder::decode_xml("Mode", mode
, obj
, true);
10 if (mode
.compare("GOVERNANCE") != 0 && mode
.compare("COMPLIANCE") != 0) {
11 throw RGWXMLDecoder::err("bad Mode in lock rule");
13 bool days_exist
= RGWXMLDecoder::decode_xml("Days", days
, obj
);
14 bool years_exist
= RGWXMLDecoder::decode_xml("Years", years
, obj
);
15 if ((days_exist
&& years_exist
) || (!days_exist
&& !years_exist
)) {
16 throw RGWXMLDecoder::err("either Days or Years must be specified, but not both");
20 void DefaultRetention::dump_xml(Formatter
*f
) const {
21 encode_xml("Mode", mode
, f
);
23 encode_xml("Days", days
, f
);
25 encode_xml("Years", years
, f
);
29 void ObjectLockRule::decode_xml(XMLObj
*obj
) {
30 RGWXMLDecoder::decode_xml("DefaultRetention", defaultRetention
, obj
, true);
33 void ObjectLockRule::dump_xml(Formatter
*f
) const {
34 encode_xml("DefaultRetention", defaultRetention
, f
);
37 void RGWObjectLock::decode_xml(XMLObj
*obj
) {
39 RGWXMLDecoder::decode_xml("ObjectLockEnabled", enabled_str
, obj
, true);
40 if (enabled_str
.compare("Enabled") != 0) {
41 throw RGWXMLDecoder::err("invalid ObjectLockEnabled value");
45 rule_exist
= RGWXMLDecoder::decode_xml("Rule", rule
, obj
);
48 void RGWObjectLock::dump_xml(Formatter
*f
) const {
50 encode_xml("ObjectLockEnabled", "Enabled", f
);
53 encode_xml("Rule", rule
, f
);
57 ceph::real_time
RGWObjectLock::get_lock_until_date(const ceph::real_time
& mtime
) const {
59 return ceph::real_time();
61 int days
= get_days();
63 days
= get_years()*365;
65 return mtime
+ make_timespan(days
*24*60*60);
68 void RGWObjectRetention::decode_xml(XMLObj
*obj
) {
69 RGWXMLDecoder::decode_xml("Mode", mode
, obj
, true);
70 if (mode
.compare("GOVERNANCE") != 0 && mode
.compare("COMPLIANCE") != 0) {
71 throw RGWXMLDecoder::err("bad Mode in retention");
74 RGWXMLDecoder::decode_xml("RetainUntilDate", date_str
, obj
, true);
75 boost::optional
<ceph::real_time
> date
= ceph::from_iso_8601(date_str
);
76 if (boost::none
== date
) {
77 throw RGWXMLDecoder::err("invalid RetainUntilDate value");
79 retain_until_date
= *date
;
82 void RGWObjectRetention::dump_xml(Formatter
*f
) const {
83 encode_xml("Mode", mode
, f
);
84 string date
= ceph::to_iso_8601(retain_until_date
);
85 encode_xml("RetainUntilDate", date
, f
);
88 void RGWObjectLegalHold::decode_xml(XMLObj
*obj
) {
89 RGWXMLDecoder::decode_xml("Status", status
, obj
, true);
90 if (status
.compare("ON") != 0 && status
.compare("OFF") != 0) {
91 throw RGWXMLDecoder::err("bad status in legal hold");
95 void RGWObjectLegalHold::dump_xml(Formatter
*f
) const {
96 encode_xml("Status", status
, f
);
99 bool RGWObjectLegalHold::is_enabled() const {
100 return status
.compare("ON") == 0;