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 ”.
118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/fog/azurerm/models/storage/file.rb', line 118 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
152 153 154 155 156 157 158 159 160 161 |
# File 'lib/fog/azurerm/models/storage/file.rb', line 152 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
173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/fog/azurerm/models/storage/file.rb', line 173 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
196 197 198 199 200 201 202 203 |
# File 'lib/fog/azurerm/models/storage/file.rb', line 196 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.
209 210 211 212 213 214 |
# File 'lib/fog/azurerm/models/storage/file.rb', line 209 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
225 226 227 228 229 |
# File 'lib/fog/azurerm/models/storage/file.rb', line 225 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
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 111 112 |
# File 'lib/fog/azurerm/models/storage/file.rb', line 66 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
241 242 243 244 |
# File 'lib/fog/azurerm/models/storage/file.rb', line 241 def url(expires, = {}) requires :key collection.get_url(key, expires, ) end |