chore: build openstack client without calling now private service.client
This commit is contained in:
parent
bc34ec0104
commit
5534190c89
3 changed files with 24 additions and 3 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
require 'fog/openstack'
|
||||||
|
|
||||||
class PjsMigrationJob < ApplicationJob
|
class PjsMigrationJob < ApplicationJob
|
||||||
queue_as :pj_migration_jobs
|
queue_as :pj_migration_jobs
|
||||||
|
|
||||||
|
@ -7,7 +9,6 @@ class PjsMigrationJob < ApplicationJob
|
||||||
return if already_moved?(blob)
|
return if already_moved?(blob)
|
||||||
|
|
||||||
service = blob.service
|
service = blob.service
|
||||||
client = service.client
|
|
||||||
container = service.container
|
container = service.container
|
||||||
old_key = blob.key
|
old_key = blob.key
|
||||||
new_key = "#{blob.created_at.strftime('%Y/%m/%d')}/#{old_key[0..1]}/#{old_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)
|
def already_moved?(blob)
|
||||||
blob.key.include?('/')
|
blob.key.include?('/')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def client
|
||||||
|
@client ||= begin
|
||||||
|
credentials = Rails.application.config.active_storage
|
||||||
|
.service_configurations['openstack']['credentials']
|
||||||
|
Fog::OpenStack::Storage.new(credentials)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
require 'fog/openstack'
|
||||||
|
|
||||||
class ActiveStorage::DownloadableFile
|
class ActiveStorage::DownloadableFile
|
||||||
def self.create_list_from_dossiers(
|
def self.create_list_from_dossiers(
|
||||||
dossiers,
|
dossiers,
|
||||||
|
@ -20,7 +22,6 @@ class ActiveStorage::DownloadableFile
|
||||||
true
|
true
|
||||||
else
|
else
|
||||||
service = file.blob.service
|
service = file.blob.service
|
||||||
client = service.client
|
|
||||||
begin
|
begin
|
||||||
client.head_object(service.container, file.blob.key)
|
client.head_object(service.container, file.blob.key)
|
||||||
true
|
true
|
||||||
|
@ -33,6 +34,13 @@ class ActiveStorage::DownloadableFile
|
||||||
|
|
||||||
private
|
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)
|
def self.bill_and_path(bill)
|
||||||
[
|
[
|
||||||
bill,
|
bill,
|
||||||
|
|
|
@ -35,11 +35,13 @@ describe ActiveStorage::DownloadableFile do
|
||||||
let(:available_blob_key) { 'available' }
|
let(:available_blob_key) { 'available' }
|
||||||
let(:unavailable_blob_key) { 'broken' }
|
let(:unavailable_blob_key) { 'broken' }
|
||||||
let(:active_storage_client) { double }
|
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
|
before do
|
||||||
require 'fog/openstack'
|
require 'fog/openstack'
|
||||||
Rails.application.config.active_storage.service = :openstack
|
Rails.application.config.active_storage.service = :openstack
|
||||||
|
|
||||||
|
allow(ActiveStorage::DownloadableFile).to receive(:client).and_return(active_storage_client)
|
||||||
end
|
end
|
||||||
after { Rails.application.config.active_storage.service = :test }
|
after { Rails.application.config.active_storage.service = :test }
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue