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