files.com 1.1.744 → 1.1.745

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b8af62f099ab3fe1820b5ff20e5dc202bee1a742c42505961cd9d00c7c894d66
4
- data.tar.gz: 337cc2a388ec0cc310a9fe9473906ce64eeaa20bd8a17ea74b9c2dc1a43f6ef8
3
+ metadata.gz: 76561ada788c8c00625ff151cad4800e0e9d8d6daf4acd434baa34b7d28be212
4
+ data.tar.gz: e063b0dcec5148771d97c8cca16cd090c307fff2b55a5c7cfa16942460ad9546
5
5
  SHA512:
6
- metadata.gz: c30b00f9b88d92ea33ba15f91cf370478862dce94240b2118027294efeb76a24885a0f100cfb7ee6771e51ff3c84d0bb2f20edd688bb7972ba72178db7e8ffda
7
- data.tar.gz: 8a559215377d6c771e06610d57ac45e29d30ee1a0a7c51945a77ee620e650a450892964060de75d255cdf21610969116e5adaa9df35a5983507d9c48598db27d
6
+ metadata.gz: b4cf0e52efc0fe229a2564bd784c579b4220a69cef0a493d6e8acaf20a4084cad8d99ffa36e073ec01e73242939119ee6fc241316fde6c0c706df5cfda9fac2d
7
+ data.tar.gz: 5e6a9e900cb910d8a17218adc1ee61d2a7308b68620e9111bc8f1e424f3a0ba80c26d064617a8d840c63574ba5879444865dca534f318d67d7c339506576cff1
data/_VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.744
1
+ 1.1.745
@@ -150,9 +150,10 @@ module Files
150
150
  def remote_request(method, url, headers = {}, body = nil)
151
151
  context = RequestLogContext.new
152
152
  context.method = method
153
- context.path = url
153
+ context.path = "[transfer]"
154
+ Util.log_debug("Transfer request", method: method, url: url)
154
155
 
155
- execute_request_with_rescues(Files.base_url, context, skip_body_logging: true) do
156
+ execute_request_with_rescues(Files.base_url, context, skip_body_logging: true, is_transfer: true) do
156
157
  conn.run_request(method, url, body, headers) do |req|
157
158
  req.options.open_timeout = Files.open_timeout
158
159
  req.options.timeout = Files.read_timeout
@@ -215,7 +216,7 @@ module Files
215
216
  raise AuthenticationError, "The provided Session ID is invalid (it contains whitespace)"
216
217
  end
217
218
 
218
- def execute_request_with_rescues(base_url, context, skip_body_logging: false)
219
+ def execute_request_with_rescues(base_url, context, skip_body_logging: false, is_transfer: false)
219
220
  num_retries = 0
220
221
  begin
221
222
  request_start = Time.now
@@ -240,14 +241,18 @@ module Files
240
241
  retry
241
242
  end
242
243
 
244
+ Util.log_debug("Transfer error details", error_message: e.message) if is_transfer
245
+
243
246
  case e
244
247
  when Faraday::ClientError, Faraday::ServerError
245
248
  if e.response and has_error_type?(e)
246
- handle_error_response(e.response, error_context)
249
+ handle_error_response(e.response, error_context, is_transfer: is_transfer)
247
250
  else
248
- handle_network_error(e, error_context, num_retries, base_url)
251
+ handle_network_error(e, error_context, num_retries, base_url, is_transfer: is_transfer)
249
252
  end
250
253
  else
254
+ raise e.exception("Transfer request failed (#{e.class})"), cause: nil if is_transfer
255
+
251
256
  raise
252
257
  end
253
258
  end
@@ -266,7 +271,7 @@ module Files
266
271
  str
267
272
  end
268
273
 
269
- private def handle_error_response(http_resp, context)
274
+ private def handle_error_response(http_resp, context, is_transfer: false)
270
275
  begin
271
276
  resp = Response.from_faraday_hash(http_resp)
272
277
  error_data = resp.data[:error] || resp.data[:errors]
@@ -275,17 +280,22 @@ module Files
275
280
 
276
281
  raise Error, "Unknown error" unless error_data
277
282
  rescue JSON::ParserError, Error
283
+ raise APIError.new("Transfer request failed", http_status: http_resp[:status]), cause: nil if is_transfer
284
+
278
285
  raise general_api_error(http_resp[:status], http_resp[:body])
279
286
  end
280
287
 
281
- error = specific_api_error(resp, error_data, context)
288
+ error = specific_api_error(resp, error_data, context, is_transfer: is_transfer)
282
289
 
283
290
  error.response = resp
284
- raise(error)
291
+ raise error, cause: nil if is_transfer
292
+
293
+ raise error
285
294
  end
286
295
 
287
- private def specific_api_error(resp, error_data, _context)
288
- Util.log_error("API error", status: resp.http_status, error_message: error_data[:message])
296
+ private def specific_api_error(resp, error_data, _context, is_transfer: false)
297
+ message = is_transfer ? "Transfer request failed" : error_data[:message]
298
+ Util.log_error("API error", status: resp.http_status, error_message: message)
289
299
 
290
300
  opts = {
291
301
  http_body: resp.http_body,
@@ -295,28 +305,34 @@ module Files
295
305
  code: error_data[:code] || resp.http_status,
296
306
  }
297
307
 
298
- return APIError.new(error_data[:message], **opts) unless resp&.data&.dig(:type)
308
+ return APIError.new(message, **opts) unless resp&.data&.dig(:type)
299
309
 
