Skip to content

Commit 207f14a

Browse files
authored
revert: setting idempotency header (googleapis#23588)
This reverts commit 0f5a074 (pull request googleapis#22517). There are several issues with the original change, notably that it sets the invocation ID as a constant, meaning ALL calls from the same Ruby VM will always use the same invocation ID. This will likely confuse any consumer of this value. (Indeed, some basic integration tests run against that code yielded weird results.)
1 parent d94d703 commit 207f14a

File tree

3 files changed

+4
-31
lines changed

3 files changed

+4
-31
lines changed

google-apis-core/lib/google/apis/core/api_command.rb

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
require 'google/apis/errors'
1919
require 'json'
2020
require 'retriable'
21+
require "securerandom"
2122

2223
module Google
2324
module Apis
@@ -69,7 +70,6 @@ def initialize(method, url, body: nil, client_version: nil)
6970
def prepare!
7071
set_api_client_header
7172
set_user_project_header
72-
set_idempotency_token_header
7373
if options&.api_format_version
7474
header['X-Goog-Api-Format-Version'] = options.api_format_version.to_s
7575
end
@@ -143,7 +143,6 @@ def allow_form_encoding?
143143
end
144144

145145
private
146-
INVOCATION_ID = SecureRandom.uuid
147146

148147
def set_api_client_header
149148
old_xgac = header
@@ -175,12 +174,8 @@ def set_user_project_header
175174
header['X-Goog-User-Project'] = quota_project_id if quota_project_id
176175
end
177176

178-
def set_idempotency_token_header
179-
header['X-Goog-Gcs-Idempotency-Token'] = INVOCATION_ID
180-
end
181-
182177
def invocation_id_header
183-
"gccl-invocation-id/#{INVOCATION_ID}"
178+
"gccl-invocation-id/#{SecureRandom.uuid}"
184179
end
185180

186181
# Attempt to parse a JSON error message

google-apis-core/spec/google/apis/core/api_command_spec.rb

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,11 @@
3434

3535
let(:client_version) { "1.2.3" }
3636
let(:x_goog_api_client_value) { "gl-ruby/#{RUBY_VERSION} gdcl/#{client_version}" }
37+
3738
context('with preparation') do
3839
let(:command) do
3940
Google::Apis::Core::ApiCommand.new(:get, 'https://www.googleapis.com/zoo/animals', client_version: client_version)
4041
end
41-
let(:invocation_id) { 'test123' }
42-
43-
before(:example) do
44-
Google::Apis::Core::ApiCommand.const_set(:INVOCATION_ID, invocation_id)
45-
end
4642

4743
it 'should set X-Goog-Api-Client header if none is set' do
4844
command.prepare!
@@ -93,14 +89,6 @@
9389
command.options.add_invocation_id_header = true
9490
command.prepare!
9591
expect(command.header["X-Goog-Api-Client"]).to include("gccl-invocation-id")
96-
expect(command.header["X-Goog-Api-Client"]).to include(invocation_id)
97-
98-
end
99-
100-
it "should set the X-Goog-Gcs-Idempotency-Token header" do
101-
command.prepare!
102-
expect(command.header['X-Goog-Gcs-Idempotency-Token']).not_to be_nil
103-
expect(command.header['X-Goog-Gcs-Idempotency-Token']).to eql invocation_id
10492
end
10593
end
10694

@@ -262,18 +250,11 @@
262250
command.options.add_invocation_id_header = true
263251
result = command.execute(client)
264252
invocation_id_header = command.header["X-Goog-Api-Client"]
253+
265254
expect(invocation_id_header).to include("gccl-invocation-id")
266255
expect(a_request(:get, 'https://www.googleapis.com/zoo/animals')
267256
.with { |req| req.headers['X-Goog-Api-Client'] == invocation_id_header }).to have_been_made.times(2)
268257
end
269-
270-
it 'should keep same idempotency_token across retries' do
271-
result = command.execute(client)
272-
idempotency_token_header = command.header['X-Goog-Gcs-Idempotency-Token']
273-
expect(a_request(:get, 'https://www.googleapis.com/zoo/animals')
274-
.with { |req| req.headers['X-Goog-Gcs-Idempotency-Token'] == idempotency_token_header })
275-
.to have_been_made.times(2)
276-
end
277258
end
278259

279260
context('with a project not linked response') do

google-apis-core/spec/google/apis/core/service_spec.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
let(:service_ud) { Google::Apis::Core::BaseService.new('https://www.$UNIVERSE_DOMAIN$/', '', client_version: client_version) }
2626
let(:service_with_base_path) { Google::Apis::Core::BaseService.new('https://www.googleapis.com/', 'my_service/v1/', client_version: client_version) }
2727
let(:x_goog_api_client_value) { "gl-ruby/#{RUBY_VERSION} gdcl/#{client_version}" }
28-
let(:invocation_id) { 'test123' }
2928

3029
before do
3130
Google::Apis::ClientOptions.default.application_name = 'test'
@@ -375,7 +374,6 @@
375374

376375
context 'with batch uploads' do
377376
before(:example) do
378-
Google::Apis::Core::ApiCommand.const_set(:INVOCATION_ID, invocation_id)
379377
allow(SecureRandom).to receive(:uuid).and_return('b1981e17-f622-49af-b2eb-203308b1b17d')
380378
allow(Digest::SHA1).to receive(:hexdigest).and_return('outer', 'inner')
381379
response = <<EOF.gsub(/\n/, "\r\n")
@@ -432,7 +430,6 @@
432430
433431
POST /upload/zoo/animals\\? HTTP/1\\.1
434432
X-Goog-Api-Client: #{Regexp.escape(x_goog_api_client_value)}
435-
X-Goog-Gcs-Idempotency-Token: #{invocation_id}
436433
Content-Type: multipart/related; boundary=inner
437434
X-Goog-Upload-Protocol: multipart
438435
Authorization: Bearer a token

0 commit comments

Comments
 (0)