Browse Source

feat: update application to use non paas and paas configuration services, add helper to determine if platform is paas

feat: don't double-instantiate the configuration service

feat: add self. to is_paas? definition, and require module in rack_attack

chore: lint
pull/1822/head
Sam Seed 3 years ago committed by Chirag-Bhatti
parent
commit
5e3b175416
  1. 5
      app/helpers/platform_helper.rb
  2. 2
      app/jobs/data_export_xml_job.rb
  3. 2
      app/models/forms/bulk_upload_lettings/upload_your_file.rb
  4. 2
      app/models/forms/bulk_upload_sales/upload_your_file.rb
  5. 2
      app/services/bulk_upload/downloader.rb
  6. 8
      config/initializers/rack_attack.rb
  7. 6
      config/initializers/sidekiq.rb
  8. 2
      lib/tasks/data_import.rake
  9. 2
      lib/tasks/data_import_field.rake
  10. 8
      lib/tasks/full_import.rake

5
app/helpers/platform_helper.rb

@ -0,0 +1,5 @@
module PlatformHelper
def self.is_paas?
!ENV["VCAP_SERVICES"].nil?
end
end

2
app/jobs/data_export_xml_job.rb

@ -2,7 +2,7 @@ class DataExportXmlJob < ApplicationJob
queue_as :default
def perform(full_update: false)
storage_service = Storage::S3Service.new(Configuration::PaasConfigurationService.new, ENV["EXPORT_PAAS_INSTANCE"])
storage_service = Storage::S3Service.new(PlatformHelper.is_paas? ? Configuration::PaasConfigurationService.new : Configuration::EnvConfigurationService.new, ENV["EXPORT_PAAS_INSTANCE"])
export_service = Exports::LettingsLogExportService.new(storage_service)
export_service.export_xml_lettings_logs(full_update:)

2
app/models/forms/bulk_upload_lettings/upload_your_file.rb

@ -57,7 +57,7 @@ module Forms
def storage_service
@storage_service ||= if upload_enabled?
Storage::S3Service.new(
Configuration::PaasConfigurationService.new,
PlatformHelper.is_paas? ? Configuration::PaasConfigurationService.new : Configuration::EnvConfigurationService.new,
ENV["CSV_DOWNLOAD_PAAS_INSTANCE"],
)
else

2
app/models/forms/bulk_upload_sales/upload_your_file.rb

@ -50,7 +50,7 @@ module Forms
def storage_service
@storage_service ||= if FeatureToggle.upload_enabled?
Storage::S3Service.new(
Configuration::PaasConfigurationService.new,
PlatformHelper.is_paas? ? Configuration::PaasConfigurationService.new : Configuration::EnvConfigurationService.new,
ENV["CSV_DOWNLOAD_PAAS_INSTANCE"],
)
else

2
app/services/bulk_upload/downloader.rb

@ -38,7 +38,7 @@ private
def s3_storage_service
Storage::S3Service.new(
Configuration::PaasConfigurationService.new,
PlatformHelper.is_paas? ? Configuration::PaasConfigurationService.new : Configuration::EnvConfigurationService.new,
ENV["CSV_DOWNLOAD_PAAS_INSTANCE"],
)
end

8
config/initializers/rack_attack.rb

@ -1,14 +1,18 @@
require "configuration/configuration_service"
require "configuration/paas_configuration_service"
require "configuration/env_configuration_service"
require Rails.root.join("app/helpers/platform_helper")
configuration_service = PlatformHelper.is_paas? ? Configuration::PaasConfigurationService.new : Configuration::EnvConfigurationService.new
if Rails.env.development? || Rails.env.test?
Rack::Attack.cache.store = ActiveSupport::Cache::MemoryStore.new
Rack::Attack.enabled = false
elsif Rails.env.review?
redis_url = Configuration::PaasConfigurationService.new.redis_uris.to_a[0][1]
redis_url = configuration_service.redis_uris.to_a[0][1]
Rack::Attack.cache.store = ActiveSupport::Cache::RedisCacheStore.new(url: redis_url)
else
redis_url = Configuration::PaasConfigurationService.new.redis_uris[:"dluhc-core-#{Rails.env}-redis"]
redis_url = configuration_service.redis_uris[:"dluhc-core-#{Rails.env}-redis"]
Rack::Attack.cache.store = ActiveSupport::Cache::RedisCacheStore.new(url: redis_url)
end

6
config/initializers/sidekiq.rb