300
310
  begin
301
311
  error_type = resp.data[:type].split("/").last
302
312
  error_class_name = "#{error_type.split("-").map(&:capitalize).join}Error"
303
313
  error_class = Files.const_get(error_class_name)
304
- error_class.new(error_data[:message], **opts)
314
+ error_class.new(message, **opts)
305
315
  rescue NameError
306
- APIError.new(error_data[:message], **opts)
316
+ APIError.new(message, **opts)
307
317
  end
308
318
  end
309
319
 
310
- private def handle_network_error(error, _context, num_retries, base_url = nil)
320
+ private def handle_network_error(error, _context, num_retries, base_url = nil, is_transfer: false)
311
321
  base_url ||= Files.base_url
312
322
 
313
- error_message = error.message.empty? ? error.response[:body] : error.message
323
+ error_message = if is_transfer
324
+ error.class.name
325
+ else
326
+ error.message.empty? ? error.response[:body] : error.message
327
+ end
314
328
 
315
329
  Util.log_error("Network error", error_message: error_message)
316
330
  message = "Could not connect to Files.com at URL #{base_url}. Please check your internet connection and try again. If this problem persists, you should check Files.com's service status at https://status.files.com, or contact your primary account representative."
317
331
  message += " Request was retried #{num_retries} times." if num_retries > 0
318
332
  message += "\n\n(Network error: #{error_message})"
319
333
 
334
+ raise APIConnectionError, message, cause: nil if is_transfer
335
+
320
336
  raise APIConnectionError, message
321
337
  end
322
338
 
@@ -372,7 +388,8 @@ module Files
372
388
  end
373
389
 
374
390
  private def log_response_error(context, request_start, error)
375
- Util.log_error("Error", elapsed: Time.now - request_start, error_message: error.message, method: context.method, path: context.path)
391
+ Util.log_error("Error", elapsed: Time.now - request_start, error_type: error.class, method: context.method, path: context.path)
392
+ Util.log_debug("Error details", error_message: error.message)
376
393
  end
377
394
 
378
395
  class RequestLogContext
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Files
4
- VERSION = "1.1.744"
4
+ VERSION = "1.1.745"
5
5
  end
@@ -3,6 +3,67 @@ require "spec_helper"
3
3
  RSpec.describe Files::ApiClient do
4
4
  let(:subject) { described_class.new }
5
5
 
6
+ describe "signed transfer privacy" do
7
+ it "keeps API error types without echoing a transfer URL" do
8
+ url = "https://transfer.example.test/private-part?signature=secret"
9
+ output = StringIO.new
10
+ original_logger = Files.logger
11
+ Files.logger = Logger.new(output, level: Logger::INFO)
12
+ connection = Faraday.new do |builder|
13
+ builder.response :raise_error
14
+ builder.adapter :test do |stub|
15
+ stub.put(url) { [ 404, {}, { type: "not-found", error: url }.to_json ] }
16
+ end
17
+ end
18
+
19
+ expect { described_class.new(connection).remote_request(:put, url, {}, "part") }.to raise_error(Files::NotFoundError) { |error|
20
+ expect(error.http_status).to eq(404)
21
+ expect(error.full_message).not_to include(url, "private-part", "secret")
22
+ }
23
+ expect(output.string).not_to include(url, "private-part", "secret")
24
+ ensure
25
+ Files.logger = original_logger
26
+ end
27
+
28
+ it "keeps the URL out of normal logs and errors while retaining retries and debug details" do
29
+ url = "https://transfer.example.test/private-part?X-Amz-Credential=credential&X-Amz-Signature=signature"
30
+ original_logger = Files.logger
31
+ original_retries = Files.max_network_retries
32
+ original_delay = Files.initial_network_retry_delay
33
+ Files.max_network_retries = 1
34
+ Files.initial_network_retry_delay = 0
35
+
36
+ [ Logger::INFO, Logger::DEBUG ].each do |level|
37
+ output = StringIO.new
38
+ Files.logger = Logger.new(output, level: level)
39
+ attempts = 0
40
+ connection = Faraday.new do |builder|
41
+ builder.adapter :test do |stub|
42
+ stub.put(url) do
43
+ attempts += 1
44
+ raise Faraday::ConnectionFailed, "connection reset for #{url}"
45
+ end
46
+ end
47
+ end
48
+
49
+ expect { described_class.new(connection).remote_request(:put, url, {}, "part") }.to raise_error(Faraday::ConnectionFailed) { |error|
50
+ expect(error.full_message).not_to include(url, "private-part", "credential", "signature")
51
+ }
52
+ expect(attempts).to eq(2)
53
+ if level == Logger::INFO
54
+ expect(output.string).to include("Request", "Error")
55
+ expect(output.string).not_to include(url, "private-part", "credential", "signature")
56
+ else
57
+ expect(output.string).to include(url, "connection reset")
58
+ end
59
+ end
60
+ ensure
61
+ Files.logger = original_logger
62
+ Files.max_network_retries = original_retries
63
+ Files.initial_network_retry_delay = original_delay
64
+ end
65
+ end
66
+
6
67
  describe "#execute_request_with_rescues" do
7
68
  let(:context) { double('context', method: 'some method', path: 'some path') }
8
69
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: files.com
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.744
4
+ version: 1.1.745
5
5
  platform: ruby
6
6
  authors:
7
7
  - files.com