google-apis-core 1.0.1 → 1.1.0

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: 3942b0296ecaefbf670d435adf32df8c1f14be2a16d9a890ed3551ba7d95688a
4
- data.tar.gz: 66e5e8b65a689f1ccd5788de4ec169d1f4298b1cc106362d1fc3075f17a62526
3
+ metadata.gz: 850aff1c0e3fa076d1ae86405b2390296f569c0f8a7f05e81aa94deca2419995
4
+ data.tar.gz: 5f0e301b6362136d3cad534d1de668ac535ef025c6b525a7f6bc402d8deb10cf
5
5
  SHA512:
6
- metadata.gz: 50a6c03bb553d70d16ca5120416eca74c4983329069ea80d5c42c840e9f06b9934be375b60563b78c55eadd233e21c33514743f75139d8751d89ece9cf8f7450
7
- data.tar.gz: 6bac8358f9627301e9dab533a4c303442235fb4bd239aac2bcab20ca86a322975b00e51c6bffee629b07d4e219f060c81d3264b32a654ddb8da8666fa3c93360
6
+ metadata.gz: 6aac326b8d12f844d928bf46de25daa0fe52e2f0f1c1558df08d832fa29d354eb69c94ae360dabd94aac59ade6c12fa4131f4b4bd7a55f222b84720ad4e93bdf
7
+ data.tar.gz: 66f01cade6af7c80059f34ba0567ebe5e0683e022a505c3996d290eb5c7073e033a7a95f89c0926d437e640cab2c8959abbe405cf4cf1cca54eb5c9c9760b191
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Release History
2
2
 
