comparison mod_storage_s3/mod_storage_s3.lua @ 5670:2c9d72ef829e

mod_storage_s3: Handle signing of request ?query part
author Kim Alvefur <zash@zash.se>
date Sat, 14 Oct 2023 21:40:20 +0200
parents 30f91daa40b4
children c8322c64a548
comparison
equal deleted inserted replaced
5669:30f91daa40b4 5670:2c9d72ef829e
33 local keyval = { }; 33 local keyval = { };
34 driver.keyval = { __index = keyval; __name = module.name .. " keyval store" }; 34 driver.keyval = { __index = keyval; __name = module.name .. " keyval store" };
35 35
36 local aws4_format = "AWS4-HMAC-SHA256 Credential=%s/%s, SignedHeaders=%s, Signature=%s"; 36 local aws4_format = "AWS4-HMAC-SHA256 Credential=%s/%s, SignedHeaders=%s, Signature=%s";
37 37
38 local function new_request(method, path, payload) 38 local function new_request(method, path, query, payload)
39 local request = url.parse(base_uri); 39 local request = url.parse(base_uri);
40 request.path = path; 40 request.path = path;
41 41
42 local payload_type = nil; 42 local payload_type = nil;
43 if st.is_stanza(payload) then 43 if st.is_stanza(payload) then
66 66
67 local canonical_uri = url.build({ path = request.path }); 67 local canonical_uri = url.build({ path = request.path });
68 local canonical_query = ""; 68 local canonical_query = "";
69 local canonical_headers = array(); 69 local canonical_headers = array();
70 local signed_headers = array() 70 local signed_headers = array()
71
72 if query then
73 local sorted_query = array();
74 for name, value in it.sorted_pairs(query) do
75 sorted_query:push({ name = name; value = value });
76 end
77 sorted_query:sort(function (a,b) return a.name < b.name end)
78 canonical_query = httputil.formencode(sorted_query):gsub("%%%x%x", string.upper);
79 request.query = canonical_query;
80 end
71 81
72 for header_name, header_value in it.sorted_pairs(headers) do 82 for header_name, header_value in it.sorted_pairs(headers) do
73 header_name = header_name:lower(); 83 header_name = header_name:lower();
74 canonical_headers:push(header_name .. ":" .. header_value .. "\n"); 84 canonical_headers:push(header_name .. ":" .. header_value .. "\n");
75 signed_headers:push(header_name); 85 signed_headers:push(header_name);