gitlab-fog-azure-rm 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.arclint +8 -0
- data/.codeclimate.yml +17 -0
- data/.gitignore +6 -0
- data/.gitlab-ci.yml +17 -0
- data/.hound.yml +2 -0
- data/.rubocop.yml +5 -0
- data/.rubocop_todo.yml +274 -0
- data/.travis.yml +49 -0
- data/CHANGELOG.md +414 -0
- data/CONTRIBUTING.md +40 -0
- data/CONTRIBUTORS.md +12 -0
- data/Gemfile +3 -0
- data/LICENSE.md +20 -0
- data/README.md +100 -0
- data/gitlab-fog-azure-rm.gemspec +31 -0
- data/lib/fog/azurerm.rb +30 -0
- data/lib/fog/azurerm/async_response.rb +44 -0
- data/lib/fog/azurerm/config.rb +1 -0
- data/lib/fog/azurerm/constants.rb +72 -0
- data/lib/fog/azurerm/credentials.rb +40 -0
- data/lib/fog/azurerm/custom_fog_errors.rb +52 -0
- data/lib/fog/azurerm/docs/storage.md +398 -0
- data/lib/fog/azurerm/docs/structure.md +53 -0
- data/lib/fog/azurerm/models/resources/azure_resource.rb +25 -0
- data/lib/fog/azurerm/models/resources/azure_resources.rb +40 -0
- data/lib/fog/azurerm/models/resources/dependency.rb +27 -0
- data/lib/fog/azurerm/models/resources/deployment.rb +65 -0
- data/lib/fog/azurerm/models/resources/deployments.rb +30 -0
- data/lib/fog/azurerm/models/resources/provider.rb +27 -0
- data/lib/fog/azurerm/models/resources/provider_resource_type.rb +22 -0
- data/lib/fog/azurerm/models/resources/resource_group.rb +34 -0
- data/lib/fog/azurerm/models/resources/resource_groups.rb +29 -0
- data/lib/fog/azurerm/models/storage/directories.rb +75 -0
- data/lib/fog/azurerm/models/storage/directory.rb +151 -0
- data/lib/fog/azurerm/models/storage/file.rb +265 -0
- data/lib/fog/azurerm/models/storage/files.rb +183 -0
- data/lib/fog/azurerm/models/storage/kind.rb +12 -0
- data/lib/fog/azurerm/models/storage/sku_name.rb +15 -0
- data/lib/fog/azurerm/models/storage/sku_tier.rb +12 -0
- data/lib/fog/azurerm/models/storage/storage_account.rb +92 -0
- data/lib/fog/azurerm/models/storage/storage_accounts.rb +47 -0
- data/lib/fog/azurerm/requests/storage/acquire_blob_lease.rb +32 -0
- data/lib/fog/azurerm/requests/storage/acquire_container_lease.rb +32 -0
- data/lib/fog/azurerm/requests/storage/check_container_exists.rb +30 -0
- data/lib/fog/azurerm/requests/storage/commit_blob_blocks.rb +30 -0
- data/lib/fog/azurerm/requests/storage/compare_container_blobs.rb +148 -0
- data/lib/fog/azurerm/requests/storage/copy_blob.rb +30 -0
- data/lib/fog/azurerm/requests/storage/copy_blob_from_uri.rb +30 -0
- data/lib/fog/azurerm/requests/storage/copy_object.rb +20 -0
- data/lib/fog/azurerm/requests/storage/create_block_blob.rb +108 -0
- data/lib/fog/azurerm/requests/storage/create_container.rb +40 -0
- data/lib/fog/azurerm/requests/storage/create_disk.rb +62 -0
- data/lib/fog/azurerm/requests/storage/create_page_blob.rb +31 -0
- data/lib/fog/azurerm/requests/storage/delete_blob.rb +32 -0
- data/lib/fog/azurerm/requests/storage/delete_blob_https_url.rb +39 -0
- data/lib/fog/azurerm/requests/storage/delete_container.rb +31 -0
- data/lib/fog/azurerm/requests/storage/delete_disk.rb +36 -0
- data/lib/fog/azurerm/requests/storage/delete_object_url.rb +30 -0
- data/lib/fog/azurerm/requests/storage/get_blob.rb +163 -0
- data/lib/fog/azurerm/requests/storage/get_blob_http_url.rb +39 -0
- data/lib/fog/azurerm/requests/storage/get_blob_https_url.rb +39 -0
- data/lib/fog/azurerm/requests/storage/get_blob_properties.rb +55 -0
- data/lib/fog/azurerm/requests/storage/get_blob_url.rb +28 -0
- data/lib/fog/azurerm/requests/storage/get_container_acl.rb +30 -0
- data/lib/fog/azurerm/requests/storage/get_container_properties.rb +41 -0
- data/lib/fog/azurerm/requests/storage/get_container_url.rb +34 -0
- data/lib/fog/azurerm/requests/storage/get_object_url.rb +21 -0
- data/lib/fog/azurerm/requests/storage/list_blobs.rb +168 -0
- data/lib/fog/azurerm/requests/storage/list_containers.rb +73 -0
- data/lib/fog/azurerm/requests/storage/multipart_save_block_blob.rb +110 -0
- data/lib/fog/azurerm/requests/storage/put_blob_block.rb +30 -0
- data/lib/fog/azurerm/requests/storage/put_blob_https_url.rb +39 -0
- data/lib/fog/azurerm/requests/storage/put_blob_metadata.rb +31 -0
- data/lib/fog/azurerm/requests/storage/put_blob_pages.rb +30 -0
- data/lib/fog/azurerm/requests/storage/put_blob_properties.rb +31 -0
- data/lib/fog/azurerm/requests/storage/put_container_acl.rb +31 -0
- data/lib/fog/azurerm/requests/storage/put_container_metadata.rb +31 -0
- data/lib/fog/azurerm/requests/storage/put_object_url.rb +30 -0
- data/lib/fog/azurerm/requests/storage/release_blob_lease.rb +30 -0
- data/lib/fog/azurerm/requests/storage/release_container_lease.rb +30 -0
- data/lib/fog/azurerm/requests/storage/save_page_blob.rb +111 -0
- data/lib/fog/azurerm/requests/storage/wait_blob_copy_operation_to_finish.rb +56 -0
- data/lib/fog/azurerm/storage.rb +126 -0
- data/lib/fog/azurerm/utilities/general.rb +186 -0
- data/lib/fog/azurerm/utilities/logger_messages.yml +19 -0
- data/lib/fog/azurerm/version.rb +5 -0
- data/rake-script.sh +10 -0
- data/rakefile +29 -0
- data/test/api_stub.rb +147 -0
- data/test/api_stub/models/storage/directory.rb +178 -0
- data/test/api_stub/models/storage/file.rb +181 -0
- data/test/api_stub/requests/storage/directory.rb +89 -0
- data/test/api_stub/requests/storage/file.rb +252 -0
- data/test/integration/README.md +14 -0
- data/test/integration/blob.rb +297 -0
- data/test/integration/container.rb +160 -0
- data/test/integration/credentials/azure.yml +5 -0
- data/test/integration/storage_account.rb +135 -0
- data/test/models/storage/test_directories.rb +74 -0
- data/test/models/storage/test_directory.rb +178 -0
- data/test/models/storage/test_file.rb +294 -0
- data/test/models/storage/test_files.rb +234 -0
- data/test/requests/storage/test_acquire_blob_lease.rb +36 -0
- data/test/requests/storage/test_acquire_container_lease.rb +36 -0
- data/test/requests/storage/test_check_container_exists.rb +18 -0
- data/test/requests/storage/test_commit_blob_blocks.rb +34 -0
- data/test/requests/storage/test_compare_container_blobs.rb +36 -0
- data/test/requests/storage/test_copy_blob.rb +39 -0
- data/test/requests/storage/test_copy_blob_from_uri.rb +36 -0
- data/test/requests/storage/test_create_block_blob.rb +80 -0
- data/test/requests/storage/test_create_container.rb +36 -0
- data/test/requests/storage/test_create_disk.rb +70 -0
- data/test/requests/storage/test_create_page_blob.rb +34 -0
- data/test/requests/storage/test_delete_blob.rb +42 -0
- data/test/requests/storage/test_delete_blob_https_url.rb +32 -0
- data/test/requests/storage/test_delete_container.rb +42 -0
- data/test/requests/storage/test_delete_disk.rb +30 -0
- data/test/requests/storage/test_get_blob.rb +141 -0
- data/test/requests/storage/test_get_blob_http_url.rb +30 -0
- data/test/requests/storage/test_get_blob_https_url.rb +32 -0
- data/test/requests/storage/test_get_blob_properties.rb +47 -0
- data/test/requests/storage/test_get_blob_url.rb +75 -0
- data/test/requests/storage/test_get_container_acl.rb +37 -0
- data/test/requests/storage/test_get_container_properties.rb +45 -0
- data/test/requests/storage/test_get_container_url.rb +33 -0
- data/test/requests/storage/test_list_blobs.rb +77 -0
- data/test/requests/storage/test_list_containers.rb +54 -0
- data/test/requests/storage/test_multipart_save_block_blob.rb +105 -0
- data/test/requests/storage/test_put_blob_block.rb +34 -0
- data/test/requests/storage/test_put_blob_https_url.rb +32 -0
- data/test/requests/storage/test_put_blob_metadata.rb +36 -0
- data/test/requests/storage/test_put_blob_pages.rb +34 -0
- data/test/requests/storage/test_put_blob_properties.rb +39 -0
- data/test/requests/storage/test_put_container_acl.rb +34 -0
- data/test/requests/storage/test_put_container_metadata.rb +36 -0
- data/test/requests/storage/test_release_blob_lease.rb +34 -0
- data/test/requests/storage/test_release_container_lease.rb +34 -0
- data/test/requests/storage/test_save_page_blob.rb +115 -0
- data/test/requests/storage/test_wait_blob_copy_operation_to_finish.rb +148 -0
- data/test/smoke_tests/compute/test_resource_group_smoke.rb +37 -0
- data/test/test_credentials.rb +63 -0
- data/test/test_helper.rb +846 -0
- metadata +352 -0
@@ -0,0 +1,30 @@
|
|
1
|
+
module Fog
|
2
|
+
module Storage
|
3
|
+
class AzureRM
|
4
|
+
# This class provides the actual implementation for service calls.
|
5
|
+
class Real
|
6
|
+
def put_blob_pages(container_name, blob_name, start_range, end_range, data, options = {})
|
7
|
+
options[:request_id] = SecureRandom.uuid
|
8
|
+
msg = "put_blob_pages [#{start_range}-#{end_range}] / #{blob_name} to the container #{container_name}. options: #{options}"
|
9
|
+
Fog::Logger.debug msg
|
10
|
+
|
11
|
+
begin
|
12
|
+
@blob_client.put_blob_pages(container_name, blob_name, start_range, end_range, data, options)
|
13
|
+
rescue Azure::Core::Http::HTTPError => ex
|
14
|
+
raise_azure_exception(ex, msg)
|
15
|
+
end
|
16
|
+
|
17
|
+
Fog::Logger.debug "[#{start_range}-#{end_range}] / #{blob_name} is uploaded successfully."
|
18
|
+
true
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# This class provides the mock implementation.
|
23
|
+
class Mock
|
24
|
+
def put_blob_pages(*)
|
25
|
+
true
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Fog
|
2
|
+
module Storage
|
3
|
+
class AzureRM
|
4
|
+
# This class provides the actual implemention for service calls.
|
5
|
+
class Real
|
6
|
+
def put_blob_properties(container_name, name, options = {})
|
7
|
+
options[:request_id] = SecureRandom.uuid
|
8
|
+
msg = "Set Blob #{name} properties #{options} in container #{container_name}."
|
9
|
+
Fog::Logger.debug msg
|
10
|
+
|
11
|
+
begin
|
12
|
+
@blob_client.set_blob_properties(container_name, name, options)
|
13
|
+
rescue Azure::Core::Http::HTTPError => ex
|
14
|
+
raise_azure_exception(ex, msg)
|
15
|
+
end
|
16
|
+
|
17
|
+
Fog::Logger.debug "Setting properties of blob #{name} successfully."
|
18
|
+
true
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# This class provides the mock implementation for unit tests.
|
23
|
+
class Mock
|
24
|
+
def put_blob_properties(container_name, name, options = {})
|
25
|
+
Fog::Logger.debug "Set Blob #{name} properties #{options} in a container #{container_name} successfully."
|
26
|
+
true
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Fog
|
2
|
+
module Storage
|
3
|
+
class AzureRM
|
4
|
+
# This class provides the actual implementation for service calls.
|
5
|
+
class Real
|
6
|
+
def put_container_acl(name, acl, options = {})
|
7
|
+
options[:request_id] = SecureRandom.uuid
|
8
|
+
msg = "Setting Container #{name} acl #{acl.nil? ? 'nil' : acl}. options: #{options}"
|
9
|
+
Fog::Logger.debug msg
|
10
|
+
|
11
|
+
begin
|
12
|
+
@blob_client.set_container_acl(name, acl, options)
|
13
|
+
rescue Azure::Core::Http::HTTPError => ex
|
14
|
+
raise_azure_exception(ex, msg)
|
15
|
+
end
|
16
|
+
|
17
|
+
Fog::Logger.debug "Setting acl of container #{name} successfully."
|
18
|
+
true
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# This class provides the mock implementation for unit tests.
|
23
|
+
class Mock
|
24
|
+
def put_container_acl(*)
|
25
|
+
Fog::Logger.debug 'Set Container testcontainer1 acl successfully.'
|
26
|
+
true
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Fog
|
2
|
+
module Storage
|
3
|
+
class AzureRM
|
4
|
+
# This class provides the actual implementation for service calls.
|
5
|
+
class Real
|
6
|
+
def put_container_metadata(name, metadata, options = {})
|
7
|
+
options[:request_id] = SecureRandom.uuid
|
8
|
+
msg = "Setting Container #{name} metadata. options: #{options}"
|
9
|
+
Fog::Logger.debug msg
|
10
|
+
|
11
|
+
begin
|
12
|
+
@blob_client.set_container_metadata(name, metadata, options)
|
13
|
+
rescue Azure::Core::Http::HTTPError => ex
|
14
|
+
raise_azure_exception(ex, msg)
|
15
|
+
end
|
16
|
+
|
17
|
+
Fog::Logger.debug "Setting metadata of container #{name} successfully."
|
18
|
+
true
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# This class provides the mock implementation for unit tests.
|
23
|
+
class Mock
|
24
|
+
def put_container_metadata(*)
|
25
|
+
Fog::Logger.debug 'Set Container testcontainer1 metadata successfully.'
|
26
|
+
true
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Fog
|
2
|
+
module Storage
|
3
|
+
class AzureRM
|
4
|
+
# This class provides the actual implemention for service calls.
|
5
|
+
class Real
|
6
|
+
# Generate a pre-signed URL for create an object in an Azure blob storage
|
7
|
+
# This is to make this library compatible with CarrierWave.
|
8
|
+
#
|
9
|
+
# @param container_name [String] Name of container containing blob
|
10
|
+
# @param blob_name [String] Name of blob to get expiring url for
|
11
|
+
# @param expires [Time] An expiry time for this url
|
12
|
+
#
|
13
|
+
# @return [String] - https url for blob
|
14
|
+
#
|
15
|
+
# @see https://docs.microsoft.com/en-us/rest/api/storageservices/put-blob
|
16
|
+
#
|
17
|
+
def put_object_url(bucket_name, object_name, expire_at, _upload_options)
|
18
|
+
put_blob_https_url(bucket_name, object_name, expire_at)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# This class provides the mock implementation for unit tests.
|
23
|
+
class Mock
|
24
|
+
def put_object_url(*args)
|
25
|
+
put_blob_https_url(*args)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Fog
|
2
|
+
module Storage
|
3
|
+
class AzureRM
|
4
|
+
# This class provides the actual implementation for service calls.
|
5
|
+
class Real
|
6
|
+
def release_blob_lease(container_name, name, lease_id, options = {})
|
7
|
+
options[:request_id] = SecureRandom.uuid
|
8
|
+
msg = "Releasing blob: #{name} of container #{container_name} having lease_id #{lease_id} options: #{options}"
|
9
|
+
Fog::Logger.debug msg
|
10
|
+
|
11
|
+
begin
|
12
|
+
@blob_client.release_blob_lease(container_name, name, lease_id, options)
|
13
|
+
rescue Azure::Core::Http::HTTPError => ex
|
14
|
+
raise_azure_exception(ex, msg)
|
15
|
+
end
|
16
|
+
|
17
|
+
Fog::Logger.debug "Blob #{name} released successfully."
|
18
|
+
true
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# This class provides the mock implementation for unit tests.
|
23
|
+
class Mock
|
24
|
+
def release_blob_lease(*)
|
25
|
+
true
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Fog
|
2
|
+
module Storage
|
3
|
+
class AzureRM
|
4
|
+
# This class provides the actual implementation for service calls.
|
5
|
+
class Real
|
6
|
+
def release_container_lease(name, lease_id, options={})
|
7
|
+
options[:request_id] = SecureRandom.uuid
|
8
|
+
msg = "Releasing container: #{name} having lease_id #{lease_id} options: #{options}"
|
9
|
+
Fog::Logger.debug msg
|
10
|
+
|
11
|
+
begin
|
12
|
+
@blob_client.release_container_lease(name, lease_id, options)
|
13
|
+
rescue Azure::Core::Http::HTTPError => ex
|
14
|
+
raise_azure_exception(ex, msg)
|
15
|
+
end
|
16
|
+
|
17
|
+
Fog::Logger.debug "Container #{name} released successfully."
|
18
|
+
true
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# This class provides the mock implementation for unit tests.
|
23
|
+
class Mock
|
24
|
+
def release_container_lease(*)
|
25
|
+
true
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
module Fog
|
2
|
+
module Storage
|
3
|
+
class AzureRM
|
4
|
+
# This class provides the actual implementation for service calls.
|
5
|
+
class Real
|
6
|
+
# This class is used to store chunk data for page blob before uploading.
|
7
|
+
class BlobChunk
|
8
|
+
attr_reader :id # For debug
|
9
|
+
attr_reader :start_range
|
10
|
+
attr_reader :data
|
11
|
+
|
12
|
+
def initialize(id, start_range, data)
|
13
|
+
@id = id
|
14
|
+
@start_range = start_range
|
15
|
+
@data = data
|
16
|
+
end
|
17
|
+
|
18
|
+
def end_range
|
19
|
+
@start_range + @data.size - 1
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# This class is a stream to read chunk data.
|
24
|
+
class BlobFileStream
|
25
|
+
def initialize(body)
|
26
|
+
if body.respond_to?(:read)
|
27
|
+
if body.respond_to?(:rewind)
|
28
|
+
begin
|
29
|
+
body.rewind
|
30
|
+
rescue => ex
|
31
|
+
Fog::Logger.debug "save_page_blob - body responds to :rewind but throws an exception when calling :rewind: #{ex.inspect}"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
@stream = body
|
35
|
+
else
|
36
|
+
@stream = StringIO.new(body)
|
37
|
+
end
|
38
|
+
@mutex = Mutex.new
|
39
|
+
@count = 0
|
40
|
+
end
|
41
|
+
|
42
|
+
def read(size)
|
43
|
+
data = nil
|
44
|
+
id = 0
|
45
|
+
start_range = 0
|
46
|
+
@mutex.synchronize do
|
47
|
+
start_range = @stream.pos
|
48
|
+
data = @stream.read(size)
|
49
|
+
return nil if data.nil?
|
50
|
+
@count += 1
|
51
|
+
id = @count
|
52
|
+
end
|
53
|
+
BlobChunk.new(id, start_range, data)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def save_page_blob(container_name, blob_name, body, options)
|
58
|
+
threads_num = options.delete(:worker_thread_num)
|
59
|
+
threads_num = UPLOAD_BLOB_WORKER_THREAD_COUNT if threads_num.nil? || !threads_num.is_a?(Integer) || threads_num < 1
|
60
|
+
|
61
|
+
begin
|
62
|
+
blob_size = Fog::Storage.get_body_size(body)
|
63
|
+
raise "The page blob size must be aligned to a 512-byte boundary. But the file size is #{blob_size}." if (blob_size % 512).nonzero?
|
64
|
+
|
65
|
+
# Initiate the upload
|
66
|
+
Fog::Logger.debug "Creating the page blob #{container_name}/#{blob_name}. options: #{options}"
|
67
|
+
create_page_blob(container_name, blob_name, blob_size, options)
|
68
|
+
options.delete(:content_md5)
|
69
|
+
|
70
|
+
# Uploading content
|
71
|
+
iostream = BlobFileStream.new(body)
|
72
|
+
|
73
|
+
threads = []
|
74
|
+
threads_num.times do |id|
|
75
|
+
thread = Thread.new do
|
76
|
+
Fog::Logger.debug "Created upload thread #{id}."
|
77
|
+
while (chunk = iostream.read(MAXIMUM_CHUNK_SIZE))
|
78
|
+
Fog::Logger.debug "Upload thread #{id} is uploading #{chunk.id}, start_range: #{chunk.start_range}, size: #{chunk.data.size}."
|
79
|
+
put_blob_pages(container_name, blob_name, chunk.start_range, chunk.end_range, chunk.data, options) if Digest::MD5.hexdigest(chunk.data) != HASH_OF_4MB_EMPTY_CONTENT
|
80
|
+
end
|
81
|
+
Fog::Logger.debug "Upload thread #{id} finished."
|
82
|
+
end
|
83
|
+
thread.abort_on_exception = true
|
84
|
+
threads << thread
|
85
|
+
end
|
86
|
+
|
87
|
+
threads.each(&:join)
|
88
|
+
rescue
|
89
|
+
# Abort the upload & reraise
|
90
|
+
begin
|
91
|
+
delete_blob(container_name, blob_name)
|
92
|
+
rescue => ex
|
93
|
+
Fog::Logger.debug "Cannot delete the blob: #{container_name}/#{blob_name} after save_page_blob failed. #{ex.inspect}"
|
94
|
+
end
|
95
|
+
raise
|
96
|
+
end
|
97
|
+
|
98
|
+
Fog::Logger.debug "Successfully save the page blob: #{container_name}/#{blob_name}."
|
99
|
+
true
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
# This class provides the mock implementation for unit tests.
|
104
|
+
class Mock
|
105
|
+
def save_page_blob(*)
|
106
|
+
true
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Fog
|
2
|
+
module Storage
|
3
|
+
class AzureRM
|
4
|
+
# This class provides the actual implementation for service calls.
|
5
|
+
class Real
|
6
|
+
def wait_blob_copy_operation_to_finish(container_name, blob_name, copy_id, copy_status, timeout = nil)
|
7
|
+
begin
|
8
|
+
start_time = Time.new
|
9
|
+
while copy_status == COPY_STATUS[:PENDING]
|
10
|
+
blob = get_blob_properties(container_name, blob_name)
|
11
|
+
blob_props = blob.properties
|
12
|
+
if !copy_id.nil? && blob_props[:copy_id] != copy_id
|
13
|
+
raise "The progress of copying to #{container_name}/#{blob_name} was interrupted by other copy operations."
|
14
|
+
end
|
15
|
+
|
16
|
+
copy_status_description = blob_props[:copy_status_description]
|
17
|
+
copy_status = blob_props[:copy_status]
|
18
|
+
break if copy_status != COPY_STATUS[:PENDING]
|
19
|
+
|
20
|
+
elapse_time = Time.new - start_time
|
21
|
+
raise TimeoutError.new("The copy operation cannot be finished in #{timeout} seconds") if !timeout.nil? && elapse_time >= timeout
|
22
|
+
|
23
|
+
copied_bytes, total_bytes = blob_props[:copy_progress].split('/').map(&:to_i)
|
24
|
+
interval = copied_bytes.zero? ? 5 : (total_bytes - copied_bytes).to_f / copied_bytes * elapse_time
|
25
|
+
interval = 30 if interval > 30
|
26
|
+
interval = 1 if interval < 1
|
27
|
+
sleep(interval)
|
28
|
+
end
|
29
|
+
|
30
|
+
if copy_status != COPY_STATUS[:SUCCESS]
|
31
|
+
raise "Failed to copy to #{container_name}/#{blob_name}: \n\tcopy status: #{copy_status}\n\tcopy description: #{copy_status_description}"
|
32
|
+
end
|
33
|
+
rescue
|
34
|
+
# Abort the copy & reraise
|
35
|
+
begin
|
36
|
+
delete_blob(container_name, blob_name)
|
37
|
+
rescue => ex
|
38
|
+
Fog::Logger.debug "Cannot delete the blob: #{container_name}/#{blob_name} after the copy operation failed. #{ex.inspect}"
|
39
|
+
end
|
40
|
+
raise
|
41
|
+
end
|
42
|
+
|
43
|
+
Fog::Logger.debug "Successfully copied the blob: #{container_name}/#{blob_name}."
|
44
|
+
true
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# This class provides the mock implementation for unit tests.
|
49
|
+
class Mock
|
50
|
+
def wait_blob_copy_operation_to_finish(*)
|
51
|
+
true
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
module Fog
|
2
|
+
module Storage
|
3
|
+
# This class registers models, requests and collections
|
4
|
+
class AzureRM < Fog::Service
|
5
|
+
# Recognizes when creating management client
|
6
|
+
recognizes :tenant_id
|
7
|
+
recognizes :client_id
|
8
|
+
recognizes :client_secret
|
9
|
+
recognizes :subscription_id
|
10
|
+
recognizes :environment
|
11
|
+
|
12
|
+
# Recognizes when creating data client
|
13
|
+
recognizes :azure_storage_account_name
|
14
|
+
recognizes :azure_storage_access_key
|
15
|
+
recognizes :debug
|
16
|
+
|
17
|
+
request_path 'fog/azurerm/requests/storage'
|
18
|
+
# Azure Storage Disk requests
|
19
|
+
request :delete_disk
|
20
|
+
request :create_disk
|
21
|
+
# Azure Storage Container requests
|
22
|
+
request :create_container
|
23
|
+
request :release_container_lease
|
24
|
+
request :acquire_container_lease
|
25
|
+
request :delete_container
|
26
|
+
request :list_containers
|
27
|
+
request :put_container_metadata
|
28
|
+
request :get_container_properties
|
29
|
+
request :get_container_acl
|
30
|
+
request :put_container_acl
|
31
|
+
request :get_container_url
|
32
|
+
request :check_container_exists
|
33
|
+
# Azure Storage Blob requests
|
34
|
+
request :list_blobs
|
35
|
+
request :put_blob_metadata
|
36
|
+
request :put_blob_properties
|
37
|
+
request :get_blob_properties
|
38
|
+
request :copy_blob
|
39
|
+
request :copy_object
|
40
|
+
request :copy_blob_from_uri
|
41
|
+
request :compare_container_blobs
|
42
|
+
request :acquire_blob_lease
|
43
|
+
request :release_blob_lease
|
44
|
+
request :delete_blob
|
45
|
+
request :get_blob
|
46
|
+
request :get_blob_url
|
47
|
+
request :get_object_url
|
48
|
+
request :get_blob_http_url
|
49
|
+
request :get_blob_https_url
|
50
|
+
request :create_block_blob
|
51
|
+
request :put_blob_block
|
52
|
+
request :put_blob_https_url
|
53
|
+
request :put_object_url
|
54
|
+
request :delete_blob_https_url
|
55
|
+
request :delete_object_url
|
56
|
+
request :commit_blob_blocks
|
57
|
+
request :create_page_blob
|
58
|
+
request :put_blob_pages
|
59
|
+
request :wait_blob_copy_operation_to_finish
|
60
|
+
request :save_page_blob
|
61
|
+
request :multipart_save_block_blob
|
62
|
+
|
63
|
+
model_path 'fog/azurerm/models/storage'
|
64
|
+
model :directory
|
65
|
+
collection :directories
|
66
|
+
model :file
|
67
|
+
collection :files
|
68
|
+
|
69
|
+
# This class provides the mock implementation for unit tests.
|
70
|
+
class Mock
|
71
|
+
def initialize(_options = {})
|
72
|
+
begin
|
73
|
+
require 'azure_mgmt_storage'
|
74
|
+
require 'azure/storage'
|
75
|
+
rescue LoadError => e
|
76
|
+
retry if require('rubygems')
|
77
|
+
raise e.message
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# This class provides the actual implementation for service calls.
|
83
|
+
class Real
|
84
|
+
def initialize(options)
|
85
|
+
begin
|
86
|
+
require 'azure_mgmt_storage'
|
87
|
+
require 'azure/storage'
|
88
|
+
require 'securerandom'
|
89
|
+
require 'vhd'
|
90
|
+
@debug = ENV['DEBUG'] || options[:debug]
|
91
|
+
require 'azure/core/http/debug_filter' if @debug
|
92
|
+
rescue LoadError => e
|
93
|
+
retry if require('rubygems')
|
94
|
+
raise e.message
|
95
|
+
end
|
96
|
+
|
97
|
+
options[:environment] = 'AzureCloud' if options[:environment].nil?
|
98
|
+
|
99
|
+
@tenant_id = options[:tenant_id]
|
100
|
+
@client_id = options[:client_id]
|
101
|
+
@client_secret = options[:client_secret]
|
102
|
+
@subscription_id = options[:subscription_id]
|
103
|
+
@environment = options[:environment]
|
104
|
+
|
105
|
+
credentials = Fog::Credentials::AzureRM.get_credentials(@tenant_id, @client_id, @client_secret, @environment)
|
106
|
+
telemetry = "gitlab-fog-azure-rm/#{Fog::AzureRM::VERSION}"
|
107
|
+
|
108
|
+
return unless @azure_storage_account_name != options[:azure_storage_account_name] ||
|
109
|
+
@azure_storage_access_key != options[:azure_storage_access_key]
|
110
|
+
|
111
|
+
@azure_storage_account_name = options[:azure_storage_account_name]
|
112
|
+
@azure_storage_access_key = options[:azure_storage_access_key]
|
113
|
+
|
114
|
+
azure_client = Azure::Storage::Client.create(storage_account_name: @azure_storage_account_name,
|
115
|
+
storage_access_key: @azure_storage_access_key)
|
116
|
+
azure_client.storage_blob_host = get_blob_endpoint(@azure_storage_account_name, true, @environment)
|
117
|
+
@blob_client = azure_client.blob_client
|
118
|
+
@blob_client.with_filter(Azure::Storage::Core::Filter::ExponentialRetryPolicyFilter.new)
|
119
|
+
@blob_client.with_filter(Azure::Core::Http::DebugFilter.new) if @debug
|
120
|
+
@signature_client = Azure::Storage::Core::Auth::SharedAccessSignature.new(@azure_storage_account_name,
|
121
|
+
@azure_storage_access_key)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|