chore: build openstack client without calling now private service.client

This commit is contained in:
simon lehericey 2023-09-07 15:13:58 +02:00
parent bc34ec0104
commit 5534190c89
3 changed files with 24 additions and 3 deletions

View file

@ -1,3 +1,5 @@
require 'fog/openstack'
class PjsMigrationJob < ApplicationJob
queue_as :pj_migration_jobs
@ -7,7 +9,6 @@ class PjsMigrationJob < ApplicationJob
return if already_moved?(blob)
service = blob.service
client = service.client
container = service.container
old_key = blob.key
new_key = "#{blob.created_at.strftime('%Y/%m/%d')}/#{old_key[0..1]}/#{old_key}"
@ -28,4 +29,14 @@ class PjsMigrationJob < ApplicationJob
def already_moved?(blob)
blob.key.include?('/')
end
private
def client
@client ||= begin
credentials = Rails.application.config.active_storage
.service_configurations['openstack']['credentials']
Fog::OpenStack::Storage.new(credentials)
end
end
end

View file

@ -1,3 +1,5 @@
require 'fog/openstack'
class ActiveStorage::DownloadableFile
def self.create_list_from_dossiers(
dossiers,
@ -20,7 +22,6 @@ class ActiveStorage::DownloadableFile
true
else
service = file.blob.service
client = service.client
begin
client.head_object(service.container, file.blob.key)
true
@ -33,6 +34,13 @@ class ActiveStorage::DownloadableFile
private
def self.client
credentials = Rails.application.config.active_storage
.service_configurations['openstack']['credentials']
Fog::OpenStack::Storage.new(credentials)
end
def self.bill_and_path(bill)
[
bill,

View file

@ -35,11 +35,13 @@ describe ActiveStorage::DownloadableFile do
let(:available_blob_key) { 'available' }
let(:unavailable_blob_key) { 'broken' }
let(:active_storage_client) { double }
let(:active_storage_service) { double(client: active_storage_client, container: object_storage_container) }
let(:active_storage_service) { double(container: object_storage_container) }
before do
require 'fog/openstack'
Rails.application.config.active_storage.service = :openstack
allow(ActiveStorage::DownloadableFile).to receive(:client).and_return(active_storage_client)
end
after { Rails.application.config.active_storage.service = :test }