void RGWLifecycleConfiguration::_add_rule(LCRule *rule)
{
- string prefix;
- LCExpiration expiration;
- int days;
- if (!rule->get_prefix(prefix)) {
- ldout(cct, 5) << "ERROR: rule->get_prefix() failed" << dendl;
- }
- if (!rule->get_expiration(expiration)) {
- ldout(cct, 5) << "ERROR: rule->get_expiration() failed" << dendl;
- }
- if (!expiration.get_days(&days)) {
- ldout(cct, 5) << "ERROR: expiration->get_days() failed" << dendl;
- }
- prefix_map[prefix] = days;
+ prefix_map[rule->get_prefix()] = rule->get_expiration().get_days();
}
void *RGWLC::LCWorker::entry() {
void RGWLC::start_processor()
{
worker = new LCWorker(cct, this);
- worker->create("lifecycle_thread");
+ worker->create("lifecycle_thr");
}
void RGWLC::stop_processor()
void dump(Formatter *f) const;
// static void generate_test_instances(list<ACLOwner*>& o);
void set_days(const string& _days) { days = _days; }
- bool get_days(int* _days) {*_days = atoi(days.c_str()); return true; }
+ int get_days() {return atoi(days.c_str()); }
};
WRITE_CLASS_ENCODER(LCExpiration)
return true;
}
- bool get_status(string& _status) {
- _status = status;
- return true;
+ string& get_status() {
+ return status;
}
- bool get_prefix(string& _prefix) {
- _prefix = prefix;
- return true;
+ string& get_prefix() {
+ return prefix;
}
- bool get_expiration(LCExpiration& _expriation) {
- _expriation = expiration;
- return true;
+ LCExpiration& get_expiration() {
+ return expiration;
}
void set_id(string*_id) {
#include "include/types.h"
+#include "rgw_user.h"
#include "rgw_lc_s3.h"
id.clear();
prefix.clear();
status.clear();
-
+
lc_id = static_cast<LCID_S3 *>(find_first("ID"));
if (!lc_id)
return false;
if (!lc_status)
return false;
status = lc_status->get_data();
-
+
lc_expiration = static_cast<LCExpiration_S3 *>(find_first("Expiration"));
if (!lc_expiration)
return false;
}
}
- return 0;
+ return 0;
+}
+
+void RGWLifecycleConfiguration_S3::dump_xml(Formatter *f) const
+{
+ f->open_object_section_in_ns("LifecycleConfiguration", XMLNS_AWS_S3);
+
+ for (auto iter = rule_map.begin(); iter != rule_map.end(); ++iter) {
+ const LCRule_S3& rule = static_cast<const LCRule_S3&>(iter->second);
+ rule.dump_xml(f);
+ }
+
+ f->close_section(); // Lifecycle
}
XMLObj *RGWLCXMLParser_S3::alloc_obj(const char *el)
using namespace std;
-class LCRule_S3 : public LCRule, public XMLObj
-{
-public:
- LCRule_S3() {}
- ~LCRule_S3() {}
-
- void to_xml(CephContext *cct, ostream& out);
- bool xml_end(const char *el);
- bool xml_start(const char *el, const char **attr);
-};
-
class LCID_S3 : public XMLObj
{
public:
void to_xml(ostream& out) {
out << "<Expiration>" << "<Days>" << days << "</Days>"<< "</Expiration>";
}
+ void dump_xml(Formatter *f) const {
+ f->open_object_section("Expiration");
+ encode_xml("Days", days, f);
+ f->close_section(); // Expiration
+ }
+};
+
+class LCRule_S3 : public LCRule, public XMLObj
+{
+public:
+ LCRule_S3() {}
+ ~LCRule_S3() {}
+
+ void to_xml(CephContext *cct, ostream& out);
+ bool xml_end(const char *el);
+ bool xml_start(const char *el, const char **attr);
+ void dump_xml(Formatter *f) const {
+ const LCExpiration_S3& expir = static_cast<const LCExpiration_S3&>(expiration);
+
+ f->open_object_section("Rule");
+ encode_xml("ID", id, f);
+ encode_xml("Prefix", prefix, f);
+ encode_xml("Status", status, f);
+ expir.dump_xml(f);
+ f->close_section(); // Rule
+ }
};
class RGWLCXMLParser_S3 : public RGWXMLParser
{
public:
RGWLifecycleConfiguration_S3(CephContext *_cct) : RGWLifecycleConfiguration(_cct) {}
+ RGWLifecycleConfiguration_S3() : RGWLifecycleConfiguration(NULL) {}
~RGWLifecycleConfiguration_S3() {}
bool xml_end(const char *el);
out << "</LifecycleConfiguration>";
}
int rebuild(RGWRados *store, RGWLifecycleConfiguration& dest);
+ void dump_xml(Formatter *f) const;
};
return 0;
}
+int RGWGetLC::verify_permission()
+{
+ bool perm;
+ perm = verify_bucket_permission(s, RGW_PERM_WRITE_ACP);
+ if (!perm)
+ return -EACCES;
+
+ return 0;
+}
+
int RGWPutLC::verify_permission()
{
bool perm;
rgw_bucket_object_pre_exec(s);
}
+void RGWGetLC::pre_exec()
+{
+ rgw_bucket_object_pre_exec(s);
+}
+
void RGWPutLC::pre_exec()
{
rgw_bucket_object_pre_exec(s);
oid.append(buf);
return;
}
+
void RGWPutLC::execute()
{
bufferlist bl;
#include "rgw_acl.h"
#include "rgw_cors.h"
#include "rgw_quota.h"
+#include "rgw_lc.h"
#include "include/assert.h"
virtual uint32_t op_mask() { return RGW_OP_TYPE_WRITE; }
};
+class RGWGetLC : public RGWOp {
+protected:
+ int ret;
+
+public:
+ RGWGetLC() : ret(0) { }
+ virtual ~RGWGetLC() { }
+
+ int verify_permission();
+ void pre_exec();
+ virtual void execute() = 0;
+
+ virtual void send_response() = 0;
+ virtual const string name() { return "get_lifecycle"; }
+ virtual uint32_t op_mask() { return RGW_OP_TYPE_WRITE; }
+};
+
class RGWPutLC : public RGWOp {
protected:
int ret;
virtual int get_params();
};
+class RGWGetLC_ObjStore : public RGWGetLC {
+public:
+ RGWGetLC_ObjStore() {}
+ ~RGWGetLC_ObjStore() {}
+};
+
class RGWPutLC_ObjStore : public RGWPutLC {
public:
RGWPutLC_ObjStore() {}
dump_start(s);
}
+void RGWGetLC_ObjStore_S3::execute()
+{
+ map<string, bufferlist> bucket_attrs;
+
+ config.set_ctx(s->cct);
+
+ RGWObjectCtx& obj_ctx = *static_cast<RGWObjectCtx *>(s->obj_ctx);
+ int ret = store->get_bucket_info(obj_ctx, s->bucket_tenant, s->bucket_name, s->bucket_info, NULL, &bucket_attrs);
+ if (ret < 0) {
+ ldout(s->cct, 0) << "LC:get_bucket_info failed" << s->bucket_name << dendl;
+ return;
+ }
+
+ map<string, bufferlist>::iterator aiter = bucket_attrs.find(RGW_ATTR_LC);
+ if (aiter == bucket_attrs.end())
+ return;
+
+ bufferlist::iterator iter(&aiter->second);
+ try {
+ config.decode(iter);
+ } catch (const buffer::error& e) {
+ ldout(s->cct, 0) << __func__ << "decode life cycle config failed" << dendl;
+ return;
+ }
+}
+
+void RGWGetLC_ObjStore_S3::send_response()
+{
+ if (ret)
+ set_req_state_err(s, ret);
+ dump_errno(s);
+ end_header(s, this, "application/xml");
+ dump_start(s);
+
+ config.dump_xml(s->formatter);
+ rgw_flush_formatter_and_reset(s, s->formatter);
+}
+
void RGWPutLC_ObjStore_S3::send_response()
{
if (ret)
return new RGWGetRequestPayment_ObjStore_S3;
} else if (s->info.args.exists("uploads")) {
return new RGWListBucketMultiparts_ObjStore_S3;
+ } else if(is_lc_op()) {
+ return new RGWGetLC_ObjStore_S3;
}
return get_obj_op(true);
}
#include "rgw_http_errors.h"
#include "rgw_acl_s3.h"
#include "rgw_policy_s3.h"
+#include "rgw_lc_s3.h"
#include "rgw_keystone.h"
#include "rgw_rest_conn.h"
#include "rgw_ldap.h"
int get_params();
};
+class RGWGetLC_ObjStore_S3 : public RGWGetLC_ObjStore {
+protected:
+ RGWLifecycleConfiguration_S3 config;
+public:
+ RGWGetLC_ObjStore_S3() {}
+ ~RGWGetLC_ObjStore_S3() {}
+ virtual void execute();
+
+ void send_response();
+};
+
class RGWPutLC_ObjStore_S3 : public RGWPutLC_ObjStore {
public:
RGWPutLC_ObjStore_S3() {}