Commit c4a39f9c authored by Tiffany Rea's avatar Tiffany Rea

Use Fog Google

parent d14b5c3f
...@@ -29,7 +29,6 @@ gem 'influxdb-client', '~> 1.17' ...@@ -29,7 +29,6 @@ gem 'influxdb-client', '~> 1.17'
gem 'terminal-table', '~> 3.0.0', require: false gem 'terminal-table', '~> 3.0.0', require: false
gem 'slack-notifier', '~> 2.4', require: false gem 'slack-notifier', '~> 2.4', require: false
gem 'fog-google', '~> 1.17', require: false gem 'fog-google', '~> 1.17', require: false
gem 'google-cloud-storage', '~> 1.36', require: false
gem 'confiner', '~> 0.2' gem 'confiner', '~> 0.2'
......
...@@ -65,8 +65,6 @@ GEM ...@@ -65,8 +65,6 @@ GEM
deprecation_toolkit (1.5.1) deprecation_toolkit (1.5.1)
activesupport (>= 4.2) activesupport (>= 4.2)
diff-lcs (1.3) diff-lcs (1.3)
digest-crc (0.6.4)
rake (>= 12.0.0, < 14.0.0)
domain_name (0.5.20190701) domain_name (0.5.20190701)
unf (>= 0.0.5, < 1.0.0) unf (>= 0.0.5, < 1.0.0)
equalizer (0.0.11) equalizer (0.0.11)
...@@ -152,20 +150,8 @@ GEM ...@@ -152,20 +150,8 @@ GEM
google-apis-core (>= 0.4, < 2.a) google-apis-core (>= 0.4, < 2.a)
google-apis-storage_v1 (0.9.0) google-apis-storage_v1 (0.9.0)
google-apis-core (>= 0.4, < 2.a) 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) google-cloud-env (1.5.0)
faraday (>= 0.17.3, < 2.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) googleauth (1.1.0)
faraday (>= 0.17.3, < 2.0) faraday (>= 0.17.3, < 2.0)
jwt (>= 1.4, < 3.0) jwt (>= 1.4, < 3.0)
...@@ -382,7 +368,6 @@ DEPENDENCIES ...@@ -382,7 +368,6 @@ DEPENDENCIES
faker (~> 2.19, >= 2.19.0) faker (~> 2.19, >= 2.19.0)
fog-google (~> 1.17) fog-google (~> 1.17)
gitlab-qa gitlab-qa
google-cloud-storage (~> 1.36)
influxdb-client (~> 1.17) influxdb-client (~> 1.17)
knapsack (~> 4.0) knapsack (~> 4.0)
octokit (~> 4.21) octokit (~> 4.21)
......
# frozen_string_literal: true # frozen_string_literal: true
require "google/cloud/storage" require "fog/google"
# This script handles resources created during E2E test runs # This script handles resources created during E2E test runs
# #
...@@ -67,7 +67,7 @@ module QA ...@@ -67,7 +67,7 @@ module QA
files.each do |file| files.each do |file|
file_name = "#{environment_name}/#{file.split('/').last}" file_name = "#{environment_name}/#{file.split('/').last}"
Runtime::Logger.info("Uploading #{file_name}...") Runtime::Logger.info("Uploading #{file_name}...")
gcs_bucket.create_file(file, file_name) gcs_storage.put_object(BUCKET, file_name, File.read(file))
end end
puts "\nDone" puts "\nDone"
...@@ -76,17 +76,20 @@ module QA ...@@ -76,17 +76,20 @@ module QA
# Download files from GCS bucket by environment name # Download files from GCS bucket by environment name
# Delete the files afterward # Delete the files afterward
def download(environment_name) 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? return puts "\nNothing to download!" if files_list.empty?
files_list.each do |file| files_list.each do |file_name|
local_path = "tmp/#{file.name.split('/').last}" local_path = "tmp/#{file_name.split('/').last}"
Runtime::Logger.info("Downloading #{file.name} to #{local_path}") Runtime::Logger.info("Downloading #{file_name} to #{local_path}")
file.download(local_path) file = gcs_storage.get_object(BUCKET, file_name)
File.write(local_path, file[:body])
Runtime::Logger.info("Deleting #{file.name} from bucket") Runtime::Logger.info("Deleting #{file_name} from bucket")
file.delete gcs_storage.delete_object(BUCKET, file_name)
end end
puts "\nDone" puts "\nDone"
...@@ -158,18 +161,14 @@ module QA ...@@ -158,18 +161,14 @@ module QA
end end
def gcs_storage def gcs_storage
@gcs_storage ||= Google::Cloud::Storage.new( @gcs_storage ||= Fog::Storage::Google.new(
project_id: PROJECT, google_project: PROJECT,
credentials: json_key **(File.exist?(json_key) ? { google_json_key_location: json_key } : { google_json_key_string: json_key })
) )
rescue StandardError => e rescue StandardError => e
abort("\nThere might be something wrong with the JSON key file - [ERROR] #{e}") abort("\nThere might be something wrong with the JSON key file - [ERROR] #{e}")
end end
def gcs_bucket
@gcs_bucket ||= gcs_storage.bucket(BUCKET, skip_lookup: true)
end
# Path to GCS service account json key file # Path to GCS service account json key file
# Or the content of the key file as a hash # Or the content of the key file as a hash
def json_key def json_key
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment