diff --git a/app/services/archive_storage_service.rb b/app/services/archive_storage_service.rb deleted file mode 100644 index 92875d86a..000000000 --- a/app/services/archive_storage_service.rb +++ /dev/null @@ -1,24 +0,0 @@ -class ArchiveStorageService < StorageService - MAX_SIZE = 50 * (1024**2) # 50MiB - - def initialize(archive_io) - super() - @archive = Zip::File.open_buffer(archive_io) - end - - def list_files(folder) - @archive.glob(File.join(folder, "*.*")) - .map(&:name) - end - - def folder_present?(folder) - !list_files(folder).empty? - end - - def get_file_io(file_name) - entry = @archive.get_entry(file_name) - raise "File too large to be extracted" if entry.size > MAX_SIZE - - entry.get_input_stream - end -end diff --git a/app/services/s3_storage_service.rb b/app/services/s3_storage_service.rb deleted file mode 100644 index 15cbee3d0..000000000 --- a/app/services/s3_storage_service.rb +++ /dev/null @@ -1,78 +0,0 @@ -class S3StorageService < StorageService - attr_reader :configuration - - def initialize(paas_config_service, paas_instance_name) - super() - @paas_config_service = paas_config_service - @paas_instance_name = (paas_instance_name || "").to_sym - @configuration = create_configuration - @client = create_client - end - - def list_files(folder) - @client.list_objects_v2(bucket: @configuration.bucket_name, prefix: folder) - .flat_map { |response| response.contents.map(&:key) } - end - - def folder_present?(folder) - response = @client.list_objects_v2(bucket: @configuration.bucket_name, prefix: folder, max_keys: 1) - response.key_count == 1 - end - - def get_file_io(file_name) - @client.get_object(bucket: @configuration.bucket_name, key: file_name) - .body - end - - def write_file(file_name, data) - @client.put_object( - body: data, - bucket: @configuration.bucket_name, - key: file_name, - ) - end - -private - - def create_configuration - unless @paas_config_service.config_present? - raise "No PaaS configuration present" - end - unless @paas_config_service.s3_buckets.key?(@paas_instance_name) - raise "#{@paas_instance_name} instance name could not be found" - end - - bucket_config = @paas_config_service.s3_buckets[@paas_instance_name] - StorageConfiguration.new(bucket_config[:credentials]) - end - - def create_client - credentials = - Aws::Credentials.new( - @configuration.access_key_id, - @configuration.secret_access_key, - ) - Aws::S3::Client.new( - region: @configuration.region, - credentials:, - ) - end -end - -class StorageConfiguration - attr_reader :access_key_id, :secret_access_key, :bucket_name, :region - - def initialize(credentials) - @access_key_id = credentials[:aws_access_key_id] - @secret_access_key = credentials[:aws_secret_access_key] - @bucket_name = credentials[:bucket_name] - @region = credentials[:aws_region] - end - - def ==(other) - @access_key_id == other.access_key_id && - @secret_access_key == other.secret_access_key && - @bucket_name == other.bucket_name && - @region == other.region - end -end diff --git a/app/services/storage/archive_service.rb b/app/services/storage/archive_service.rb new file mode 100644 index 000000000..dcf3e8d75 --- /dev/null +++ b/app/services/storage/archive_service.rb @@ -0,0 +1,26 @@ +module Storage + class ArchiveService < StorageService + MAX_SIZE = 50 * (1024**2) # 50MiB + + def initialize(archive_io) + super() + @archive = Zip::File.open_buffer(archive_io) + end + + def list_files(folder) + @archive.glob(File.join(folder, "*.*")) + .map(&:name) + end + + def folder_present?(folder) + !list_files(folder).empty? + end + + def get_file_io(file_name) + entry = @archive.get_entry(file_name) + raise "File too large to be extracted" if entry.size > MAX_SIZE + + entry.get_input_stream + end + end +end diff --git a/app/services/storage/s3_service.rb b/app/services/storage/s3_service.rb new file mode 100644 index 000000000..9aa043e98 --- /dev/null +++ b/app/services/storage/s3_service.rb @@ -0,0 +1,80 @@ +module Storage + class S3Service < StorageService + attr_reader :configuration + + def initialize(config_service, paas_instance_name) + super() + @config_service = config_service + @instance_name = (paas_instance_name || "").to_sym + @configuration = create_configuration + @client = create_client + end + + def list_files(folder) + @client.list_objects_v2(bucket: @configuration.bucket_name, prefix: folder) + .flat_map { |response| response.contents.map(&:key) } + end + + def folder_present?(folder) + response = @client.list_objects_v2(bucket: @configuration.bucket_name, prefix: folder, max_keys: 1) + response.key_count == 1 + end + + def get_file_io(file_name) + @client.get_object(bucket: @configuration.bucket_name, key: file_name) + .body + end + + def write_file(file_name, data) + @client.put_object( + body: data, + bucket: @configuration.bucket_name, + key: file_name, + ) + end + + private + + def create_configuration + unless @config_service.config_present? + raise "No PaaS configuration present" + end + unless @config_service.s3_buckets.key?(@instance_name) + raise "#{@instance_name} instance name could not be found" + end + + bucket_config = @config_service.s3_buckets[@instance_name] + StorageConfiguration.new(bucket_config[:credentials]) + end + + def create_client + credentials = + Aws::Credentials.new( + @configuration.access_key_id, + @configuration.secret_access_key, + ) + Aws::S3::Client.new( + region: @configuration.region, + credentials:, + ) + end + end + + class StorageConfiguration + attr_reader :access_key_id, :secret_access_key, :bucket_name, :region + + def initialize(credentials) + @access_key_id = credentials[:aws_access_key_id] + @secret_access_key = credentials[:aws_secret_access_key] + @bucket_name = credentials[:bucket_name] + @region = credentials[:aws_region] + end + + def ==(other) + @access_key_id == other.access_key_id && + @secret_access_key == other.secret_access_key && + @bucket_name == other.bucket_name && + @region == other.region + end + end +end diff --git a/app/services/storage/storage_service.rb b/app/services/storage/storage_service.rb new file mode 100644 index 000000000..afb3d4a58 --- /dev/null +++ b/app/services/storage/storage_service.rb @@ -0,0 +1,19 @@ +module Storage + class StorageService + def list_files(_folder) + raise NotImplementedError + end + + def folder_present?(_folder) + raise NotImplementedError + end + + def get_file_io(_file_name) + raise NotImplementedError + end + + def write_file(_file_name, _data) + raise NotImplementedError + end + end +end diff --git a/app/services/storage_service.rb b/app/services/storage_service.rb deleted file mode 100644 index 0135a92a1..000000000 --- a/app/services/storage_service.rb +++ /dev/null @@ -1,17 +0,0 @@ -class StorageService - def list_files(_folder) - raise NotImplementedError - end - - def folder_present?(_folder) - raise NotImplementedError - end - - def get_file_io(_file_name) - raise NotImplementedError - end - - def write_file(_file_name, _data) - raise NotImplementedError - end -end diff --git a/lib/tasks/data_export.rake b/lib/tasks/data_export.rake index cf669f488..c173bd5f0 100644 --- a/lib/tasks/data_export.rake +++ b/lib/tasks/data_export.rake @@ -4,7 +4,7 @@ namespace :core do format = args[:format] full_update = args[:full_update].present? && args[:full_update] == "true" - storage_service = S3StorageService.new(PaasConfigurationService.new, ENV["EXPORT_PAAS_INSTANCE"]) + storage_service = Storage::S3Service.new(PaasConfigurationService.new, ENV["EXPORT_PAAS_INSTANCE"]) export_service = Exports::CaseLogExportService.new(storage_service) if format.present? && format == "CSV" diff --git a/lib/tasks/data_import.rake b/lib/tasks/data_import.rake index 738fbceb5..80254b93b 100644 --- a/lib/tasks/data_import.rake +++ b/lib/tasks/data_import.rake @@ -5,7 +5,7 @@ namespace :core do path = args[:path] raise "Usage: rake core:data_import['data_type', 'path/to/xml_files']" if path.blank? || type.blank? - storage_service = S3StorageService.new(PaasConfigurationService.new, ENV["IMPORT_PAAS_INSTANCE"]) + storage_service = Storage::S3Service.new(PaasConfigurationService.new, ENV["IMPORT_PAAS_INSTANCE"]) case type when "organisation" diff --git a/lib/tasks/data_import_field.rake b/lib/tasks/data_import_field.rake index 7de94cd09..4c9362093 100644 --- a/lib/tasks/data_import_field.rake +++ b/lib/tasks/data_import_field.rake @@ -5,7 +5,7 @@ namespace :core do path = args[:path] raise "Usage: rake core:data_import_field['field','path/to/xml_files']" if path.blank? || field.blank? - storage_service = S3StorageService.new(PaasConfigurationService.new, ENV["IMPORT_PAAS_INSTANCE"]) + storage_service = Storage::S3Service.new(PaasConfigurationService.new, ENV["IMPORT_PAAS_INSTANCE"]) # We only allow a reduced list of known fields to be updatable case field diff --git a/lib/tasks/full_import.rake b/lib/tasks/full_import.rake index 792eaceff..5f4ed52bd 100644 --- a/lib/tasks/full_import.rake +++ b/lib/tasks/full_import.rake @@ -6,9 +6,9 @@ namespace :core do archive_path = args[:archive_path] raise "Usage: rake core:full_import['path/to/archive']" if archive_path.blank? - s3_service = S3StorageService.new(PaasConfigurationService.new, ENV["IMPORT_PAAS_INSTANCE"]) + s3_service = Storage::S3Service.new(PaasConfigurationService.new, ENV["IMPORT_PAAS_INSTANCE"]) archive_io = s3_service.get_file_io(archive_path) - archive_service = ArchiveStorageService.new(archive_io) + archive_service = Storage::ArchiveService.new(archive_io) import_list = [ Import.new(Imports::OrganisationImportService, :create_organisations, "institution"), diff --git a/spec/lib/tasks/data_export_spec.rb b/spec/lib/tasks/data_export_spec.rb index ae0acdb0d..da87f6bf2 100644 --- a/spec/lib/tasks/data_export_spec.rb +++ b/spec/lib/tasks/data_export_spec.rb @@ -5,7 +5,7 @@ describe "rake core:data_export", type: task do subject(:task) { Rake::Task["core:data_export"] } let(:paas_instance) { "paas_export_instance" } - let(:storage_service) { instance_double(S3StorageService) } + let(:storage_service) { instance_double(Storage::S3Service) } let(:paas_config_service) { instance_double(PaasConfigurationService) } let(:export_service) { instance_double(Exports::CaseLogExportService) } @@ -14,7 +14,7 @@ describe "rake core:data_export", type: task do Rake::Task.define_task(:environment) task.reenable - allow(S3StorageService).to receive(:new).and_return(storage_service) + allow(Storage::S3Service).to receive(:new).and_return(storage_service) allow(PaasConfigurationService).to receive(:new).and_return(paas_config_service) allow(Exports::CaseLogExportService).to receive(:new).and_return(export_service) allow(ENV).to receive(:[]) @@ -23,7 +23,7 @@ describe "rake core:data_export", type: task do context "when exporting case logs with no parameters" do it "starts the XML export process" do - expect(S3StorageService).to receive(:new).with(paas_config_service, paas_instance) + expect(Storage::S3Service).to receive(:new).with(paas_config_service, paas_instance) expect(Exports::CaseLogExportService).to receive(:new).with(storage_service) expect(export_service).to receive(:export_xml_case_logs) @@ -33,7 +33,7 @@ describe "rake core:data_export", type: task do context "when exporting case logs with CSV format" do it "starts the CSV export process" do - expect(S3StorageService).to receive(:new).with(paas_config_service, paas_instance) + expect(Storage::S3Service).to receive(:new).with(paas_config_service, paas_instance) expect(Exports::CaseLogExportService).to receive(:new).with(storage_service) expect(export_service).to receive(:export_csv_case_logs) diff --git a/spec/lib/tasks/data_import_spec.rb b/spec/lib/tasks/data_import_spec.rb index 9a88ef22e..7d36c2a8d 100644 --- a/spec/lib/tasks/data_import_spec.rb +++ b/spec/lib/tasks/data_import_spec.rb @@ -5,7 +5,7 @@ describe "rake core:data_import", type: :task do subject(:task) { Rake::Task["core:data_import"] } let(:instance_name) { "paas_import_instance" } - let(:storage_service) { instance_double(S3StorageService) } + let(:storage_service) { instance_double(Storage::S3Service) } let(:paas_config_service) { instance_double(PaasConfigurationService) } before do @@ -13,7 +13,7 @@ describe "rake core:data_import", type: :task do Rake::Task.define_task(:environment) task.reenable - allow(S3StorageService).to receive(:new).and_return(storage_service) + allow(Storage::S3Service).to receive(:new).and_return(storage_service) allow(PaasConfigurationService).to receive(:new).and_return(paas_config_service) allow(ENV).to receive(:[]) allow(ENV).to receive(:[]).with("IMPORT_PAAS_INSTANCE").and_return(instance_name) @@ -29,7 +29,7 @@ describe "rake core:data_import", type: :task do end it "creates an organisation from the given XML file" do - expect(S3StorageService).to receive(:new).with(paas_config_service, instance_name) + expect(Storage::S3Service).to receive(:new).with(paas_config_service, instance_name) expect(Imports::OrganisationImportService).to receive(:new).with(storage_service) expect(import_service).to receive(:create_organisations).with(fixture_path) @@ -47,7 +47,7 @@ describe "rake core:data_import", type: :task do end it "creates a user from the given XML file" do - expect(S3StorageService).to receive(:new).with(paas_config_service, instance_name) + expect(Storage::S3Service).to receive(:new).with(paas_config_service, instance_name) expect(Imports::UserImportService).to receive(:new).with(storage_service) expect(import_service).to receive(:create_users).with(fixture_path) @@ -65,7 +65,7 @@ describe "rake core:data_import", type: :task do end it "creates an organisation from the given XML file" do - expect(S3StorageService).to receive(:new).with(paas_config_service, instance_name) + expect(Storage::S3Service).to receive(:new).with(paas_config_service, instance_name) expect(Imports::DataProtectionConfirmationImportService).to receive(:new).with(storage_service) expect(import_service).to receive(:create_data_protection_confirmations).with(fixture_path) @@ -83,7 +83,7 @@ describe "rake core:data_import", type: :task do end it "creates an organisation la from the given XML file" do - expect(S3StorageService).to receive(:new).with(paas_config_service, instance_name) + expect(Storage::S3Service).to receive(:new).with(paas_config_service, instance_name) expect(Imports::OrganisationRentPeriodImportService).to receive(:new).with(storage_service) expect(import_service).to receive(:create_organisation_rent_periods).with(fixture_path) @@ -101,7 +101,7 @@ describe "rake core:data_import", type: :task do end it "creates case logs from the given XML file" do - expect(S3StorageService).to receive(:new).with(paas_config_service, instance_name) + expect(Storage::S3Service).to receive(:new).with(paas_config_service, instance_name) expect(Imports::CaseLogsImportService).to receive(:new).with(storage_service) expect(import_service).to receive(:create_logs).with(fixture_path) @@ -119,7 +119,7 @@ describe "rake core:data_import", type: :task do end it "creates a scheme from the given XML file" do - expect(S3StorageService).to receive(:new).with(paas_config_service, instance_name) + expect(Storage::S3Service).to receive(:new).with(paas_config_service, instance_name) expect(Imports::SchemeImportService).to receive(:new).with(storage_service) expect(import_service).to receive(:create_schemes).with(fixture_path) @@ -137,7 +137,7 @@ describe "rake core:data_import", type: :task do end it "creates a scheme location from the given XML file" do - expect(S3StorageService).to receive(:new).with(paas_config_service, instance_name) + expect(Storage::S3Service).to receive(:new).with(paas_config_service, instance_name) expect(Imports::SchemeLocationImportService).to receive(:new).with(storage_service) expect(import_service).to receive(:create_scheme_locations).with(fixture_path) diff --git a/spec/lib/tasks/date_import_field_spec.rb b/spec/lib/tasks/date_import_field_spec.rb index 5dd96ff28..a79a1d379 100644 --- a/spec/lib/tasks/date_import_field_spec.rb +++ b/spec/lib/tasks/date_import_field_spec.rb @@ -5,7 +5,7 @@ describe "rake core:data_import_field", type: :task do subject(:task) { Rake::Task["core:data_import_field"] } let(:instance_name) { "paas_import_instance" } - let(:storage_service) { instance_double(S3StorageService) } + let(:storage_service) { instance_double(Storage::S3Service) } let(:paas_config_service) { instance_double(PaasConfigurationService) } before do @@ -13,7 +13,7 @@ describe "rake core:data_import_field", type: :task do Rake::Task.define_task(:environment) task.reenable - allow(S3StorageService).to receive(:new).and_return(storage_service) + allow(Storage::S3Service).to receive(:new).and_return(storage_service) allow(PaasConfigurationService).to receive(:new).and_return(paas_config_service) allow(ENV).to receive(:[]) allow(ENV).to receive(:[]).with("IMPORT_PAAS_INSTANCE").and_return(instance_name) @@ -32,7 +32,7 @@ describe "rake core:data_import_field", type: :task do let(:field) { "tenant_code" } it "properly configures the storage service" do - expect(S3StorageService).to receive(:new).with(paas_config_service, instance_name) + expect(Storage::S3Service).to receive(:new).with(paas_config_service, instance_name) task.invoke(field, fixture_path) end @@ -46,7 +46,7 @@ describe "rake core:data_import_field", type: :task do let(:field) { "lettings_allocation" } it "properly configures the storage service" do - expect(S3StorageService).to receive(:new).with(paas_config_service, instance_name) + expect(Storage::S3Service).to receive(:new).with(paas_config_service, instance_name) task.invoke(field, fixture_path) end @@ -60,7 +60,7 @@ describe "rake core:data_import_field", type: :task do let(:field) { "major_repairs" } it "properly configures the storage service" do - expect(S3StorageService).to receive(:new).with(paas_config_service, instance_name) + expect(Storage::S3Service).to receive(:new).with(paas_config_service, instance_name) task.invoke(field, fixture_path) end diff --git a/spec/lib/tasks/full_import_spec.rb b/spec/lib/tasks/full_import_spec.rb index c7fedc6dd..78f336197 100644 --- a/spec/lib/tasks/full_import_spec.rb +++ b/spec/lib/tasks/full_import_spec.rb @@ -5,8 +5,8 @@ require "zip" describe "rake core:full_import", type: :task do subject(:task) { Rake::Task["core:full_import"] } - let(:s3_service) { instance_double(S3StorageService) } - let(:archive_service) { instance_double(ArchiveStorageService) } + let(:s3_service) { instance_double(Storage::S3Service) } + let(:archive_service) { instance_double(Storage::ArchiveService) } let(:paas_config_service) { instance_double(PaasConfigurationService) } before do @@ -15,9 +15,9 @@ describe "rake core:full_import", type: :task do task.reenable allow(PaasConfigurationService).to receive(:new).and_return(paas_config_service) - allow(S3StorageService).to receive(:new).and_return(s3_service) + allow(Storage::S3Service).to receive(:new).and_return(s3_service) allow(s3_service).to receive(:get_file_io) - allow(ArchiveStorageService).to receive(:new).and_return(archive_service) + allow(Storage::ArchiveService).to receive(:new).and_return(archive_service) end context "when starting a full import" do diff --git a/spec/services/exports/case_log_export_service_spec.rb b/spec/services/exports/case_log_export_service_spec.rb index fc59cde4e..82124f288 100644 --- a/spec/services/exports/case_log_export_service_spec.rb +++ b/spec/services/exports/case_log_export_service_spec.rb @@ -3,7 +3,7 @@ require "rails_helper" RSpec.describe Exports::CaseLogExportService do subject(:export_service) { described_class.new(storage_service) } - let(:storage_service) { instance_double(S3StorageService) } + let(:storage_service) { instance_double(Storage::S3Service) } let(:xml_export_file) { File.open("spec/fixtures/exports/general_needs_log.xml", "r:UTF-8") } let(:local_manifest_file) { File.open("spec/fixtures/exports/manifest.xml", "r:UTF-8") } diff --git a/spec/services/imports/case_logs_field_import_service_spec.rb b/spec/services/imports/case_logs_field_import_service_spec.rb index 7184ee648..e703c3786 100644 --- a/spec/services/imports/case_logs_field_import_service_spec.rb +++ b/spec/services/imports/case_logs_field_import_service_spec.rb @@ -3,7 +3,7 @@ require "rails_helper" RSpec.describe Imports::CaseLogsFieldImportService do subject(:import_service) { described_class.new(storage_service, logger) } - let(:storage_service) { instance_double(S3StorageService) } + let(:storage_service) { instance_double(Storage::S3Service) } let(:logger) { instance_double(ActiveSupport::Logger) } let(:real_2021_2022_form) { Form.new("config/forms/2021_2022.json", "2021_2022") } diff --git a/spec/services/imports/case_logs_import_service_spec.rb b/spec/services/imports/case_logs_import_service_spec.rb index 30a5cc41e..075244ecf 100644 --- a/spec/services/imports/case_logs_import_service_spec.rb +++ b/spec/services/imports/case_logs_import_service_spec.rb @@ -3,7 +3,7 @@ require "rails_helper" RSpec.describe Imports::CaseLogsImportService do subject(:case_log_service) { described_class.new(storage_service, logger) } - let(:storage_service) { instance_double(S3StorageService) } + let(:storage_service) { instance_double(Storage::S3Service) } let(:logger) { instance_double(ActiveSupport::Logger) } let(:real_2021_2022_form) { Form.new("config/forms/2021_2022.json", "2021_2022") } diff --git a/spec/services/imports/data_protection_confirmation_import_service_spec.rb b/spec/services/imports/data_protection_confirmation_import_service_spec.rb index db5a25046..cb14829b4 100644 --- a/spec/services/imports/data_protection_confirmation_import_service_spec.rb +++ b/spec/services/imports/data_protection_confirmation_import_service_spec.rb @@ -5,7 +5,7 @@ RSpec.describe Imports::DataProtectionConfirmationImportService do let(:old_org_id) { "7c5bd5fb549c09a2c55d7cb90d7ba84927e64618" } let(:old_id) { old_org_id } let(:import_file) { File.open("#{fixture_directory}/#{old_id}.xml") } - let(:storage_service) { instance_double(S3StorageService) } + let(:storage_service) { instance_double(Storage::S3Service) } let(:logger) { instance_double(ActiveSupport::Logger) } context "when importing data protection confirmations" do diff --git a/spec/services/imports/organisation_import_service_spec.rb b/spec/services/imports/organisation_import_service_spec.rb index 5eceea549..48a0d72bb 100644 --- a/spec/services/imports/organisation_import_service_spec.rb +++ b/spec/services/imports/organisation_import_service_spec.rb @@ -1,7 +1,7 @@ require "rails_helper" RSpec.describe Imports::OrganisationImportService do - let(:storage_service) { instance_double(S3StorageService) } + let(:storage_service) { instance_double(Storage::S3Service) } let(:logger) { instance_double(Rails::Rack::Logger) } let(:folder_name) { "organisations" } let(:filenames) { %w[my_folder/my_file1.xml my_folder/my_file2.xml] } diff --git a/spec/services/imports/organisation_rent_period_import_service_spec.rb b/spec/services/imports/organisation_rent_period_import_service_spec.rb index b85bb64e5..adb4899e9 100644 --- a/spec/services/imports/organisation_rent_period_import_service_spec.rb +++ b/spec/services/imports/organisation_rent_period_import_service_spec.rb @@ -5,7 +5,7 @@ RSpec.describe Imports::OrganisationRentPeriodImportService do let(:old_org_id) { "44026acc7ed5c29516b26f2a5deb639e5e37966d" } let(:old_id) { "ebd22326d33e389e9f1bfd546979d2c05f9e68d6" } let(:import_file) { File.open("#{fixture_directory}/#{old_id}.xml") } - let(:storage_service) { instance_double(S3StorageService) } + let(:storage_service) { instance_double(Storage::S3Service) } let(:logger) { instance_double(ActiveSupport::Logger) } context "when importing organisation rent periods" do diff --git a/spec/services/imports/scheme_import_service_spec.rb b/spec/services/imports/scheme_import_service_spec.rb index b6b98d25d..efba81a1c 100644 --- a/spec/services/imports/scheme_import_service_spec.rb +++ b/spec/services/imports/scheme_import_service_spec.rb @@ -3,7 +3,7 @@ require "rails_helper" RSpec.describe Imports::SchemeImportService do subject(:scheme_service) { described_class.new(storage_service, logger) } - let(:storage_service) { instance_double(S3StorageService) } + let(:storage_service) { instance_double(Storage::S3Service) } let(:logger) { instance_double(ActiveSupport::Logger) } let(:fixture_directory) { "spec/fixtures/imports/mgmtgroups" } diff --git a/spec/services/imports/scheme_location_import_service_spec.rb b/spec/services/imports/scheme_location_import_service_spec.rb index 95a5b2b9e..c70ca3904 100644 --- a/spec/services/imports/scheme_location_import_service_spec.rb +++ b/spec/services/imports/scheme_location_import_service_spec.rb @@ -3,7 +3,7 @@ require "rails_helper" RSpec.describe Imports::SchemeLocationImportService do subject(:location_service) { described_class.new(storage_service, logger) } - let(:storage_service) { instance_double(S3StorageService) } + let(:storage_service) { instance_double(Storage::S3Service) } let(:logger) { instance_double(ActiveSupport::Logger) } let(:fixture_directory) { "spec/fixtures/imports/schemes" } diff --git a/spec/services/imports/user_import_service_spec.rb b/spec/services/imports/user_import_service_spec.rb index b9e3028c9..c4aea00bc 100644 --- a/spec/services/imports/user_import_service_spec.rb +++ b/spec/services/imports/user_import_service_spec.rb @@ -5,7 +5,7 @@ RSpec.describe Imports::UserImportService do let(:old_user_id) { "fc7625a02b24ae16162aa63ae7cb33feeec0c373" } let(:old_org_id) { "7c5bd5fb549c09a2c55d7cb90d7ba84927e64618" } let(:user_file) { File.open("#{fixture_directory}/#{old_user_id}.xml") } - let(:storage_service) { instance_double(S3StorageService) } + let(:storage_service) { instance_double(Storage::S3Service) } let(:logger) { instance_double(ActiveSupport::Logger) } let(:notify_client) { instance_double(Notifications::Client) } let(:devise_notify_mailer) { DeviseNotifyMailer.new } diff --git a/spec/services/archive_storage_service_spec.rb b/spec/services/storage/archive_service_spec.rb similarity index 98% rename from spec/services/archive_storage_service_spec.rb rename to spec/services/storage/archive_service_spec.rb index fb33e4dd3..52808262f 100644 --- a/spec/services/archive_storage_service_spec.rb +++ b/spec/services/storage/archive_service_spec.rb @@ -1,6 +1,6 @@ require "rails_helper" -RSpec.describe ArchiveStorageService do +RSpec.describe Storage::ArchiveService do subject(:archive_service) { described_class.new(archive_content) } let(:compressed_folder) { "my_directory" } diff --git a/spec/services/s3_storage_service_spec.rb b/spec/services/storage/s3_service_spec.rb similarity index 96% rename from spec/services/s3_storage_service_spec.rb rename to spec/services/storage/s3_service_spec.rb index c89b7c1bb..6c0f0eeb1 100644 --- a/spec/services/s3_storage_service_spec.rb +++ b/spec/services/storage/s3_service_spec.rb @@ -1,6 +1,6 @@ require "rails_helper" -RSpec.describe S3StorageService do +RSpec.describe Storage::S3Service do let(:instance_name) { "instance_1" } let(:bucket_name) { "bucket_1" } let(:vcap_services) do @@ -48,11 +48,11 @@ RSpec.describe S3StorageService do end it "creates a Storage Configuration" do - expect(storage_service.configuration).to be_an(StorageConfiguration) + expect(storage_service.configuration).to be_an(Storage::StorageConfiguration) end it "sets the expected parameters in the configuration" do - expected_configuration = StorageConfiguration.new( + expected_configuration = Storage::StorageConfiguration.new( { aws_access_key_id: "key_id", aws_region: "eu-west-2",