3
+ ### 1.1.0 (2026-05-17)
4
+
5
+ #### Features
6
+
7
+ * adding checksum header ([#25157](https://github.com/googleapis/google-api-ruby-client/issues/25157))
8
+
9
+ ### 1.0.2 (2025-09-09)
10
+
11
+ #### Bug Fixes
12
+
13
+ * Handle nil response in on_data callback for Faraday streaming ([#24235](https://github.com/googleapis/google-api-ruby-client/issues/24235))
14
+
3
15
  ### 1.0.1 (2025-08-08)
4
16
 
5
17
  #### Bug Fixes
@@ -38,6 +38,11 @@ module Google
38
38
  #
39
39
  # @param [Object] store
40
40
  # Storage object
41
+ #
42
+ # @note Warning: This class is part of a deprecated credentials flow.
43
+ # Providing an unvalidated credential configuration to Google APIs can
44
+ # compromise the security of your systems and data. Use
45
+ # google-auth-library-ruby instead.
41
46
  def initialize(store)
42
47
  @store= store
43
48
  @authorization = nil
@@ -37,6 +37,11 @@ module Google
37
37
 
38
38
  ##
39
39
  # Attempt to read in credentials from the specified file.
40
+ #
41
+ # @note Warning: This method is part of a deprecated credentials flow.
42
+ # Providing an unvalidated credential configuration to Google APIs can
43
+ # compromise the security of your systems and data. Use
44
+ # google-auth-library-ruby instead.
40
45
  def load_credentials
41
46
  open(path, 'r') { |f| JSON.parse(f.read) }
42
47
  rescue
@@ -37,6 +37,12 @@ module Google
37
37
 
38
38
  ##
39
39
  # Attempt to read in credentials from redis.
40
+ #
41
+ # @note Warning: This method is part of a deprecated credentials flow.
42
+ # Providing an unvalidated credential configuration to Google APIs can
43
+ # compromise the security of your systems and data. Use
44
+ # google-auth-library-ruby instead.
45
+ #
40
46
  # @return [Hash]
41
47
  def load_credentials
42
48
  credentials = redis.get redis_credentials_key
@@ -81,7 +81,10 @@ module Google
81
81
 
82
82
  http_res = client.get(url.to_s, query, request_header) do |request|
83
83
  request.options.on_data = proc do |chunk, _size, res|
84
- status = res.status.to_i
84
+ # The on_data callback is only invoked on a successful response.
85
+ # Some Faraday adapters (e.g. Typhoeus) may not provide a response
86
+ # object in the callback, so we default to a 200 OK status.
87
+ status = res ? res.status.to_i : 200
85
88
  next if chunk.nil? || (status >= 300 && status < 400)
86
89
 
87
90
  # HTTP 206 is Partial Content
@@ -48,7 +48,10 @@ module Google
48
48
 
49
49
  http_res = client.get(url.to_s, query, request_header) do |request|
50
50
  request.options.on_data = proc do |chunk, _size, res|
51
- status = res.status.to_i
51
+ # The on_data callback is only invoked on a successful response.
52
+ # Some Faraday adapters (e.g. Typhoeus) may not provide a response
53
+ # object in the callback, so we default to a 200 OK status.
54
+ status = res ? res.status.to_i : 200
52
55
  next if chunk.nil? || (status >= 300 && status < 400)
53
56
 
54
57
  download_offset ||= (status == 206 ? @offset : 0)
@@ -176,6 +176,10 @@ module Google
176
176
  request_header = header.dup
177
177
  request_header[CONTENT_RANGE_HEADER] = get_content_range_header current_chunk_size
178
178
  request_header[CONTENT_LENGTH_HEADER] = current_chunk_size.to_s
179
+ last_chunk = remaining_content_size <= current_chunk_size
180
+ formatted_string = formatted_checksum_header
181
+ request_header['X-Goog-Hash'] = formatted_string if (last_chunk && !formatted_string.empty?)
182
+
179
183
  chunk_body =
180
184
  if @upload_chunk_size == 0
181
185
  upload_io
@@ -191,7 +195,7 @@ module Google
191
195
  success(result)
192
196
  rescue => e
193
197
  logger.warn {
194
- "error occured please use uploadId-#{response.headers['X-GUploader-UploadID']} to resume your upload"
198
+ "error occurred please use uploadId-#{response.headers['X-GUploader-UploadID']} to resume your upload"
195
199
  } unless response.nil?
196
200
  upload_io.pos = @offset
197
201
  error(e, rethrow: true)
@@ -290,6 +294,30 @@ module Google
290
294
  end
291
295
  sprintf('bytes %s/%d', numerator, upload_io.size)
292
296
  end
297
+
298
+ # Generates a formatted checksum header string from the request body.
299
+ #
300
+ # Parses the body as JSON and extracts checksum values for the keys "crc32c", "md5Hash", and "md5".
301
+ # The "md5Hash" key is renamed to "md5" in the output.
302
+ # Returns a comma-separated string in the format "key=value" for each present checksum.
303
+ #
304
+ # @example
305
+ # If the body contains:
306
+ # { "md5Hash": "1B2M2Y8AsgTpgAmY7PhCfg==",
307
+ # "crc32c": "AAAAAA==" }
308
+ # The method returns:
309
+ # "crc32c=AAAAAA==,md5=1B2M2Y8AsgTpgAmY7PhCfg=="
310
+ # @return [String] the formatted checksum header, or an empty string if no relevant keys are present
311
+ def formatted_checksum_header
312
+ hash_data = body.to_s.empty? ? {} : JSON.parse(body)
313
+ target_keys = ["crc32c", "md5Hash", "md5"]
314
+ selected_keys = hash_data.slice(*target_keys)
315
+ formatted_string = selected_keys.map do |key, value|
316
+ output_key = (key == "md5Hash") ? "md5" : key
317
+ "#{output_key}=#{value}"
318
+ end.join(',')
319
+ formatted_string
320
+ end
293
321
  end
294
322
  end
295
323
  end
@@ -16,7 +16,7 @@ module Google
16
16
  module Apis
17
17
  module Core
18
18
  # Core version
19
- VERSION = "1.0.1".freeze
19
+ VERSION = "1.1.0".freeze
20
20
  end
21
21
  end
22
22
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-apis-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Google LLC
@@ -153,7 +153,7 @@ licenses:
153
153
  metadata:
154
154
  bug_tracker_uri: https://github.com/googleapis/google-api-ruby-client/issues
155
155
  changelog_uri: https://github.com/googleapis/google-api-ruby-client/tree/main/google-apis-core/CHANGELOG.md
156
- documentation_uri: https://googleapis.dev/ruby/google-apis-core/v1.0.1
156
+ documentation_uri: https://googleapis.dev/ruby/google-apis-core/v1.1.0
157
157
  source_code_uri: https://github.com/googleapis/google-api-ruby-client/tree/main/google-apis-core
158
158
  rdoc_options: []
159
159
  require_paths: