diff options
-rw-r--r-- | src/luarocks/upload/api.lua | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/src/luarocks/upload/api.lua b/src/luarocks/upload/api.lua index fd476968..ec6ef3bb 100644 --- a/src/luarocks/upload/api.lua +++ b/src/luarocks/upload/api.lua | |||
@@ -119,6 +119,11 @@ end | |||
119 | local ltn12_ok, ltn12 = pcall(require, "ltn12") | 119 | local ltn12_ok, ltn12 = pcall(require, "ltn12") |
120 | if not ltn12_ok then -- If not using LuaSocket and/or LuaSec... | 120 | if not ltn12_ok then -- If not using LuaSocket and/or LuaSec... |
121 | 121 | ||
122 | local function redact_api_url(url) | ||
123 | url = tostring(url) | ||
124 | return (url:gsub(".*/api/[^/]+/[^/]+", "")) | ||
125 | end | ||
126 | |||
122 | function Api:request(url, params, post_params) | 127 | function Api:request(url, params, post_params) |
123 | local vars = cfg.variables | 128 | local vars = cfg.variables |
124 | local json_ok, json = require_json() | 129 | local json_ok, json = require_json() |
@@ -157,26 +162,26 @@ function Api:request(url, params, post_params) | |||
157 | end | 162 | end |
158 | local ok = fs.execute_string(curl_cmd..fs.Q(url).." -o "..fs.Q(tmpfile)) | 163 | local ok = fs.execute_string(curl_cmd..fs.Q(url).." -o "..fs.Q(tmpfile)) |
159 | if not ok then | 164 | if not ok then |
160 | return nil, "API failure: " .. tostring(url) | 165 | return nil, "API failure: " .. redact_api_url(url) |
161 | end | 166 | end |
162 | else | 167 | else |
163 | local ok, err = fs.download(url, tmpfile) | 168 | local ok, err = fs.download(url, tmpfile) |
164 | if not ok then | 169 | if not ok then |
165 | return nil, "API failure: " .. tostring(err) .. " - " .. tostring(url) | 170 | return nil, "API failure: " .. tostring(err) .. " - " .. redact_api_url(url) |
166 | end | 171 | end |
167 | end | 172 | end |
168 | 173 | ||
169 | local tmpfd = io.open(tmpfile) | 174 | local tmpfd = io.open(tmpfile) |
170 | if not tmpfd then | 175 | if not tmpfd then |
171 | os.remove(tmpfile) | 176 | os.remove(tmpfile) |
172 | return nil, "API failure reading temporary file - " .. tostring(url) | 177 | return nil, "API failure reading temporary file - " .. redact_api_url(url) |
173 | end | 178 | end |
174 | out = tmpfd:read("*a") | 179 | out = tmpfd:read("*a") |
175 | tmpfd:close() | 180 | tmpfd:close() |
176 | os.remove(tmpfile) | 181 | os.remove(tmpfile) |
177 | 182 | ||
178 | if self.debug then | 183 | if self.debug then |
179 | util.printout("[" .. tostring(method) .. " via curl] " .. tostring(url) .. " ... ") | 184 | util.printout("[" .. tostring(method) .. " via curl] " .. redact_api_url(url) .. " ... ") |
180 | end | 185 | end |
181 | 186 | ||
182 | return json.decode(out) | 187 | return json.decode(out) |
@@ -229,7 +234,7 @@ function Api:request(url, params, post_params) | |||
229 | end | 234 | end |
230 | local method = post_params and "POST" or "GET" | 235 | local method = post_params and "POST" or "GET" |
231 | if self.debug then | 236 | if self.debug then |
232 | util.printout("[" .. tostring(method) .. " via "..via.."] " .. tostring(url) .. " ... ") | 237 | util.printout("[" .. tostring(method) .. " via "..via.."] " .. redact_api_url(url) .. " ... ") |
233 | end | 238 | end |
234 | local out = {} | 239 | local out = {} |
235 | local _, status = http.request({ | 240 | local _, status = http.request({ |
@@ -243,7 +248,7 @@ function Api:request(url, params, post_params) | |||
243 | util.printout(tostring(status)) | 248 | util.printout(tostring(status)) |
244 | end | 249 | end |
245 | if status ~= 200 then | 250 | if status ~= 200 then |
246 | return nil, "API returned " .. tostring(status) .. " - " .. tostring(url) | 251 | return nil, "API returned " .. tostring(status) .. " - " .. redact_api_url(url) |
247 | end | 252 | end |
248 | return json.decode(table.concat(out)) | 253 | return json.decode(table.concat(out)) |
249 | end | 254 | end |