Class: Cnvrg::Downloader::Client
- Inherits:
-
Object
- Object
- Cnvrg::Downloader::Client
- Defined in:
- lib/cnvrg/downloader/client.rb
Direct Known Subclasses
Cnvrg::Downloader::Clients::AzureClient, Cnvrg::Downloader::Clients::GcpClient, Cnvrg::Downloader::Clients::S3Client
Class Method Summary collapse
Instance Method Summary collapse
- #cut_prefix(prefix, file) ⇒ Object
- #decrypt(str) ⇒ Object
- #download(storage_path, local_path) ⇒ Object
- #extract_key_iv(sts_path) ⇒ Object
-
#initialize(params) ⇒ Client
constructor
A new instance of Client.
- #mkdir(path, recursive: false) ⇒ Object
- #prepare_download(local_path) ⇒ Object
- #upload(storage_path, local_path) ⇒ Object
Constructor Details
#initialize(params) ⇒ Client
Returns a new instance of Client.
7 8 9 10 11 12 |
# File 'lib/cnvrg/downloader/client.rb', line 7 def initialize(params) @key = '' @iv = '' @client = '' @bucket = '' end |
Class Method Details
.factory(params) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/cnvrg/downloader/client.rb', line 44 def self.factory(params) params = params.as_json case params["storage"] when 's3', 'minio' return Cnvrg::Downloader::Clients::S3Client.new(sts_path: params["path_sts"], access_key: params["sts_a"], secret: params["sts_s"], session_token: params["sts_st"], region: params["region"], bucket: params["bucket"], encryption: params["encryption"], endpoint: params["endpoint"], storage: params["storage"]) when 'azure' azure_params = params.symbolize_keys.slice(*[:storage_account_name, :storage_access_key, :container, :sts]) return Cnvrg::Downloader::Clients::AzureClient.new(**azure_params) when 'gcp' return Cnvrg::Downloader::Clients::GcpClient.new(project_id: params["project_id"], credentials: params["credentials"], bucket_name: params["bucket_name"], sts: params["sts"]) end end |
Instance Method Details
#cut_prefix(prefix, file) ⇒ Object
20 21 22 |
# File 'lib/cnvrg/downloader/client.rb', line 20 def cut_prefix(prefix, file) file.gsub(prefix, '').gsub(/^\/*/, '') end |
#decrypt(str) ⇒ Object
40 41 42 |
# File 'lib/cnvrg/downloader/client.rb', line 40 def decrypt(str) Cnvrg::Helpers.decrypt(@key, @iv, str) end |
#download(storage_path, local_path) ⇒ Object
24 25 26 |
# File 'lib/cnvrg/downloader/client.rb', line 24 def download(storage_path, local_path) ### need to be implemented.. end |
#extract_key_iv(sts_path) ⇒ Object
14 15 16 17 18 |
# File 'lib/cnvrg/downloader/client.rb', line 14 def extract_key_iv(sts_path) sts = open(sts_path).read rescue nil raise StandardError.new("Cant open sts") if sts.blank? sts.split("\n") end |
#mkdir(path, recursive: false) ⇒ Object
32 33 34 |
# File 'lib/cnvrg/downloader/client.rb', line 32 def mkdir(path, recursive: false) recursive ? FileUtils.mkdir_p(path) : FileUtils.mkdir(path) end |
#prepare_download(local_path) ⇒ Object
36 37 38 |
# File 'lib/cnvrg/downloader/client.rb', line 36 def prepare_download(local_path) mkdir(File.dirname(local_path), recursive: true) end |
#upload(storage_path, local_path) ⇒ Object
28 29 30 |
# File 'lib/cnvrg/downloader/client.rb', line 28 def upload(storage_path, local_path) ### need to be implemented.. end |