Skip to content

Commit cd1a711

Browse files
updating token value
1 parent b53b80d commit cd1a711

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

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

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

2322
module Google
2423
module Apis
@@ -144,6 +143,7 @@ def allow_form_encoding?
144143
end
145144

146145
private
146+
INVOCATION_ID = SecureRandom.uuid
147147

148148
def set_api_client_header
149149
old_xgac = header
@@ -174,13 +174,13 @@ def set_user_project_header
174174
end
175175
header['X-Goog-User-Project'] = quota_project_id if quota_project_id
176176
end
177-
177+
178178
def set_idempotency_token_header
179-
header['X-Goog-Gcs-Idempotency-Token'] = SecureRandom.uuid
179+
header['X-Goog-Gcs-Idempotency-Token'] = INVOCATION_ID
180180
end
181181

182182
def invocation_id_header
183-
"gccl-invocation-id/#{SecureRandom.uuid}"
183+
"gccl-invocation-id/#{INVOCATION_ID}"
184184
end
185185

186186
# Attempt to parse a JSON error message

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@
3838
let(:command) do
3939
Google::Apis::Core::ApiCommand.new(:get, 'https://www.googleapis.com/zoo/animals', client_version: client_version)
4040
end
41+
let(:invocation_id) { 'test123' }
42+
43+
before(:example) do
44+
Google::Apis::Core::ApiCommand.const_set(:INVOCATION_ID, invocation_id)
45+
end
4146

4247
it 'should set X-Goog-Api-Client header if none is set' do
4348
command.prepare!
@@ -88,12 +93,15 @@
8893
command.options.add_invocation_id_header = true
8994
command.prepare!
9095
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+
9198
end
9299

93100
it "should set the X-Goog-Gcs-Idempotency-Token header" do
94101
command.options.add_idempotency_token_header = true
95102
command.prepare!
96103
expect(command.header['X-Goog-Gcs-Idempotency-Token']).not_to be_nil
104+
expect(command.header['X-Goog-Gcs-Idempotency-Token']).to eql invocation_id
97105
end
98106
end
99107

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
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' }
2829

2930
before do
3031
Google::Apis::ClientOptions.default.application_name = 'test'
@@ -285,6 +286,7 @@
285286

286287
context 'with batch uploads' do
287288
before(:example) do
289+
Google::Apis::Core::ApiCommand.const_set(:INVOCATION_ID, invocation_id)
288290
allow(SecureRandom).to receive(:uuid).and_return('b1981e17-f622-49af-b2eb-203308b1b17d')
289291
allow(Digest::SHA1).to receive(:hexdigest).and_return('outer', 'inner')
290292
response = <<EOF.gsub(/\n/, "\r\n")
@@ -341,7 +343,7 @@
341343
342344
POST /upload/zoo/animals\\? HTTP/1\\.1
343345
X-Goog-Api-Client: #{Regexp.escape(x_goog_api_client_value)}
344-
X-Goog-Gcs-Idempotency-Token: b1981e17-f622-49af-b2eb-203308b1b17d
346+
X-Goog-Gcs-Idempotency-Token: #{invocation_id}
345347
Content-Type: multipart/related; boundary=inner
346348
X-Goog-Upload-Protocol: multipart
347349
Authorization: Bearer a token

0 commit comments

Comments
 (0)