Commit fbfb7138 authored by Micaël Bergeron's avatar Micaël Bergeron

polish the error handling when object storage is unavailable

parent a3c4ffa3
......@@ -4,7 +4,7 @@ class PseudonymizerWorker
def perform
abort "The pseudonymizer is not available with this license." unless License.feature_available?(:pseudonymizer)
return unless Gitlab::CurrentSettings.pseudonymizer_enabled?
abort "The pseudonymizer is disabled." unless Gitlab::CurrentSettings.pseudonymizer_enabled?
options = Pseudonymizer::Options.new(
config: YAML.load_file(Gitlab.config.pseudonymizer.manifest),
......@@ -14,6 +14,8 @@ class PseudonymizerWorker
dumper = Pseudonymizer::Dumper.new(options)
uploader = Pseudonymizer::Uploader.new(options, progress_output: File.open(File::NULL, "w"))
abort "The pseudonymizer object storage must be configured." unless uploader.available?
begin
dumper.tables_to_csv
uploader.upload
......
module Pseudonymizer
ObjectStorageUnavailableError = Class.new(StandardError)
class Uploader
include Gitlab::Utils::StrongMemoize
......@@ -22,12 +24,20 @@ module Pseudonymizer
@connection_params = self.class.object_store_credentials
end
def available?
!connect_to_remote_directory.nil?
rescue ObjectStorageUnavailableError
false
end
def upload
progress_output.puts "Uploading output files to remote storage #{remote_directory}:"
file_list.each do |file|
upload_file(file, remote_directory)
end
rescue ObjectStorageUnavailableError
abort "Cannot upload files, make sure the `pseudonimizer.upload.connection` is set properly".color(:red)
end
def cleanup
......@@ -62,7 +72,8 @@ module Pseudonymizer
def connect_to_remote_directory
if @connection_params.blank?
abort "Cannot upload files, make sure the `pseudonimizer.upload.connection` is set properly".color(:red)
raise ObjectStorageUnavailableError
end
connection = ::Fog::Storage.new(@connection_params)
......
......@@ -83,6 +83,8 @@ namespace :gitlab do
dumper = Pseudonymizer::Dumper.new(options)
uploader = Pseudonymizer::Uploader.new(options)
abort "There is an error in the pseudonymizer object store configuration." unless uploader.available?
begin
dumper.tables_to_csv
uploader.upload
......
require 'spec_helper'
describe Pseudonymizer::Pager do
class Counter
@count = 0
def increment(*args)
self.count += 1
end
end
let(:page_size) { 1 }
let!(:projects) { create_list(:project, 10) }
subject { described_class.new("projects", whitelisted_columns) }
......
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