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
- #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
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/cnvrg/downloader/client.rb', line 40 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' return Cnvrg::Downloader::Clients::AzureDownloader.new(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
#decrypt(str) ⇒ Object
36 37 38 |
# File 'lib/cnvrg/downloader/client.rb', line 36 def decrypt(str) Cnvrg::Helpers.decrypt(@key, @iv, str) end |
#download(storage_path, local_path) ⇒ Object
20 21 22 |
# File 'lib/cnvrg/downloader/client.rb', line 20 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
28 29 30 |
# File 'lib/cnvrg/downloader/client.rb', line 28 def mkdir(path, recursive: false) recursive ? FileUtils.mkdir_p(path) : FileUtils.mkdir(path) end |
#prepare_download(local_path) ⇒ Object
32 33 34 |
# File 'lib/cnvrg/downloader/client.rb', line 32 def prepare_download(local_path) mkdir(File.dirname(local_path), recursive: true) end |
#upload(storage_path, local_path) ⇒ Object
24 25 26 |
# File 'lib/cnvrg/downloader/client.rb', line 24 def upload(storage_path, local_path) ### need to be implemented.. end |