Class: Fog::Storage::AzureRM::File
- Inherits:
-
Model
- Object
- Model
- Fog::Storage::AzureRM::File
- Defined in:
- lib/fog/azurerm/models/storage/file.rb
Overview
This class is giving implementation of create/save and delete/destroy for Blob.
Instance Attribute Summary collapse
-
#body ⇒ File || String
Get file’s body if exists, else ”.
Instance Method Summary collapse
-
#copy(target_directory_key, target_file_key, options = {}) ⇒ Fog::Storage::AzureRM::File
Copy object from one container to other container.
-
#copy_from_uri(source_uri, options = {}) ⇒ Boolean
Copy object from a uri.
-
#destroy(options = {}) ⇒ Boolean
Destroy file.
-
#public? ⇒ Boolean
Get whether the file can be accessed by anonymous.
-
#public_url(options = {}) ⇒ String
Get publicly accessible url.
-
#save(options = {}) ⇒ Boolean
Save the file to the directory in Azure storage.
-
#url(expires, options = {}) ⇒ String
Get a url for file.
Instance Attribute Details
#body ⇒ File || String
Get file’s body if exists, else ”.
116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/fog/azurerm/models/storage/file.rb', line 116 def body return attributes[:body] if attributes[:body] return '' unless last_modified file = collection.get(identity) if file.nil? attributes[:body] = '' return '' end attributes[:body] = file.body end |
Instance Method Details
#copy(target_directory_key, target_file_key, options = {}) ⇒ Fog::Storage::AzureRM::File
Copy object from one container to other container.
required attributes: directory, key
150 151 152 153 154 155 156 157 158 159 |
# File 'lib/fog/azurerm/models/storage/file.rb', line 150 def copy(target_directory_key, target_file_key, = {}) requires :directory, :key timeout = .delete(:timeout) copy_id, copy_status = service.copy_blob(target_directory_key, target_file_key, directory.key, key, ) service.wait_blob_copy_operation_to_finish(target_directory_key, target_file_key, copy_id, copy_status, timeout) target_directory = service.directories.new(key: target_directory_key) target_directory.files.head(target_file_key) end |
#copy_from_uri(source_uri, options = {}) ⇒ Boolean
Copy object from a uri.
required attributes: directory, key
171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/fog/azurerm/models/storage/file.rb', line 171 def copy_from_uri(source_uri, = {}) requires :directory, :key timeout = .delete(:timeout) copy_id, copy_status = service.copy_blob_from_uri(directory.key, key, source_uri, ) service.wait_blob_copy_operation_to_finish(directory.key, key, copy_id, copy_status, timeout) blob = service.get_blob_properties(directory.key, key) data = parse_storage_object(blob) merge_attributes(data) true end |
#destroy(options = {}) ⇒ Boolean
Destroy file.
required attributes: directory, key
194 195 196 197 198 199 200 201 |
# File 'lib/fog/azurerm/models/storage/file.rb', line 194 def destroy( = {}) requires :key requires :directory attributes[:body] = nil service.delete_blob(directory.key, key, ) true end |
#public? ⇒ Boolean
Get whether the file can be accessed by anonymous.
207 208 209 210 211 212 |
# File 'lib/fog/azurerm/models/storage/file.rb', line 207 def public? requires :directory # TBD: The blob can be accessed if read permision is set in one access policy of the container. directory.acl == 'container' || directory.acl == 'blob' end |
#public_url(options = {}) ⇒ String
Get publicly accessible url.
required attributes: directory, key
223 224 225 226 227 |
# File 'lib/fog/azurerm/models/storage/file.rb', line 223 def public_url( = {}) requires :directory, :key [:scheme] == 'https' if [:scheme].nil? @service.get_blob_url(directory.key, key, ) if public? end |
#save(options = {}) ⇒ Boolean
Save the file to the directory in Azure storage. TODO: Support snapshots.
required attributes: body(Only if update_body is true), directory, key
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/fog/azurerm/models/storage/file.rb', line 64 def save( = {}) update_body = .delete(:update_body) update_body = true if update_body.nil? requires :directory, :key raise ArgumentError.new('body is required when update_body is true') if update_body && attributes[:body].nil? remap_attributes( , 'Blob-Type' => :blob_type, 'Content-Type' => :content_type, 'Content-MD5' => :content_md5, 'Content-Encoding' => :content_encoding, 'Content-Language' => :content_language, 'Cache-Control' => :cache_control, 'Content-Disposition' => :content_disposition ) = { blob_type: blob_type, content_type: content_type, content_md5: content_md5, content_encoding: content_encoding, content_language: content_language, cache_control: cache_control, content_disposition: content_disposition, metadata: }.merge!() = .reject { |_key, value| value.nil? || value.to_s.empty? } if update_body blob = save_blob() data = parse_storage_object(blob) merge_attributes(data) attributes[:content_length] = Fog::Storage.get_body_size(body) attributes[:content_type] ||= Fog::Storage.get_content_type(body) else service.(directory.key, key, [:metadata]) if [:metadata] .delete(:metadata) service.put_blob_properties(directory.key, key, ) blob = service.get_blob_properties(directory.key, key) data = parse_storage_object(blob) merge_attributes(data) end true end |
#url(expires, options = {}) ⇒ String
Get a url for file.
required attributes: key
239 240 241 242 |
# File 'lib/fog/azurerm/models/storage/file.rb', line 239 def url(expires, = {}) requires :key collection.get_url(key, expires, ) end |