# HG changeset patch # User Kim Alvefur # Date 1697312461 -7200 # Node ID c74a96dc5d58eabb07f600dee03a1fbac249d78e # Parent c8322c64a5483d6d8b734fa606cfc67e4dba31c4 mod_storage_s3: Implement iteration of keyvalue keys (users usually) diff -r c8322c64a548 -r c74a96dc5d58 mod_storage_s3/mod_storage_s3.lua --- a/mod_storage_s3/mod_storage_s3.lua Sat Oct 14 21:40:46 2023 +0200 +++ b/mod_storage_s3/mod_storage_s3.lua Sat Oct 14 21:41:01 2023 +0200 @@ -151,7 +151,25 @@ end function keyval:users() - return nil, "not-implemented"; + local bucket_path = url.build_path({ is_absolute = true; bucket; is_directory = true }); + local prefix = url.build_path({ jid.escape(module.host); jid.escape(self.store); is_directory = true }); + local list_result, err = async.wait_for(new_request("GET", bucket_path, { prefix = prefix })) + if err or list_result.code ~= 200 then + return nil, err; + end + local list_bucket_result = xml.parse(list_result.body); + if list_bucket_result:get_child_text("IsTruncated") == "true" then + local max_keys = list_bucket_result:get_child_text("MaxKeys"); + module:log("warn", "Paging truncated results not implemented, max %s %s returned", max_keys, self.store); + end + local keys = array(); + for content in list_bucket_result:childtags("Contents") do + local key = url.parse_path(content:get_child_text("Key")); + keys:push(jid.unescape(key[3])); + end + return function() + return keys:pop(); + end end module:provides("storage", driver);