@ -1,8 +1,10 @@
require "sidekiq/web"
require "sidekiq/cron/web"
configuration_service = PlatformHelper.is_paas? ? Configuration::PaasConfigurationService.new : Configuration::EnvConfigurationService.new
if Rails.env.staging? || Rails.env.production?
redis_url = Configuration::PaasConfigurationService.new.redis_uris[:"dluhc-core-#{Rails.env}-redis"]
redis_url = configuration_service.redis_uris[:"dluhc-core-#{Rails.env}-redis"]
Sidekiq.configure_server do |config|
config.redis = { url: redis_url }
@ -14,7 +16,7 @@ if Rails.env.staging? || Rails.env.production?
end
if Rails.env.review?
redis_url = Configuration::PaasConfigurationService.new.redis_uris.to_a[0][1]
redis_url = configuration_service.redis_uris.to_a[0][1]
Sidekiq.configure_server do |config|
config.redis = { url: redis_url }

2
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 = Storage::S3Service.new(Configuration::PaasConfigurationService.new, ENV["IMPORT_PAAS_INSTANCE"])
storage_service = Storage::S3Service.new(PlatformHelper.is_paas? ? Configuration::PaasConfigurationService.new : Configuration::EnvConfigurationService.new, ENV["IMPORT_PAAS_INSTANCE"])
case type
when "organisation"

2
lib/tasks/data_import_field.rake

@ -8,7 +8,7 @@ namespace :core do
# We only allow a reduced list of known fields to be updatable
case field
when "tenancycode", "major_repairs", "lettings_allocation", "offered"
s3_service = Storage::S3Service.new(Configuration::PaasConfigurationService.new, ENV["IMPORT_PAAS_INSTANCE"])
s3_service = Storage::S3Service.new(PlatformHelper.is_paas? ? Configuration::PaasConfigurationService.new : Configuration::EnvConfigurationService.new, ENV["IMPORT_PAAS_INSTANCE"])
archive_io = s3_service.get_file_io(path)
archive_service = Storage::ArchiveService.new(archive_io)
if archive_service.folder_present?("logs")

8
lib/tasks/full_import.rake

@ -6,7 +6,7 @@ namespace :import do
institutions_csv_name = args[:institutions_csv_name]
raise "Usage: rake import:initial['institutions_csv_name']" if institutions_csv_name.blank?
s3_service = Storage::S3Service.new(Configuration::PaasConfigurationService.new, ENV["IMPORT_PAAS_INSTANCE"])
s3_service = Storage::S3Service.new(PlatformHelper.is_paas? ? Configuration::PaasConfigurationService.new : Configuration::EnvConfigurationService.new, ENV["IMPORT_PAAS_INSTANCE"])
csv = CSV.parse(s3_service.get_file_io(institutions_csv_name), headers: true)
org_count = csv.length
@ -43,7 +43,7 @@ namespace :import do
institutions_csv_name = args[:institutions_csv_name]
raise "Usage: rake import:logs['institutions_csv_name']" if institutions_csv_name.blank?
s3_service = Storage::S3Service.new(Configuration::PaasConfigurationService.new, ENV["IMPORT_PAAS_INSTANCE"])
s3_service = Storage::S3Service.new(PlatformHelper.is_paas? ? Configuration::PaasConfigurationService.new : Configuration::EnvConfigurationService.new, ENV["IMPORT_PAAS_INSTANCE"])
csv = CSV.parse(s3_service.get_file_io(institutions_csv_name), headers: true)
org_count = csv.length
@ -77,7 +77,7 @@ namespace :import do
institutions_csv_name = args[:institutions_csv_name]
raise "Usage: rake import:trigger_invites['institutions_csv_name']" if institutions_csv_name.blank?
s3_service = Storage::S3Service.new(Configuration::PaasConfigurationService.new, ENV["IMPORT_PAAS_INSTANCE"])
s3_service = Storage::S3Service.new(PlatformHelper.is_paas? ? Configuration::PaasConfigurationService.new : Configuration::EnvConfigurationService.new, ENV["IMPORT_PAAS_INSTANCE"])
csv = CSV.parse(s3_service.get_file_io(institutions_csv_name), headers: true)
Rails.logger.info("Triggering user invite emails")
@ -98,7 +98,7 @@ namespace :import do
institutions_csv_name = args[:institutions_csv_name]
raise "Usage: rake import:generate_reports['institutions_csv_name']" if institutions_csv_name.blank?
s3_service = Storage::S3Service.new(Configuration::PaasConfigurationService.new, ENV["IMPORT_PAAS_INSTANCE"])
s3_service = Storage::S3Service.new(PlatformHelper.is_paas? ? Configuration::PaasConfigurationService.new : Configuration::EnvConfigurationService.new, ENV["IMPORT_PAAS_INSTANCE"])
institutions_csv = CSV.parse(s3_service.get_file_io(institutions_csv_name), headers: true)
Imports::ImportReportService.new(s3_service, institutions_csv).create_reports(institutions_csv_name)

Loading…
Cancel
Save