Mercurial > prosody-modules
comparison mod_storage_s3/mod_storage_s3.lua @ 5672:c74a96dc5d58
mod_storage_s3: Implement iteration of keyvalue keys (users usually)
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sat, 14 Oct 2023 21:41:01 +0200 |
| parents | c8322c64a548 |
| children | b17ba149b7c5 |
comparison
equal
deleted
inserted
replaced
| 5671:c8322c64a548 | 5672:c74a96dc5d58 |
|---|---|
| 149 | 149 |
| 150 return async.wait_for(new_request("PUT", self:_path(user), nil, data)); | 150 return async.wait_for(new_request("PUT", self:_path(user), nil, data)); |
| 151 end | 151 end |
| 152 | 152 |
| 153 function keyval:users() | 153 function keyval:users() |
| 154 return nil, "not-implemented"; | 154 local bucket_path = url.build_path({ is_absolute = true; bucket; is_directory = true }); |
| 155 local prefix = url.build_path({ jid.escape(module.host); jid.escape(self.store); is_directory = true }); | |
| 156 local list_result, err = async.wait_for(new_request("GET", bucket_path, { prefix = prefix })) | |
| 157 if err or list_result.code ~= 200 then | |
| 158 return nil, err; | |
| 159 end | |
| 160 local list_bucket_result = xml.parse(list_result.body); | |
| 161 if list_bucket_result:get_child_text("IsTruncated") == "true" then | |
| 162 local max_keys = list_bucket_result:get_child_text("MaxKeys"); | |
| 163 module:log("warn", "Paging truncated results not implemented, max %s %s returned", max_keys, self.store); | |
| 164 end | |
| 165 local keys = array(); | |
| 166 for content in list_bucket_result:childtags("Contents") do | |
| 167 local key = url.parse_path(content:get_child_text("Key")); | |
| 168 keys:push(jid.unescape(key[3])); | |
| 169 end | |
| 170 return function() | |
| 171 return keys:pop(); | |
| 172 end | |
| 155 end | 173 end |
| 156 | 174 |
| 157 module:provides("storage", driver); | 175 module:provides("storage", driver); |
