]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw/user: add 'create_date' to RGWAccessKey
authorCasey Bodley <cbodley@redhat.com>
Wed, 20 Dec 2023 16:25:03 +0000 (11:25 -0500)
committerCasey Bodley <cbodley@redhat.com>
Fri, 12 Apr 2024 19:34:27 +0000 (15:34 -0400)
Signed-off-by: Casey Bodley <cbodley@redhat.com>
(cherry picked from commit c51b910e47ce784f086714ea8179b10620d78801)

src/rgw/driver/rados/rgw_user.cc
src/rgw/rgw_acl_types.h
src/rgw/rgw_common.cc

index 01fa37fdf7cd37deb9f65b25affdd69bd7a7c3de..ee6e3157293cf19acb8c5ded062f1c05c0bb4f3d 100644 (file)
@@ -533,7 +533,6 @@ int RGWAccessKeyPool::generate_key(const DoutPrefixProvider *dpp, RGWUserAdminOp
   std::string id;
   std::string key;
 
-  std::pair<std::string, RGWAccessKey> key_pair;
   RGWAccessKey new_key;
   std::unique_ptr<rgw::sal::User> duplicate_check;
 
@@ -618,13 +617,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;
@@ -688,6 +690,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;
index 3f9f1715aba435e18be25bf1fb8cea19a19c8602..d844567c344368a053cfca43b22ca89c7f87a25f 100644 (file)
@@ -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;
index c680b3d9b56a2c8162a09aa8dc2a46cf2eb44d2d..905d34f48eb11c204d762d1190d15e79f9902c56 100644 (file)
@@ -2971,6 +2971,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
@@ -2992,6 +2993,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) {
@@ -3006,6 +3008,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) {
@@ -3023,6 +3026,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);
 }