From b4c5e010adf3ca7b370ccea3b18e818f9d9a79b7 Mon Sep 17 00:00:00 2001 From: Stanislav Kolotinskiy Date: Tue, 18 Jan 2022 15:05:16 +0200 Subject: [PATCH] Consider case when GCS config is a string re #BFSY-64 --- lib/travis/services/find_caches.rb | 6 ++++-- spec/lib/services/find_caches_spec.rb | 5 +++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/travis/services/find_caches.rb b/lib/travis/services/find_caches.rb index 5a82d0fdf3..2333c1373f 100644 --- a/lib/travis/services/find_caches.rb +++ b/lib/travis/services/find_caches.rb @@ -154,8 +154,10 @@ def fetch_s3(cache_objects, options) def fetch_gcs(cache_objects, options) config = cache_options[:gcs] storage = ::Google::Apis::StorageV1::StorageService.new - json_key_io = StringIO.new(JSON.dump(config.to_h[:json_key])) - bucket_name = config[:bucket_name] + json_key_obj = config.to_h[:json_key] + json_key_obj = JSON.dump(json_key_obj) unless json_key_obj.is_a?(String) + json_key_io = StringIO.new(json_key_obj) + bucket_name = config[:bucket_name] storage.authorization = ::Google::Auth::ServiceAccountCredentials.make_creds( json_key_io: json_key_io, diff --git a/spec/lib/services/find_caches_spec.rb b/spec/lib/services/find_caches_spec.rb index dfa19021b5..b7631e6ffa 100644 --- a/spec/lib/services/find_caches_spec.rb +++ b/spec/lib/services/find_caches_spec.rb @@ -73,6 +73,11 @@ context 'with GCS configuration' do let(:cache_options) { { gcs: { bucket_name: '', json_key: { type: 'service_account', project_id: 'test-project-id' } } } } its(:size) { is_expected.to eq 0 } + + context 'when configuration is a String' do + let(:cache_options) { { gcs: { bucket_name: '', json_key: JSON.dump(type: 'service_account', project_id: 'test-project-id') } } } + its(:size) { is_expected.to eq 0 } + end end end end