Class: Fog::AzureRM::Storage::Files

Inherits:
Collection
  • Object
show all
Includes:
Utilities::General
Defined in:
lib/fog/azurerm/models/storage/files.rb

Overview

This class is giving implementation of listing blobs.

Instance Method Summary collapse

Methods included from Utilities::General

#get_blob_endpoint, #get_blob_endpoint_with_domain, #get_circuit_name_from_id, #get_end_point_type, #get_hash_from_object, #get_image_name, #get_record_set_from_id, #get_record_type, #get_resource_from_resource_id, #get_resource_group_from_id, #get_subscription_id, #get_traffic_manager_profile_name_from_endpoint_id, #get_type_from_recordset_type, #get_virtual_machine_from_id, #get_virtual_network_from_id, #parse_storage_object, #raise_azure_exception, #random_string, #remove_trailing_periods_from_path_segments, #storage_endpoint_suffix, #validate_params

Instance Method Details

#all(options = {}) ⇒ Fog::AzureRM::Storage::Files

List all files(blobs) under the directory.

required attributes: directory

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • max_keys (String)

    or max_results Sets the maximum number of files to return.

  • delimiter (String)

    Sets to cause that the operation returns a BlobPrefix element in the response body that acts as a placeholder for all files whose names begin with the same substring up to the appearance of the delimiter character. The delimiter may be a single character or a string.

  • marker (String)

    Sets the identifier that specifies the portion of the list to be returned.

  • prefix (String)

    Sets filters the results to return only files whose name begins with the specified prefix.

Returns:



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/fog/azurerm/models/storage/files.rb', line 32

def all(options = {})
  requires :directory

  options = {
    max_results: max_results,
    delimiter: delimiter,
    marker: marker,
    prefix: prefix
  }.merge!(options)
  options = options.reject { |_key, value| value.nil? || value.to_s.empty? }
  merge_attributes(options)
  parent = directory.collection.get(
    directory.key,
    options
  )
  return nil unless parent

  merge_attributes(parent.files.attributes)
  load(parent.files.map(&:attributes))
end

#eachObject



58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/fog/azurerm/models/storage/files.rb', line 58

def each
  if block_given?
    subset = dup.all

    subset.each_file_this_page { |f| yield f }
    while subset.next_marker
      subset = subset.all(marker: subset.next_marker)
      subset.each_file_this_page { |f| yield f }
    end
  end

  self
end

#each_file_this_pageFog::AzureRM::Storage::Files

Enumerate every file under the directory if block_given?



57
# File 'lib/fog/azurerm/models/storage/files.rb', line 57

alias each_file_this_page each

#get(key, options = {}, &block) ⇒ Fog::AzureRM::Storage::File

Get the file(blob) with full content as :body with the given name.

required attributes: directory

Parameters:

  • key (String)

    Name of file

  • options (Hash) (defaults to: {})

Options Hash (options):

  • block_size (String)

    Sets buffer size when block_given? is true. Default is 32 MB

Returns:



82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/fog/azurerm/models/storage/files.rb', line 82

def get(key, options = {}, &block)
  requires :directory

  blob, content = service.get_blob(directory.key, key, options, &block)
  data = parse_storage_object(blob)
  file_data = data.merge(
    body: content,
    key: key
  )
  new(file_data)
rescue => error
  return nil if error.message == 'NotFound'
  raise error
end

#get_http_url(key, expires, options = {}) ⇒ String

Get the http URL of the file(blob) with the given name.

required attributes: directory

Parameters:

  • key (String)

    Name of file

  • expires (Time)

    The time at which the shared access signature becomes invalid, in a UTC format.

  • options (Hash) (defaults to: {})

    Unused. To keep same interface as other providers.

Returns:

  • (String)

    A http URL.



128
129
130
131
132
# File 'lib/fog/azurerm/models/storage/files.rb', line 128

def get_http_url(key, expires, options = {})
  requires :directory

  service.get_blob_http_url(directory.key, key, expires, options)
end

#get_https_url(key, expires, options = {}) ⇒ String

Get the https URL of the file(blob) with the given name.

required attributes: directory

Parameters:

  • key (String)

    Name of file

  • expires (Time)

    The time at which the shared access signature becomes invalid, in a UTC format.

  • options (Hash) (defaults to: {})

    Unused. To keep same interface as other providers.

Returns:

  • (String)

    A https URL.



144
145
146
147
148
# File 'lib/fog/azurerm/models/storage/files.rb', line 144

def get_https_url(key, expires, options = {})
  requires :directory

  service.get_blob_https_url(directory.key, key, expires, options)
end

#get_url(key, expires, options = {}) ⇒ String

Get the URL of the file(blob) with the given name.

required attributes: directory

Parameters:

  • key (String)

    Name of file

  • expires (Time)

    The time at which the shared access signature becomes invalid, in a UTC format.

  • options (Hash) (defaults to: {})

Options Hash (options):

  • scheme (String)

    Sets which URL to get, http or https. Options: https or http. Default is https.

Returns:

  • (String)

    A URL.



108
109
110
111
112
113
114
115
116
# File 'lib/fog/azurerm/models/storage/files.rb', line 108

def get_url(key, expires, options = {})
  requires :directory

  if options[:scheme] == 'http'
    get_http_url(key, expires, options)
  else
    get_https_url(key, expires, options)
  end
end

#head(key, options = {}) ⇒ Fog::AzureRM::Storage::File

Get the file(blob) without content with the given name.

required attributes: directory

Parameters:

  • key (String)

    Name of file

  • options (Hash) (defaults to: {})

Returns:



159
160
161
162
163
164
165
166
167
168
169
# File 'lib/fog/azurerm/models/storage/files.rb', line 159

def head(key, options = {})
  requires :directory

  blob = service.get_blob_properties(directory.key, key, options)
  data = parse_storage_object(blob)
  file_data = data.merge(key: key)
  new(file_data)
rescue => error
  return nil if error.message == 'NotFound'
  raise error
end

#new(attributes = {}) ⇒ Fog::AzureRM::Storage::File

Create a new file.

required attributes: directory

Returns:



177
178
179
180
181
# File 'lib/fog/azurerm/models/storage/files.rb', line 177

def new(attributes = {})
  requires :directory

  super({ directory: directory }.merge!(attributes))
end