diff --git a/qa/Gemfile b/qa/Gemfile index 8dee3fb9326253577210a2a69dc1bb910315ba4d..05acab5653ffbe7bf87c3fbc4ec81bb0e0308310 100644 --- a/qa/Gemfile +++ b/qa/Gemfile @@ -29,7 +29,6 @@ gem 'influxdb-client', '~> 1.17' gem 'terminal-table', '~> 3.0.0', require: false gem 'slack-notifier', '~> 2.4', require: false gem 'fog-google', '~> 1.17', require: false -gem 'google-cloud-storage', '~> 1.36', require: false gem 'confiner', '~> 0.2' diff --git a/qa/Gemfile.lock b/qa/Gemfile.lock index ac683ad549d53c717e0587b7e1f3e392f6749f4c..369ab0860edc805ba371ed90b542e684feb0d7c3 100644 --- a/qa/Gemfile.lock +++ b/qa/Gemfile.lock @@ -65,8 +65,6 @@ GEM deprecation_toolkit (1.5.1) activesupport (>= 4.2) diff-lcs (1.3) - digest-crc (0.6.4) - rake (>= 12.0.0, < 14.0.0) domain_name (0.5.20190701) unf (>= 0.0.5, < 1.0.0) equalizer (0.0.11) @@ -152,20 +150,8 @@ GEM google-apis-core (>= 0.4, < 2.a) google-apis-storage_v1 (0.9.0) google-apis-core (>= 0.4, < 2.a) - google-cloud-core (1.6.0) - google-cloud-env (~> 1.0) - google-cloud-errors (~> 1.0) google-cloud-env (1.5.0) faraday (>= 0.17.3, < 2.0) - google-cloud-errors (1.2.0) - google-cloud-storage (1.36.1) - addressable (~> 2.8) - digest-crc (~> 0.4) - google-apis-iamcredentials_v1 (~> 0.1) - google-apis-storage_v1 (~> 0.1) - google-cloud-core (~> 1.6) - googleauth (>= 0.16.2, < 2.a) - mini_mime (~> 1.0) googleauth (1.1.0) faraday (>= 0.17.3, < 2.0) jwt (>= 1.4, < 3.0) @@ -382,7 +368,6 @@ DEPENDENCIES faker (~> 2.19, >= 2.19.0) fog-google (~> 1.17) gitlab-qa - google-cloud-storage (~> 1.36) influxdb-client (~> 1.17) knapsack (~> 4.0) octokit (~> 4.21) diff --git a/qa/qa/tools/test_resources_handler.rb b/qa/qa/tools/test_resources_handler.rb index c298be2516006a8d461666460bf830916481870b..97b983913b45d09f486afa027a39948f58b8d23a 100644 --- a/qa/qa/tools/test_resources_handler.rb +++ b/qa/qa/tools/test_resources_handler.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require "google/cloud/storage" +require "fog/google" # This script handles resources created during E2E test runs # @@ -67,7 +67,7 @@ def upload(environment_name) files.each do |file| file_name = "#{environment_name}/#{file.split('/').last}" Runtime::Logger.info("Uploading #{file_name}...") - gcs_bucket.create_file(file, file_name) + gcs_storage.put_object(BUCKET, file_name, File.read(file)) end puts "\nDone" @@ -76,17 +76,20 @@ def upload(environment_name) # Download files from GCS bucket by environment name # Delete the files afterward def download(environment_name) - files_list = gcs_bucket.files(prefix: "#{environment_name}") + files_list = gcs_storage.list_objects(BUCKET, prefix: environment_name).items.each_with_object([]) do |obj, arr| + arr << obj.name + end return puts "\nNothing to download!" if files_list.empty? - files_list.each do |file| - local_path = "tmp/#{file.name.split('/').last}" - Runtime::Logger.info("Downloading #{file.name} to #{local_path}") - file.download(local_path) + files_list.each do |file_name| + local_path = "tmp/#{file_name.split('/').last}" + Runtime::Logger.info("Downloading #{file_name} to #{local_path}") + file = gcs_storage.get_object(BUCKET, file_name) + File.write(local_path, file[:body]) - Runtime::Logger.info("Deleting #{file.name} from bucket") - file.delete + Runtime::Logger.info("Deleting #{file_name} from bucket") + gcs_storage.delete_object(BUCKET, file_name) end puts "\nDone" @@ -158,18 +161,14 @@ def api_client end def gcs_storage - @gcs_storage ||= Google::Cloud::Storage.new( - project_id: PROJECT, - credentials: json_key + @gcs_storage ||= Fog::Storage::Google.new( + google_project: PROJECT, + **(File.exist?(json_key) ? { google_json_key_location: json_key } : { google_json_key_string: json_key }) ) rescue StandardError => e abort("\nThere might be something wrong with the JSON key file - [ERROR] #{e}") end - def gcs_bucket - @gcs_bucket ||= gcs_storage.bucket(BUCKET, skip_lookup: true) - end - # Path to GCS service account json key file # Or the content of the key file as a hash def json_key