File tree Expand file tree Collapse file tree 3 files changed +15
-5
lines changed Expand file tree Collapse file tree 3 files changed +15
-5
lines changed Original file line number Diff line number Diff line change 1818require 'google/apis/errors'
1919require 'json'
2020require 'retriable'
21- require 'securerandom'
2221
2322module 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
Original file line number Diff line number Diff line change 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!
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
Original file line number Diff line number Diff line change 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'
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 " )
341343
342344POST /upload/zoo/animals\\ ? HTTP/1\\ .1
343345X-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 }
345347Content-Type: multipart/related; boundary=inner
346348X-Goog-Upload-Protocol: multipart
347349Authorization: Bearer a token
You can’t perform that action at this time.
0 commit comments