]> git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_object_lock.cc
import ceph quincy 17.2.6
[ceph.git] / 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
3 //
4 #include "rgw_object_lock.h"
5
6 using namespace std;
7
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");
12 }
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");
17 }
18 }
19
20 void DefaultRetention::dump_xml(Formatter *f) const {
21 encode_xml("Mode", mode, f);
22 if (days > 0) {
23 encode_xml("Days", days, f);
24 } else {
25 encode_xml("Years", years, f);
26 }
27 }
28
29 void ObjectLockRule::decode_xml(XMLObj *obj) {
30 RGWXMLDecoder::decode_xml("DefaultRetention", defaultRetention, obj, true);
31 }
32
33 void ObjectLockRule::dump_xml(Formatter *f) const {
34 encode_xml("DefaultRetention", defaultRetention, f);
35 }
36
37 void RGWObjectLock::decode_xml(XMLObj *obj) {
38 string enabled_str;
39 RGWXMLDecoder::decode_xml("ObjectLockEnabled", enabled_str, obj, true);
40 if (enabled_str.compare("Enabled") != 0) {
41 throw RGWXMLDecoder::err("invalid ObjectLockEnabled value");
42 } else {
43 enabled = true;
44 }
45 rule_exist = RGWXMLDecoder::decode_xml("Rule", rule, obj);
46 }
47
48 void RGWObjectLock::dump_xml(Formatter *f) const {
49 if (enabled) {
50 encode_xml("ObjectLockEnabled", "Enabled", f);
51 }
52 if (rule_exist) {
53 encode_xml("Rule", rule, f);
54 }
55 }
56
57 ceph::real_time RGWObjectLock::get_lock_until_date(const ceph::real_time& mtime) const {
58 if (!rule_exist) {
59 return ceph::real_time();
60 }
61 int days = get_days();
62 if (days <= 0) {
63 days = get_years()*365;
64 }
65 return mtime + make_timespan(days*24*60*60);
66 }
67
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");
72 }
73 string date_str;
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");
78 }
79 retain_until_date = *date;
80 }
81
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);
86 }
87
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");
92 }
93 }
94
95 void RGWObjectLegalHold::dump_xml(Formatter *f) const {
96 encode_xml("Status", status, f);
97 }
98
99 bool RGWObjectLegalHold::is_enabled() const {
100 return status.compare("ON") == 0;
101 }