Class: Cnvrg::Downloader::Clients::AzureClient

Inherits:
Cnvrg::Downloader::Client show all
Defined in:
lib/cnvrg/downloader/clients/azure_client.rb

Instance Method Summary collapse

Methods inherited from Cnvrg::Downloader::Client

#cut_prefix, #decrypt, #extract_key_iv, factory, #link_file, #mkdir, #prepare_download, #safe_download, #safe_operation, #safe_upload

Constructor Details

#initialize(storage_account_name: nil, storage_access_key: nil, container: nil, sts: nil) ⇒ AzureClient

Returns a new instance of AzureClient.



7
8
9
10
11
12
# File 'lib/cnvrg/downloader/clients/azure_client.rb', line 7

def initialize(storage_account_name: nil, storage_access_key: nil, container: nil, sts: nil)
  @key, @iv = extract_key_iv(sts)
  @account_name = Cnvrg::Helpers.decrypt(@key, @iv, )
  @access_key = Cnvrg::Helpers.decrypt(@key, @iv, storage_access_key)
  @container = Cnvrg::Helpers.decrypt(@key, @iv, container)
end

Instance Method Details

#download(storage_path, local_path, decrypt: true) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/cnvrg/downloader/clients/azure_client.rb', line 14

def download(storage_path, local_path, decrypt: true)
  prepare_download(local_path)
  storage_path = Cnvrg::Helpers.decrypt(@key, @iv, storage_path) if decrypt
  blob, content = client.get_blob(@container, storage_path)
  ::File.open(local_path, 'wb') {|f| f.write(content)}
  blob
end

#fetch_files(prefix: nil, marker: nil, limit: 10000) ⇒ Object



30
31
32
33
34
35
# File 'lib/cnvrg/downloader/clients/azure_client.rb', line 30

def fetch_files(prefix: nil, marker: nil, limit: 10000)
  blobs = client.list_blobs(@container, prefix: prefix, max_results: limit, marker: marker)
  next_marker = blobs.continuation_token
  files = blobs.map{|x| x.name}
  [files, next_marker]
end

#upload(storage_path, local_path) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/cnvrg/downloader/clients/azure_client.rb', line 22

def upload(storage_path, local_path)
  begin
    client.create_block_blob(@container, storage_path, File.open(local_path, "rb"))
  rescue => e
    raise e
  end
end