From c51b910e47ce784f086714ea8179b10620d78801 Mon Sep 17 00:00:00 2001 From: Casey Bodley Date: Wed, 20 Dec 2023 11:25:03 -0500 Subject: [PATCH] rgw/user: add 'create_date' to RGWAccessKey Signed-off-by: Casey Bodley --- src/rgw/driver/rados/rgw_user.cc | 15 ++++++++++----- src/rgw/rgw_acl_types.h | 9 +++++++-- src/rgw/rgw_common.cc | 4 ++++ 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/rgw/driver/rados/rgw_user.cc b/src/rgw/driver/rados/rgw_user.cc index 4f221b1a50c..8af0947560e 100644 --- a/src/rgw/driver/rados/rgw_user.cc +++ b/src/rgw/driver/rados/rgw_user.cc @@ -537,7 +537,6 @@ int RGWAccessKeyPool::generate_key(const DoutPrefixProvider *dpp, RGWUserAdminOp std::string id; std::string key; - std::pair key_pair; RGWAccessKey new_key; std::unique_ptr duplicate_check; @@ -622,13 +621,16 @@ int RGWAccessKeyPool::generate_key(const DoutPrefixProvider *dpp, RGWUserAdminOp new_key.id = id; new_key.key = key; - key_pair.first = id; - key_pair.second = new_key; + if (op_state.create_date) { + new_key.create_date = *op_state.create_date; + } else { + new_key.create_date = ceph::real_clock::now(); + } if (key_type == KEY_TYPE_S3) { - access_keys->insert(key_pair); + access_keys->emplace(id, new_key); } else if (key_type == KEY_TYPE_SWIFT) { - swift_keys->insert(key_pair); + swift_keys->emplace(id, new_key); } return 0; @@ -692,6 +694,9 @@ int RGWAccessKeyPool::modify_key(RGWUserAdminOpState& op_state, std::string *err if (op_state.access_key_active) { modify_key.active = *op_state.access_key_active; } + if (op_state.create_date) { + modify_key.create_date = *op_state.create_date; + } if (key_type == KEY_TYPE_S3) { (*access_keys)[id] = modify_key; diff --git a/src/rgw/rgw_acl_types.h b/src/rgw/rgw_acl_types.h index 3f9f1715aba..d844567c344 100644 --- a/src/rgw/rgw_acl_types.h +++ b/src/rgw/rgw_acl_types.h @@ -46,28 +46,33 @@ struct RGWAccessKey { std::string key; // SecretKey std::string subuser; bool active = true; + ceph::real_time create_date; RGWAccessKey() {} RGWAccessKey(std::string _id, std::string _key) : id(std::move(_id)), key(std::move(_key)) {} void encode(bufferlist& bl) const { - ENCODE_START(3, 2, bl); + ENCODE_START(4, 2, bl); encode(id, bl); encode(key, bl); encode(subuser, bl); encode(active, bl); + encode(create_date, bl); ENCODE_FINISH(bl); } void decode(bufferlist::const_iterator& bl) { - DECODE_START_LEGACY_COMPAT_LEN_32(3, 2, 2, bl); + DECODE_START_LEGACY_COMPAT_LEN_32(4, 2, 2, bl); decode(id, bl); decode(key, bl); decode(subuser, bl); if (struct_v >= 3) { decode(active, bl); } + if (struct_v >= 4) { + decode(create_date, bl); + } DECODE_FINISH(bl); } void dump(Formatter *f) const; diff --git a/src/rgw/rgw_common.cc b/src/rgw/rgw_common.cc index 05b58e3a2d9..4421c6b566d 100644 --- a/src/rgw/rgw_common.cc +++ b/src/rgw/rgw_common.cc @@ -2972,6 +2972,7 @@ void RGWAccessKey::dump(Formatter *f) const encode_json("secret_key", key, f); encode_json("subuser", subuser, f); encode_json("active", active, f); + encode_json("create_date", create_date, f); } void RGWAccessKey::dump_plain(Formatter *f) const @@ -2993,6 +2994,7 @@ void RGWAccessKey::dump(Formatter *f, const string& user, bool swift) const } encode_json("secret_key", key, f); encode_json("active", active, f); + encode_json("create_date", create_date, f); } void RGWAccessKey::decode_json(JSONObj *obj) { @@ -3007,6 +3009,7 @@ void RGWAccessKey::decode_json(JSONObj *obj) { } } JSONDecoder::decode_json("active", active, obj); + JSONDecoder::decode_json("create_date", create_date, obj); } void RGWAccessKey::decode_json(JSONObj *obj, bool swift) { @@ -3024,6 +3027,7 @@ void RGWAccessKey::decode_json(JSONObj *obj, bool swift) { } JSONDecoder::decode_json("secret_key", key, obj, true); JSONDecoder::decode_json("active", active, obj); + JSONDecoder::decode_json("create_date", create_date, obj); } -- 2.39.5