gitlab-fog-azure-rm 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (144) hide show
  1. checksums.yaml +7 -0
  2. data/.arclint +8 -0
  3. data/.codeclimate.yml +17 -0
  4. data/.gitignore +6 -0
  5. data/.gitlab-ci.yml +17 -0
  6. data/.hound.yml +2 -0
  7. data/.rubocop.yml +5 -0
  8. data/.rubocop_todo.yml +274 -0
  9. data/.travis.yml +49 -0
  10. data/CHANGELOG.md +414 -0
  11. data/CONTRIBUTING.md +40 -0
  12. data/CONTRIBUTORS.md +12 -0
  13. data/Gemfile +3 -0
  14. data/LICENSE.md +20 -0
  15. data/README.md +100 -0
  16. data/gitlab-fog-azure-rm.gemspec +31 -0
  17. data/lib/fog/azurerm.rb +30 -0
  18. data/lib/fog/azurerm/async_response.rb +44 -0
  19. data/lib/fog/azurerm/config.rb +1 -0
  20. data/lib/fog/azurerm/constants.rb +72 -0
  21. data/lib/fog/azurerm/credentials.rb +40 -0
  22. data/lib/fog/azurerm/custom_fog_errors.rb +52 -0
  23. data/lib/fog/azurerm/docs/storage.md +398 -0
  24. data/lib/fog/azurerm/docs/structure.md +53 -0
  25. data/lib/fog/azurerm/models/resources/azure_resource.rb +25 -0
  26. data/lib/fog/azurerm/models/resources/azure_resources.rb +40 -0
  27. data/lib/fog/azurerm/models/resources/dependency.rb +27 -0
  28. data/lib/fog/azurerm/models/resources/deployment.rb +65 -0
  29. data/lib/fog/azurerm/models/resources/deployments.rb +30 -0
  30. data/lib/fog/azurerm/models/resources/provider.rb +27 -0
  31. data/lib/fog/azurerm/models/resources/provider_resource_type.rb +22 -0
  32. data/lib/fog/azurerm/models/resources/resource_group.rb +34 -0
  33. data/lib/fog/azurerm/models/resources/resource_groups.rb +29 -0
  34. data/lib/fog/azurerm/models/storage/directories.rb +75 -0
  35. data/lib/fog/azurerm/models/storage/directory.rb +151 -0
  36. data/lib/fog/azurerm/models/storage/file.rb +265 -0
  37. data/lib/fog/azurerm/models/storage/files.rb +183 -0
  38. data/lib/fog/azurerm/models/storage/kind.rb +12 -0
  39. data/lib/fog/azurerm/models/storage/sku_name.rb +15 -0
  40. data/lib/fog/azurerm/models/storage/sku_tier.rb +12 -0
  41. data/lib/fog/azurerm/models/storage/storage_account.rb +92 -0
  42. data/lib/fog/azurerm/models/storage/storage_accounts.rb +47 -0
  43. data/lib/fog/azurerm/requests/storage/acquire_blob_lease.rb +32 -0
  44. data/lib/fog/azurerm/requests/storage/acquire_container_lease.rb +32 -0
  45. data/lib/fog/azurerm/requests/storage/check_container_exists.rb +30 -0
  46. data/lib/fog/azurerm/requests/storage/commit_blob_blocks.rb +30 -0
  47. data/lib/fog/azurerm/requests/storage/compare_container_blobs.rb +148 -0
  48. data/lib/fog/azurerm/requests/storage/copy_blob.rb +30 -0
  49. data/lib/fog/azurerm/requests/storage/copy_blob_from_uri.rb +30 -0
  50. data/lib/fog/azurerm/requests/storage/copy_object.rb +20 -0
  51. data/lib/fog/azurerm/requests/storage/create_block_blob.rb +108 -0
  52. data/lib/fog/azurerm/requests/storage/create_container.rb +40 -0
  53. data/lib/fog/azurerm/requests/storage/create_disk.rb +62 -0
  54. data/lib/fog/azurerm/requests/storage/create_page_blob.rb +31 -0
  55. data/lib/fog/azurerm/requests/storage/delete_blob.rb +32 -0
  56. data/lib/fog/azurerm/requests/storage/delete_blob_https_url.rb +39 -0
  57. data/lib/fog/azurerm/requests/storage/delete_container.rb +31 -0
  58. data/lib/fog/azurerm/requests/storage/delete_disk.rb +36 -0
  59. data/lib/fog/azurerm/requests/storage/delete_object_url.rb +30 -0
  60. data/lib/fog/azurerm/requests/storage/get_blob.rb +163 -0
  61. data/lib/fog/azurerm/requests/storage/get_blob_http_url.rb +39 -0
  62. data/lib/fog/azurerm/requests/storage/get_blob_https_url.rb +39 -0
  63. data/lib/fog/azurerm/requests/storage/get_blob_properties.rb +55 -0
  64. data/lib/fog/azurerm/requests/storage/get_blob_url.rb +28 -0
  65. data/lib/fog/azurerm/requests/storage/get_container_acl.rb +30 -0
  66. data/lib/fog/azurerm/requests/storage/get_container_properties.rb +41 -0
  67. data/lib/fog/azurerm/requests/storage/get_container_url.rb +34 -0
  68. data/lib/fog/azurerm/requests/storage/get_object_url.rb +21 -0
  69. data/lib/fog/azurerm/requests/storage/list_blobs.rb +168 -0
  70. data/lib/fog/azurerm/requests/storage/list_containers.rb +73 -0
  71. data/lib/fog/azurerm/requests/storage/multipart_save_block_blob.rb +110 -0
  72. data/lib/fog/azurerm/requests/storage/put_blob_block.rb +30 -0
  73. data/lib/fog/azurerm/requests/storage/put_blob_https_url.rb +39 -0
  74. data/lib/fog/azurerm/requests/storage/put_blob_metadata.rb +31 -0
  75. data/lib/fog/azurerm/requests/storage/put_blob_pages.rb +30 -0
  76. data/lib/fog/azurerm/requests/storage/put_blob_properties.rb +31 -0
  77. data/lib/fog/azurerm/requests/storage/put_container_acl.rb +31 -0
  78. data/lib/fog/azurerm/requests/storage/put_container_metadata.rb +31 -0
  79. data/lib/fog/azurerm/requests/storage/put_object_url.rb +30 -0
  80. data/lib/fog/azurerm/requests/storage/release_blob_lease.rb +30 -0
  81. data/lib/fog/azurerm/requests/storage/release_container_lease.rb +30 -0
  82. data/lib/fog/azurerm/requests/storage/save_page_blob.rb +111 -0
  83. data/lib/fog/azurerm/requests/storage/wait_blob_copy_operation_to_finish.rb +56 -0
  84. data/lib/fog/azurerm/storage.rb +126 -0
  85. data/lib/fog/azurerm/utilities/general.rb +186 -0
  86. data/lib/fog/azurerm/utilities/logger_messages.yml +19 -0
  87. data/lib/fog/azurerm/version.rb +5 -0
  88. data/rake-script.sh +10 -0
  89. data/rakefile +29 -0
  90. data/test/api_stub.rb +147 -0
  91. data/test/api_stub/models/storage/directory.rb +178 -0
  92. data/test/api_stub/models/storage/file.rb +181 -0
  93. data/test/api_stub/requests/storage/directory.rb +89 -0
  94. data/test/api_stub/requests/storage/file.rb +252 -0
  95. data/test/integration/README.md +14 -0
  96. data/test/integration/blob.rb +297 -0
  97. data/test/integration/container.rb +160 -0
  98. data/test/integration/credentials/azure.yml +5 -0
  99. data/test/integration/storage_account.rb +135 -0
  100. data/test/models/storage/test_directories.rb +74 -0
  101. data/test/models/storage/test_directory.rb +178 -0
  102. data/test/models/storage/test_file.rb +294 -0
  103. data/test/models/storage/test_files.rb +234 -0
  104. data/test/requests/storage/test_acquire_blob_lease.rb +36 -0
  105. data/test/requests/storage/test_acquire_container_lease.rb +36 -0
  106. data/test/requests/storage/test_check_container_exists.rb +18 -0
  107. data/test/requests/storage/test_commit_blob_blocks.rb +34 -0
  108. data/test/requests/storage/test_compare_container_blobs.rb +36 -0
  109. data/test/requests/storage/test_copy_blob.rb +39 -0
  110. data/test/requests/storage/test_copy_blob_from_uri.rb +36 -0
  111. data/test/requests/storage/test_create_block_blob.rb +80 -0
  112. data/test/requests/storage/test_create_container.rb +36 -0
  113. data/test/requests/storage/test_create_disk.rb +70 -0
  114. data/test/requests/storage/test_create_page_blob.rb +34 -0
  115. data/test/requests/storage/test_delete_blob.rb +42 -0
  116. data/test/requests/storage/test_delete_blob_https_url.rb +32 -0
  117. data/test/requests/storage/test_delete_container.rb +42 -0
  118. data/test/requests/storage/test_delete_disk.rb +30 -0
  119. data/test/requests/storage/test_get_blob.rb +141 -0
  120. data/test/requests/storage/test_get_blob_http_url.rb +30 -0
  121. data/test/requests/storage/test_get_blob_https_url.rb +32 -0
  122. data/test/requests/storage/test_get_blob_properties.rb +47 -0
  123. data/test/requests/storage/test_get_blob_url.rb +75 -0
  124. data/test/requests/storage/test_get_container_acl.rb +37 -0
  125. data/test/requests/storage/test_get_container_properties.rb +45 -0
  126. data/test/requests/storage/test_get_container_url.rb +33 -0
  127. data/test/requests/storage/test_list_blobs.rb +77 -0
  128. data/test/requests/storage/test_list_containers.rb +54 -0
  129. data/test/requests/storage/test_multipart_save_block_blob.rb +105 -0
  130. data/test/requests/storage/test_put_blob_block.rb +34 -0
  131. data/test/requests/storage/test_put_blob_https_url.rb +32 -0
  132. data/test/requests/storage/test_put_blob_metadata.rb +36 -0
  133. data/test/requests/storage/test_put_blob_pages.rb +34 -0
  134. data/test/requests/storage/test_put_blob_properties.rb +39 -0
  135. data/test/requests/storage/test_put_container_acl.rb +34 -0
  136. data/test/requests/storage/test_put_container_metadata.rb +36 -0
  137. data/test/requests/storage/test_release_blob_lease.rb +34 -0
  138. data/test/requests/storage/test_release_container_lease.rb +34 -0
  139. data/test/requests/storage/test_save_page_blob.rb +115 -0
  140. data/test/requests/storage/test_wait_blob_copy_operation_to_finish.rb +148 -0
  141. data/test/smoke_tests/compute/test_resource_group_smoke.rb +37 -0
  142. data/test/test_credentials.rb +63 -0
  143. data/test/test_helper.rb +846 -0
  144. metadata +352 -0
