From f7b32011061f031ce9bdf1c08d28dc3c62022cfd Mon Sep 17 00:00:00 2001 From: Radoslaw Zarzynski Date: Mon, 11 Jan 2016 19:27:21 +0100 Subject: [PATCH] rgw: add support for putting Swift account ACLs. Signed-off-by: Radoslaw Zarzynski --- src/rgw/rgw_op.cc | 6 ++++++ src/rgw/rgw_op.h | 4 +++- src/rgw/rgw_rest_swift.cc | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index 785c1a8272ac6..76fd4d2c78543 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -2951,6 +2951,12 @@ int RGWPutMetadataAccount::init_processing() return op_ret; } + if (has_policy) { + bufferlist acl_bl; + policy.encode(acl_bl); + attrs.emplace(RGW_ATTR_ACL, std::move(acl_bl)); + } + rgw_get_request_metadata(s->cct, s->info, attrs, false); prepare_add_del_attrs(orig_attrs, rmattr_names, attrs); populate_with_generic_attrs(s, attrs); diff --git a/src/rgw/rgw_op.h b/src/rgw/rgw_op.h index 7bc6f84a21482..4993ef165c672 100644 --- a/src/rgw/rgw_op.h +++ b/src/rgw/rgw_op.h @@ -754,10 +754,12 @@ protected: RGWObjVersionTracker acct_op_tracker; RGWAccessControlPolicy policy; + bool has_policy; public: RGWPutMetadataAccount() - : new_quota_extracted(false) { + : new_quota_extracted(false), + has_policy(false) { } virtual void init(RGWRados *store, struct req_state *s, RGWHandler *h) { diff --git a/src/rgw/rgw_rest_swift.cc b/src/rgw/rgw_rest_swift.cc index bfe80f9f3bc3e..b4430783425ff 100644 --- a/src/rgw/rgw_rest_swift.cc +++ b/src/rgw/rgw_rest_swift.cc @@ -756,12 +756,47 @@ void RGWPutObj_ObjStore_SWIFT::send_response() rgw_flush_formatter_and_reset(s, s->formatter); } +static int get_swift_account_settings(req_state * const s, + RGWRados * const store, + RGWAccessControlPolicy_SWIFTAcct * const policy, + bool * const has_policy) +{ + *has_policy = false; + + const char * const acl_attr = s->info.env->get("HTTP_X_ACCOUNT_ACCESS_CONTROL"); + if (acl_attr) { + RGWAccessControlPolicy_SWIFTAcct swift_acct_policy(s->cct); + int r = swift_acct_policy.create(store, + s->user->user_id, + s->user->display_name, + string(acl_attr)); + if (r < 0) { + return r; + } + + *policy = swift_acct_policy; + *has_policy = true; + } + + return 0; +} + int RGWPutMetadataAccount_ObjStore_SWIFT::get_params() { if (s->has_bad_meta) { return -EINVAL; } + int ret = get_swift_account_settings(s, + store, + // FIXME: we need to carry unique_ptr in generic class + // and allocate appropriate ACL class in the ctor + static_cast(&policy), + &has_policy); + if (ret < 0) { + return ret; + } + get_rmattrs_from_headers(s, ACCT_PUT_ATTR_PREFIX, ACCT_REMOVE_ATTR_PREFIX, rmattr_names); return 0; -- 2.39.5