From: Yehuda Sadeh Date: Thu, 23 Nov 2017 00:25:41 +0000 (-0800) Subject: rgw: trivial implementation of otp meta handlers X-Git-Tag: v13.1.0~343^2~18 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=45ee591d144ac829db0a8e05868a325d34b7f672;p=ceph-ci.git rgw: trivial implementation of otp meta handlers Still not there yet. Need to tie into objv_tracker, and metadata log tooling. Signed-off-by: Yehuda Sadeh --- diff --git a/src/cls/otp/cls_otp_types.cc b/src/cls/otp/cls_otp_types.cc index 98c4d2560c4..a73b74e997c 100644 --- a/src/cls/otp/cls_otp_types.cc +++ b/src/cls/otp/cls_otp_types.cc @@ -12,6 +12,7 @@ * */ +#include "objclass/objclass.h" #include "common/Formatter.h" #include "common/Clock.h" #include "common/ceph_json.h" @@ -32,3 +33,16 @@ void otp_info_t::dump(Formatter *f) const encode_json("window", window, f); } +void otp_info_t::decode_json(JSONObj *obj) +{ + int t{-1}; + JSONDecoder::decode_json("type", t, obj); + type = (OTPType)t; + JSONDecoder::decode_json("id", id, obj); + JSONDecoder::decode_json("seed", seed, obj); + utime_t to; + JSONDecoder::decode_json("time_ofs", to, obj); + time_ofs = to.to_real_time(); + JSONDecoder::decode_json("step_size", step_size, obj); + JSONDecoder::decode_json("window", window, obj); +} diff --git a/src/cls/otp/cls_otp_types.h b/src/cls/otp/cls_otp_types.h index 29b9837dacc..7810461e60b 100644 --- a/src/cls/otp/cls_otp_types.h +++ b/src/cls/otp/cls_otp_types.h @@ -7,6 +7,7 @@ #define CLS_OTP_MAX_REPO_SIZE 100 +class JSONObj; namespace rados { namespace cls { @@ -53,6 +54,7 @@ namespace rados { DECODE_FINISH(bl); } void dump(Formatter *f) const; + void decode_json(JSONObj *obj); }; WRITE_CLASS_ENCODER(rados::cls::otp::otp_info_t) diff --git a/src/rgw/rgw_otp.cc b/src/rgw/rgw_otp.cc index cec7e0662a5..d2ad93b2243 100644 --- a/src/rgw/rgw_otp.cc +++ b/src/rgw/rgw_otp.cc @@ -25,37 +25,17 @@ using namespace std; static RGWMetadataHandler *otp_meta_handler = NULL; -struct RGWUserCompleteInfo { - RGWUserInfo info; - map attrs; - bool has_attrs; - - RGWUserCompleteInfo() - : has_attrs(false) - {} - - void dump(Formatter * const f) const { - info.dump(f); - encode_json("attrs", attrs, f); - } - - void decode_json(JSONObj *obj) { - decode_json_obj(info, obj); - has_attrs = JSONDecoder::decode_json("attrs", attrs, obj); - } -}; - -class RGWUserMetadataObject : public RGWMetadataObject { - RGWUserCompleteInfo uci; +class RGWOTPMetadataObject : public RGWMetadataObject { + list result; public: - RGWUserMetadataObject(const RGWUserCompleteInfo& _uci, obj_version& v, real_time m) - : uci(_uci) { + RGWOTPMetadataObject(list& _result, obj_version& v, real_time m) { + result.swap(_result); objv = v; mtime = m; } void dump(Formatter *f) const override { - uci.dump(f); + encode_json("devices", result, f); } }; @@ -64,28 +44,37 @@ public: string get_type() override { return "otp"; } int get(RGWRados *store, string& entry, RGWMetadataObject **obj) override { -#if 0 - RGWUserCompleteInfo uci; RGWObjVersionTracker objv_tracker; real_time mtime; - rgw_user uid(entry); - - int ret = rgw_get_user_info_by_uid(store, uid, uci.info, &objv_tracker, - &mtime, NULL, &uci.attrs); - if (ret < 0) { - return ret; + list result; + int r = store->list_mfa(entry, &result); + if (r < 0) { + return r; } - RGWUserMetadataObject *mdo = new RGWUserMetadataObject(uci, objv_tracker.read_version, mtime); + RGWOTPMetadataObject *mdo = new RGWOTPMetadataObject(result, objv_tracker.read_version, mtime); *obj = mdo; - -#endif - return -ENOTSUP; + return 0; } int put(RGWRados *store, string& entry, RGWObjVersionTracker& objv_tracker, real_time mtime, JSONObj *obj, sync_type_t sync_mode) override { + + list devices; + try { + JSONDecoder::decode_json("devices", devices, obj); + } catch (JSONDecoder::err& e) { + return -EINVAL; + } + + int r = store->set_mfa(entry, devices, true); + if (r < 0) { + return r; + } + + return STATUS_APPLIED; + #if 0 RGWUserCompleteInfo uci; @@ -122,35 +111,22 @@ public: return STATUS_APPLIED; #endif - return -ENOTSUP; } - struct list_keys_info { - RGWRados *store; - RGWListRawObjsCtx ctx; - }; - int remove(RGWRados *store, string& entry, RGWObjVersionTracker& objv_tracker) override { - RGWUserInfo info; - -#warning FIXME -#if 0 - rgw_user uid(entry); - - int ret = rgw_get_user_info_by_uid(store, uid, info, &objv_tracker); - if (ret < 0) - return ret; - - return rgw_delete_user(store, info, objv_tracker); -#endif - return -ENOTSUP; + return store->meta_mgr->remove_entry(this, entry, &objv_tracker); } void get_pool_and_oid(RGWRados *store, const string& key, rgw_pool& pool, string& oid) override { oid = key; - pool = store->get_zone_params().user_uid_pool; + pool = store->get_zone_params().otp_pool; } + struct list_keys_info { + RGWRados *store; + RGWListRawObjsCtx ctx; + }; + int list_keys_init(RGWRados *store, const string& marker, void **phandle) override { auto info = ceph::make_unique(); diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index 106167ba488..18f5075c504 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -14262,3 +14262,44 @@ int RGWRados::list_mfa(const rgw_user& user, list * return 0; } +int RGWRados::set_mfa(const string& oid, const list& entries, bool reset_obj) +{ + rgw_raw_obj obj(get_zone_params().otp_pool, oid); + rgw_rados_ref ref; + int r = get_system_obj_ref(obj, &ref); + if (r < 0) { + return r; + } + + librados::ObjectWriteOperation op; + if (reset_obj) { + op.remove(); + op.set_op_flags2(LIBRADOS_OP_FLAG_FAILOK); + op.create(false); + } + rados::cls::otp::OTP::set(&op, entries); + r = ref.ioctx.operate(ref.oid, &op); + if (r < 0) { + ldout(cct, 20) << "OTP set entries.size()=" << entries.size() << " result=" << (int)r << dendl; + return r; + } + + return 0; +} + +int RGWRados::list_mfa(const string& oid, list *result) +{ + rgw_raw_obj obj(get_zone_params().otp_pool, oid); + rgw_rados_ref ref; + int r = get_system_obj_ref(obj, &ref); + if (r < 0) { + return r; + } + r = rados::cls::otp::OTP::get_all(ref.ioctx, ref.oid, result); + if (r < 0) { + return r; + } + + return 0; +} + diff --git a/src/rgw/rgw_rados.h b/src/rgw/rgw_rados.h index 48217675089..6d1a639e0fb 100644 --- a/src/rgw/rgw_rados.h +++ b/src/rgw/rgw_rados.h @@ -3722,6 +3722,10 @@ public: int remove_mfa(const rgw_user& user, const string& id); int get_mfa(const rgw_user& user, const string& id, rados::cls::otp::otp_info_t *result); int list_mfa(const rgw_user& user, list *result); + + /* mfa interfaces used by metadata engine */ + int set_mfa(const string& oid, const list& entries, bool reset_obj); + int list_mfa(const string& oid, list *result); private: /** * This is a helper method, it generates a list of bucket index objects with the given