@@ -0,0 +1,265 @@
1
+ require 'mime/types'
2
+
3
+ module Fog
4
+ module Storage
5
+ class AzureRM
6
+ # This class is giving implementation of create/save and
7
+ # delete/destroy for Blob.
8
+ class File < Fog::Model
9
+ identity :key, aliases: %w(Name name Key)
10
+
11
+ attr_writer :body
12
+ attribute :directory
13
+ attribute :accept_ranges, aliases: %w(Accept-Ranges AcceptRanges)
14
+ attribute :content_length, aliases: %w(Content-Length Size), type: :integer
15
+ attribute :content_type, aliases: %w(Content-Type ContentType)
16
+ attribute :content_md5, aliases: %w(Content-MD5 ContentMD5)
17
+ attribute :content_encoding, aliases: %w(Content-Encoding ContentEncoding)
18
+ attribute :content_language, aliases: %w(Content-Language ContentLanguage)
19
+ attribute :cache_control, aliases: %w(Cache-Control CacheControl)
20
+ attribute :content_disposition, aliases: %w(Content-Disposition ContentDisposition)
21
+ attribute :copy_completion_time, aliases: %w(Copy-Completion-Time CopyCompletionTime)
22
+ attribute :copy_status, aliases: %w(Copy-Status CopyStatus)
23
+ attribute :copy_status_description, aliases: %w(Copy-Status-Description CopyStatusDescription)
24
+ attribute :copy_id, aliases: %w(Copy-Id CopyId)
25
+ attribute :copy_progress, aliases: %w(Copy-Progress CopyProgress)
26
+ attribute :copy_source, aliases: %w(Copy-Source CopySource)
27
+ attribute :etag, aliases: %w(Etag ETag)
28
+ attribute :last_modified, aliases: %w(Last-Modified LastModified), type: 'time'
29
+ attribute :lease_duration, aliases: %w(Lease-Duration LeaseDuration)
30
+ attribute :lease_state, aliases: %w(Lease-State LeaseState)
31
+ attribute :lease_status, aliases: %w(Lease-Status LeaseStatus)
32
+ attribute :sequence_number, aliases: %w(Sequence-Number SequenceNumber)
33
+ attribute :blob_type, aliases: %w(Blob-Type BlobType)
34
+ attribute :metadata
35
+
36
+ # Save the file to the directory in Azure storage.
37
+ # TODO: Support snapshots.
38
+ #
39
+ # required attributes: body(Only if update_body is true), directory, key
40
+ #
41
+ # @param identity [String] Name of directory
42
+ # @param options [Hash]
43
+ # @option options [Boolean] update_body Sets whether to upload the body of the file. Default is true.
44
+ # Will update metadata and properties when update_body is set to false.
45
+ # @option options [Integer] worker_thread_num Sets how many threads will be used to upload the body. Default is 8.
46
+ # @option options [String] blob_type or
47
+ # Blob-Type Sets blob type for the file. Options: 'BlockBlob' or 'PageBlob'. Default is 'BlockBlob'.
48
+ # @option options [String] content_type or
49
+ # Content-Type Sets content type for the file. For example, 'text/plain'.
50
+ # @option options [String] content_md5 or
51
+ # Content-MD5 Sets content MD5 hash for the file. Only for store.
52
+ # When a block file whose size <= 32 MB, Azure will verify the integrity of the blob during transport.
53
+ # Please reference this issue: https://github.com/Azure/azure-storage-ruby/issues/64
54
+ # @option options [String] content_encoding or
55
+ # Content-Encoding Sets content encoding for the file. For example, 'x-gzip'.
56
+ # @option options [String] content_language or
57
+ # Content-Language Sets the natural languages used by the file.
58
+ # @option options [String] cache_control or
59
+ # Cache-Control Sets content encoding for the file. For example, 'No-cache'.
60
+ # @option options [String] content_disposition or
61
+ # Content-Disposition Sets content disposition for the file. For exampple, 'attachment; filename=testing.txt'.
62
+ # @option options [Hash] metadata Sets custom metadata values to store with the file.
63
+ #
64
+ # @return [Boolean]
65
+ #
66
+ def save(options = {})
67
+ update_body = options.delete(:update_body)
68
+ update_body = true if update_body.nil?
69
+ requires :directory, :key
70
+ raise ArgumentError.new('body is required when update_body is true') if update_body && attributes[:body].nil?
71
+
72
+ remap_attributes(
73
+ options,
74
+ 'Blob-Type' => :blob_type,
75
+ 'Content-Type' => :content_type,
76
+ 'Content-MD5' => :content_md5,
77
+ 'Content-Encoding' => :content_encoding,
78
+ 'Content-Language' => :content_language,
79
+ 'Cache-Control' => :cache_control,
80
+ 'Content-Disposition' => :content_disposition
81
+ )
82
+ options = {
83
+ blob_type: blob_type,
84
+ content_type: content_type,
85
+ content_md5: content_md5,
86
+ content_encoding: content_encoding,
87
+ content_language: content_language,
88
+ cache_control: cache_control,
89
+ content_disposition: content_disposition,
90
+ metadata: metadata
91
+ }.merge!(options)
92
+ options = options.reject { |_key, value| value.nil? || value.to_s.empty? }
93
+
94
+ if update_body
95
+ blob = save_blob(options)
96
+
97
+ data = parse_storage_object(blob)
98
+ merge_attributes(data)
99
+ attributes[:content_length] = Fog::Storage.get_body_size(body)
100
+ attributes[:content_type] ||= Fog::Storage.get_content_type(body)
101
+ else
102
+ service.put_blob_metadata(directory.key, key, options[:metadata]) if options[:metadata]
103
+ options.delete(:metadata)
104
+ service.put_blob_properties(directory.key, key, options)
105
+
106
+ blob = service.get_blob_properties(directory.key, key)
107
+ data = parse_storage_object(blob)
108
+ merge_attributes(data)
109
+ end
110
+
111
+ true
112
+ end
113
+
114
+ # Get file's body if exists, else ''.
115
+ #
116
+ # @return [File || String]
117
+ #
118
+ def body
119
+ return attributes[:body] if attributes[:body]
120
+ return '' unless last_modified
121
+
122
+ file = collection.get(identity)
123
+ if file.nil?
124
+ attributes[:body] = ''
125
+ return ''
126
+ end
127
+
128
+ attributes[:body] = file.body
129
+ end
130
+
131
+ # Set body attribute.
132
+ #
133
+ # @param new_body [File || String]
134
+ #
135
+ # @return [File || String]
136
+ #
137
+ def body=(new_body)
138
+ attributes[:body] = new_body
139
+ end
140
+
141
+ # Copy object from one container to other container.
142
+ #
143
+ # required attributes: directory, key
144
+ #
145
+ # @param target_directory_key [String]
146
+ # @param target_file_key [String]
147
+ # @param options [Hash] options for copy_object method
148
+ # @option options [Integer] timeout Sets to raise a TimeoutError if the copy does not finish in timeout seconds.
149
+ #
150
+ # @return [Fog::Storage::AzureRM::File] New File.
151
+ #
152
+ def copy(target_directory_key, target_file_key, options = {})
153
+ requires :directory, :key
154
+
155
+ timeout = options.delete(:timeout)
156
+ copy_id, copy_status = service.copy_blob(target_directory_key, target_file_key, directory.key, key, options)
157
+ service.wait_blob_copy_operation_to_finish(target_directory_key, target_file_key, copy_id, copy_status, timeout)
158
+
159
+ target_directory = service.directories.new(key: target_directory_key)
160
+ target_directory.files.head(target_file_key)
161
+ end
162
+
163
+ # Copy object from a uri.
164
+ #
165
+ # required attributes: directory, key
166
+ #
167
+ # @param source_uri [String]
168
+ # @param options [Hash] options for copy_object method
169
+ # @option options [Integer] timeout Sets to raise a TimeoutError if the copy does not finish in timeout seconds.
170
+ #
171
+ # @return [Boolean]
172
+ #
173
+ def copy_from_uri(source_uri, options = {})
174
+ requires :directory, :key
175
+
176
+ timeout = options.delete(:timeout)
177
+ copy_id, copy_status = service.copy_blob_from_uri(directory.key, key, source_uri, options)
178
+ service.wait_blob_copy_operation_to_finish(directory.key, key, copy_id, copy_status, timeout)
179
+
180
+ blob = service.get_blob_properties(directory.key, key)
181
+ data = parse_storage_object(blob)
182
+ merge_attributes(data)
183
+
184
+ true
185
+ end
186
+
187
+ # Destroy file.
188
+ #
189
+ # required attributes: directory, key
190
+ #
191
+ # @param options [Hash]
192
+ # @option options versionId []
193
+ #
194
+ # @return [Boolean] true if successful
195
+ #
196
+ def destroy(options = {})
197
+ requires :key
198
+ requires :directory
199
+ attributes[:body] = nil
200
+ service.delete_blob(directory.key, key, options)
201
+
202
+ true
203
+ end
204
+
205
+ # Get whether the file can be accessed by anonymous.
206
+ #
207
+ # @return [Boolean]
208
+ #
209
+ def public?
210
+ requires :directory
211
+
212
+ # TBD: The blob can be accessed if read permision is set in one access policy of the container.
213
+ directory.acl == 'container' || directory.acl == 'blob'
214
+ end
215
+
216
+ # Get publicly accessible url.
217
+ #
218
+ # required attributes: directory, key
219
+ #
220
+ # @param options [Hash]
221
+ # @option options [String] scheme Sets which URL to get, http or https. Options: https or http. Default is https.
222
+ #
223
+ # @return [String] A public url.
224
+ #
225
+ def public_url(options = {})
226
+ requires :directory, :key
227
+ options[:scheme] == 'https' if options[:scheme].nil?
228
+ @service.get_blob_url(directory.key, key, options) if public?
229
+ end
230
+
231
+ # Get a url for file.
232
+ #
233
+ # required attributes: key
234
+ #
235
+ # @param expires [Time] The time at which the shared access signature becomes invalid, in a UTC format.
236
+ # @param options [Hash]
237
+ # @option options [String] scheme Sets which URL to get, http or https. Options: https or http. Default is https.
238
+ #
239
+ # @return [String] A public url which will expire after the specified time.
240
+ #
241
+ def url(expires, options = {})
242
+ requires :key
243
+ collection.get_url(key, expires, options)
244
+ end
245
+
246
+ private
247
+
248
+ # Upload blob
249
+ def save_blob(options)
250
+ if options[:blob_type].nil? || options[:blob_type] == 'BlockBlob'
251
+ if Fog::Storage.get_body_size(body) <= SINGLE_BLOB_PUT_THRESHOLD
252
+ service.create_block_blob(directory.key, key, body, options)
253
+ else
254
+ service.multipart_save_block_blob(directory.key, key, body, options)
255
+ service.get_blob_properties(directory.key, key)
256
+ end
257
+ else
258
+ service.save_page_blob(directory.key, key, body, options)
259
+ service.get_blob_properties(directory.key, key)
260
+ end
261
+ end
262
+ end
263
+ end
264
+ end
265
+ end
@@ -0,0 +1,183 @@
1
+ module Fog
2
+ module Storage
3
+ class AzureRM
4
+ # This class is giving implementation of listing blobs.
5
+ class Files < Fog::Collection
6
+ attribute :directory
7
+ attribute :delimiter, aliases: 'Delimiter'
8
+ attribute :marker, aliases: 'Marker'
9
+ attribute :max_results, aliases: %w(max-results MaxResults max_keys MaxKeys max-keys)
10
+ attribute :next_marker, aliases: %w(NextMarker next-marker)
11
+ attribute :prefix, aliases: 'Prefix'
12
+
13
+ model Fog::Storage::AzureRM::File
14
+
15
+ # List all files(blobs) under the directory.
16
+ #
17
+ # required attributes: directory
18
+ #
19
+ # @param options [Hash]
20
+ # @option options [String] max_keys or
21
+ # max_results Sets the maximum number of files to return.
22
+ # @option options [String] delimiter Sets to cause that the operation returns a BlobPrefix element in the response body that acts
23
+ # as a placeholder for all files whose names begin with the same substring up to the appearance
24
+ # of the delimiter character. The delimiter may be a single character or a string.
25
+ # @option options [String] marker Sets the identifier that specifies the portion of the list to be returned.
26
+ # @option options [String] prefix Sets filters the results to return only files whose name begins with the specified prefix.
27
+ #
28
+ # @return [Fog::Storage::AzureRM::Files] Return nil if the directory does not exist.
29
+ #
30
+ def all(options = {})
31
+ requires :directory
32
+
33
+ options = {
34
+ max_results: max_results,
35
+ delimiter: delimiter,
36
+ marker: marker,
37
+ prefix: prefix
38
+ }.merge!(options)
39
+ options = options.reject { |_key, value| value.nil? || value.to_s.empty? }
40
+ merge_attributes(options)
41
+ parent = directory.collection.get(
42
+ directory.key,
43
+ options
44
+ )
45
+ return nil unless parent
46
+
47
+ merge_attributes(parent.files.attributes)
48
+ load(parent.files.map(&:attributes))
49
+ end
50
+
51
+ # Enumerate every file under the directory if block_given?
52
+ #
53
+ # @return [Fog::Storage::AzureRM::Files]
54
+ #
55
+ alias each_file_this_page each
56
+ def each
57
+ if block_given?
58
+ subset = dup.all
59
+
60
+ subset.each_file_this_page { |f| yield f }
61
+ while subset.next_marker
62
+ subset = subset.all(marker: subset.next_marker)
63
+ subset.each_file_this_page { |f| yield f }
64
+ end
65
+ end
66
+
67
+ self
68
+ end
69
+
70
+ # Get the file(blob) with full content as :body with the given name.
71
+ #
72
+ # required attributes: directory
73
+ #
74
+ # @param key [String] Name of file
75
+ # @param options [Hash]
76
+ # @option options [String] block_size Sets buffer size when block_given? is true. Default is 32 MB
77
+ #
78
+ # @return [Fog::Storage::AzureRM::File] A file. Return nil if the file does not exist.
79
+ #
80
+ def get(key, options = {}, &block)
81
+ requires :directory
82
+
83
+ blob, content = service.get_blob(directory.key, key, options, &block)
84
+ data = parse_storage_object(blob)
85
+ file_data = data.merge(
86
+ body: content,
87
+ key: key
88
+ )
89
+ new(file_data)
90
+ rescue => error
91
+ return nil if error.message == 'NotFound'
92
+ raise error
93
+ end
94
+
95
+ # Get the URL of the file(blob) with the given name.
96
+ #
97
+ # required attributes: directory
98
+ #
99
+ # @param key [String] Name of file
100
+ # @param expires [Time] The time at which the shared access signature becomes invalid, in a UTC format.
101
+ # @param options [Hash]
102
+ # @option options [String] scheme Sets which URL to get, http or https. Options: https or http. Default is https.
103
+ #
104
+ # @return [String] A URL.
105
+ #
106
+ def get_url(key, expires, options = {})
107
+ requires :directory
108
+
109
+ if options[:scheme] == 'http'
110
+ get_http_url(key, expires, options)
111
+ else
112
+ get_https_url(key, expires, options)
113
+ end
114
+ end
115
+
116
+ # Get the http URL of the file(blob) with the given name.
117
+ #
118
+ # required attributes: directory
119
+ #
120
+ # @param key [String] Name of file
121
+ # @param expires [Time] The time at which the shared access signature becomes invalid, in a UTC format.
122
+ # @param options [Hash] Unused. To keep same interface as other providers.
123
+ #
124
+ # @return [String] A http URL.
125
+ #
126
+ def get_http_url(key, expires, _options = {})
127
+ requires :directory
128
+
129
+ service.get_blob_http_url(directory.key, key, expires)
130
+ end
131
+
132
+ # Get the https URL of the file(blob) with the given name.
133
+ #
134
+ # required attributes: directory
135
+ #
136
+ # @param key [String] Name of file
137
+ # @param expires [Time] The time at which the shared access signature becomes invalid, in a UTC format.
138
+ # @param options [Hash] Unused. To keep same interface as other providers.
139
+ #
140
+ # @return [String] A https URL.
141
+ #
142
+ def get_https_url(key, expires, _options = {})
143
+ requires :directory
144
+
145
+ service.get_blob_https_url(directory.key, key, expires)
146
+ end
147
+
148
+ # Get the file(blob) without content with the given name.
149
+ #
150
+ # required attributes: directory
151
+ #
152
+ # @param key [String] Name of file
153
+ # @param options [Hash]
154
+ #
155
+ # @return [Fog::Storage::AzureRM::File] A file. Return nil if the file does not exist.
156
+ #
157
+ def head(key, options = {})
158
+ requires :directory
159
+
160
+ blob = service.get_blob_properties(directory.key, key, options)
161
+ data = parse_storage_object(blob)
162
+ file_data = data.merge(key: key)
163
+ new(file_data)
164
+ rescue => error
165
+ return nil if error.message == 'NotFound'
166
+ raise error
167
+ end
168
+
169
+ # Create a new file.
170
+ #
171
+ # required attributes: directory
172
+ #
173
+ # @return [Fog::Storage::AzureRM::File] A file. You need to use File.save to upload this new file.
174
+ #
175
+ def new(attributes = {})
176
+ requires :directory
177
+
178
+ super({ directory: directory }.merge!(attributes))
179
+ end
180
+ end
181
+ end
182
+ end
183
+ end
@@ -0,0 +1,12 @@
1
+ module Fog
2
+ module ARM
3
+ module Storage
4
+ module Models
5
+ module Kind
6
+ Storage = 'Storage'.freeze
7
+ BlobStorage = 'BlobStorage'.freeze
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end