gitlab-fog-azure-rm 1.8.0 → 1.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. checksums.yaml +4 -4
  2. data/.gitlab-ci.yml +12 -0
  3. data/.rubocop_todo.yml +1 -1
  4. data/gitlab-fog-azure-rm.gemspec +3 -2
  5. data/lib/fog/azurerm/docs/storage.md +1 -1
  6. data/lib/fog/azurerm/identity_encoding_filter.rb +12 -0
  7. data/lib/fog/azurerm/models/storage/directories.rb +6 -6
  8. data/lib/fog/azurerm/models/storage/directory.rb +4 -4
  9. data/lib/fog/azurerm/models/storage/file.rb +6 -3
  10. data/lib/fog/azurerm/models/storage/files.rb +8 -8
  11. data/lib/fog/azurerm/models/storage/storage_account.rb +4 -4
  12. data/lib/fog/azurerm/models/storage/storage_accounts.rb +6 -6
  13. data/lib/fog/azurerm/requests/storage/acquire_blob_lease.rb +2 -2
  14. data/lib/fog/azurerm/requests/storage/acquire_container_lease.rb +2 -2
  15. data/lib/fog/azurerm/requests/storage/check_container_exists.rb +2 -2
  16. data/lib/fog/azurerm/requests/storage/commit_blob_blocks.rb +2 -2
  17. data/lib/fog/azurerm/requests/storage/compare_container_blobs.rb +2 -2
  18. data/lib/fog/azurerm/requests/storage/copy_blob.rb +2 -2
  19. data/lib/fog/azurerm/requests/storage/copy_blob_from_uri.rb +2 -2
  20. data/lib/fog/azurerm/requests/storage/copy_object.rb +2 -2
  21. data/lib/fog/azurerm/requests/storage/create_block_blob.rb +2 -2
  22. data/lib/fog/azurerm/requests/storage/create_container.rb +2 -2
  23. data/lib/fog/azurerm/requests/storage/create_page_blob.rb +2 -2
  24. data/lib/fog/azurerm/requests/storage/delete_blob.rb +2 -2
  25. data/lib/fog/azurerm/requests/storage/delete_blob_https_url.rb +4 -4
  26. data/lib/fog/azurerm/requests/storage/delete_container.rb +2 -2
  27. data/lib/fog/azurerm/requests/storage/delete_object.rb +2 -2
  28. data/lib/fog/azurerm/requests/storage/delete_object_url.rb +2 -2
  29. data/lib/fog/azurerm/requests/storage/get_blob.rb +2 -2
  30. data/lib/fog/azurerm/requests/storage/get_blob_http_url.rb +5 -5
  31. data/lib/fog/azurerm/requests/storage/get_blob_https_url.rb +6 -5
  32. data/lib/fog/azurerm/requests/storage/get_blob_properties.rb +2 -2
  33. data/lib/fog/azurerm/requests/storage/get_blob_url.rb +4 -4
  34. data/lib/fog/azurerm/requests/storage/get_container_acl.rb +2 -2
  35. data/lib/fog/azurerm/requests/storage/get_container_properties.rb +2 -2
  36. data/lib/fog/azurerm/requests/storage/get_container_url.rb +4 -4
  37. data/lib/fog/azurerm/requests/storage/get_object.rb +2 -2
  38. data/lib/fog/azurerm/requests/storage/get_object_url.rb +2 -2
  39. data/lib/fog/azurerm/requests/storage/list_blobs.rb +2 -2
  40. data/lib/fog/azurerm/requests/storage/list_containers.rb +2 -2
  41. data/lib/fog/azurerm/requests/storage/put_blob_block.rb +2 -2
  42. data/lib/fog/azurerm/requests/storage/put_blob_http_url.rb +39 -0
  43. data/lib/fog/azurerm/requests/storage/put_blob_https_url.rb +4 -4
  44. data/lib/fog/azurerm/requests/storage/put_blob_metadata.rb +2 -2
  45. data/lib/fog/azurerm/requests/storage/put_blob_pages.rb +2 -2
  46. data/lib/fog/azurerm/requests/storage/put_blob_properties.rb +2 -2
  47. data/lib/fog/azurerm/requests/storage/put_container_acl.rb +2 -2
  48. data/lib/fog/azurerm/requests/storage/put_container_metadata.rb +2 -2
  49. data/lib/fog/azurerm/requests/storage/put_object_url.rb +2 -2
  50. data/lib/fog/azurerm/requests/storage/release_blob_lease.rb +2 -2
  51. data/lib/fog/azurerm/requests/storage/release_container_lease.rb +2 -2
  52. data/lib/fog/azurerm/requests/storage/save_page_blob.rb +2 -2
  53. data/lib/fog/azurerm/requests/storage/wait_blob_copy_operation_to_finish.rb +2 -2
  54. data/lib/fog/azurerm/storage.rb +62 -9
  55. data/lib/fog/azurerm/utilities/general.rb +0 -5
  56. data/lib/fog/azurerm/version.rb +1 -1
  57. data/lib/fog/azurerm.rb +4 -5
  58. data/rakefile +4 -5
  59. data/test/api_stub/models/storage/directory.rb +1 -1
  60. data/test/api_stub/models/storage/file.rb +1 -1
  61. data/test/api_stub/requests/storage/directory.rb +1 -1
  62. data/test/api_stub/requests/storage/file.rb +4 -4
  63. data/test/integration/README.md +5 -7
  64. data/test/integration/blob.rb +28 -36
  65. data/test/integration/container.rb +8 -39
  66. data/test/integration/credentials/azure.yml +4 -5
  67. data/test/models/storage/test_directories.rb +5 -5
  68. data/test/models/storage/test_directory.rb +2 -2
  69. data/test/models/storage/test_file.rb +16 -4
  70. data/test/models/storage/test_files.rb +8 -8
  71. data/test/requests/storage/test_acquire_blob_lease.rb +2 -2
  72. data/test/requests/storage/test_acquire_container_lease.rb +2 -2
  73. data/test/requests/storage/test_check_container_exists.rb +1 -1
  74. data/test/requests/storage/test_commit_blob_blocks.rb +2 -2
  75. data/test/requests/storage/test_compare_container_blobs.rb +2 -2
  76. data/test/requests/storage/test_copy_blob.rb +2 -2
  77. data/test/requests/storage/test_copy_blob_from_uri.rb +2 -2
  78. data/test/requests/storage/test_create_block_blob.rb +2 -2
  79. data/test/requests/storage/test_create_container.rb +2 -2
  80. data/test/requests/storage/test_create_page_blob.rb +2 -2
  81. data/test/requests/storage/test_delete_blob.rb +2 -2
  82. data/test/requests/storage/test_delete_blob_https_url.rb +7 -10
  83. data/test/requests/storage/test_delete_container.rb +2 -2
  84. data/test/requests/storage/test_delete_object.rb +2 -2
  85. data/test/requests/storage/test_get_blob.rb +2 -2
  86. data/test/requests/storage/test_get_blob_encoding.rb +45 -0
  87. data/test/requests/storage/test_get_blob_http_url.rb +13 -9
  88. data/test/requests/storage/test_get_blob_https_url.rb +95 -13
  89. data/test/requests/storage/test_get_blob_properties.rb +2 -2
  90. data/test/requests/storage/test_get_blob_url.rb +15 -24
  91. data/test/requests/storage/test_get_container_acl.rb +2 -2
  92. data/test/requests/storage/test_get_container_properties.rb +2 -2
  93. data/test/requests/storage/test_get_container_url.rb +5 -8
  94. data/test/requests/storage/test_get_object.rb +2 -2
  95. data/test/requests/storage/test_list_blobs.rb +2 -2
  96. data/test/requests/storage/test_list_containers.rb +2 -2
  97. data/test/requests/storage/test_put_blob_block.rb +2 -2
  98. data/test/requests/storage/test_put_blob_http_url.rb +33 -0
  99. data/test/requests/storage/test_put_blob_https_url.rb +8 -11
  100. data/test/requests/storage/test_put_blob_metadata.rb +2 -2
  101. data/test/requests/storage/test_put_blob_pages.rb +2 -2
  102. data/test/requests/storage/test_put_blob_properties.rb +2 -2
  103. data/test/requests/storage/test_put_container_acl.rb +2 -2
  104. data/test/requests/storage/test_put_container_metadata.rb +2 -2
  105. data/test/requests/storage/test_release_blob_lease.rb +2 -2
  106. data/test/requests/storage/test_release_container_lease.rb +2 -2
  107. data/test/requests/storage/test_save_page_blob.rb +2 -2
  108. data/test/requests/storage/test_wait_blob_copy_operation_to_finish.rb +15 -6
  109. data/test/test_helper.rb +38 -690
  110. metadata +27 -20
  111. data/lib/fog/azurerm/models/resources/azure_resource.rb +0 -25
  112. data/lib/fog/azurerm/models/resources/azure_resources.rb +0 -40
  113. data/lib/fog/azurerm/models/resources/dependency.rb +0 -27
  114. data/lib/fog/azurerm/models/resources/deployment.rb +0 -65
  115. data/lib/fog/azurerm/models/resources/deployments.rb +0 -30
  116. data/lib/fog/azurerm/models/resources/provider.rb +0 -27
  117. data/lib/fog/azurerm/models/resources/provider_resource_type.rb +0 -22
  118. data/lib/fog/azurerm/models/resources/resource_group.rb +0 -34
  119. data/lib/fog/azurerm/models/resources/resource_groups.rb +0 -29
  120. data/test/integration/storage_account.rb +0 -135
  121. data/test/smoke_tests/compute/test_resource_group_smoke.rb +0 -37
@@ -1,6 +1,6 @@
1
1
  module Fog
2
- module Storage
3
- class AzureRM
2
+ module AzureRM
3
+ class Storage
4
4
  # This class provides the actual implementation for service calls.
5
5
  # https://msdn.microsoft.com/en-us/library/azure/dd179352.aspx
6
6
  class Real
@@ -1,6 +1,6 @@
1
1
  module Fog
2
- module Storage
3
- class AzureRM
2
+ module AzureRM
3
+ class Storage
4
4
  # This class provides the actual implementation for service calls.
5
5
  class Real
6
6
  def put_blob_block(container_name, blob_name, block_id, data, options = {})
@@ -0,0 +1,39 @@
1
+ module Fog
2
+ module AzureRM
3
+ class Storage
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
+ #
8
+ # @param container_name [String] Name of container containing blob
9
+ # @param blob_name [String] Name of blob to get expiring url for
10
+ # @param expires [Time] An expiry time for this url
11
+ #
12
+ # @return [String] - https url for blob
13
+ #
14
+ # @see https://docs.microsoft.com/en-us/rest/api/storageservices/put-blob
15
+ #
16
+ def put_blob_http_url(container_name, blob_name, expires)
17
+ relative_path = "#{container_name}/#{blob_name}"
18
+ params = {
19
+ service: 'b',
20
+ resource: 'b',
21
+ permissions: 'c',
22
+ expiry: expires.utc.iso8601
23
+ }
24
+ token = signature_client(expires).generate_service_sas_token(relative_path, params)
25
+ uri = @blob_client.generate_uri(relative_path, {}, { encode: true })
26
+ url = "#{uri}?#{token}"
27
+ url.sub('https:', 'http:')
28
+ end
29
+ end
30
+
31
+ # This class provides the mock implementation for unit tests.
32
+ class Mock
33
+ def put_blob_http_url(*)
34
+ 'http://mockaccount.blob.core.windows.net/test_container/test_blob?token'
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -1,6 +1,6 @@
1
1
  module Fog
2
- module Storage
3
- class AzureRM
2
+ module AzureRM
3
+ class Storage
4
4
  # This class provides the actual implemention for service calls.
5
5
  class Real
6
6
  # Generate a pre-signed URL for create an object in an Azure blob storage
@@ -22,7 +22,7 @@ module Fog
22
22
  expiry: expires.utc.iso8601,
23
23
  protocol: 'https'
24
24
  }
25
- token = @signature_client.generate_service_sas_token(relative_path, params)
25
+ token = signature_client(expires).generate_service_sas_token(relative_path, params)
26
26
  uri = @blob_client.generate_uri(relative_path, {}, { encode: true })
27
27
  "#{uri}?#{token}"
28
28
  end
@@ -31,7 +31,7 @@ module Fog
31
31
  # This class provides the mock implementation for unit tests.
32
32
  class Mock
33
33
  def put_blob_https_url(*)
34
- 'https://sa.blob.core.windows.net/test_container/test_blob?token'
34
+ 'https://mockaccount.blob.core.windows.net/test_container/test_blob?token'
35
35
  end
36
36
  end
37
37
  end
@@ -1,6 +1,6 @@
1
1
  module Fog
2
- module Storage
3
- class AzureRM
2
+ module AzureRM
3
+ class Storage
4
4
  # This class provides the actual implementation for service calls.
5
5
  class Real
6
6
  def put_blob_metadata(container_name, name, metadata, options = {})
@@ -1,6 +1,6 @@
1
1
  module Fog
2
- module Storage
3
- class AzureRM
2
+ module AzureRM
3
+ class Storage
4
4
  # This class provides the actual implementation for service calls.
5
5
  class Real
6
6
  def put_blob_pages(container_name, blob_name, start_range, end_range, data, options = {})
@@ -1,6 +1,6 @@
1
1
  module Fog
2
- module Storage
3
- class AzureRM
2
+ module AzureRM
3
+ class Storage
4
4
  # This class provides the actual implemention for service calls.
5
5
  class Real
6
6
  def put_blob_properties(container_name, name, options = {})
@@ -1,6 +1,6 @@
1
1
  module Fog
2
- module Storage
3
- class AzureRM
2
+ module AzureRM
3
+ class Storage
4
4
  # This class provides the actual implementation for service calls.
5
5
  class Real
6
6
  def put_container_acl(name, acl, options = {})
@@ -1,6 +1,6 @@
1
1
  module Fog
2
- module Storage
3
- class AzureRM
2
+ module AzureRM
3
+ class Storage
4
4
  # This class provides the actual implementation for service calls.
5
5
  class Real
6
6
  def put_container_metadata(name, metadata, options = {})
@@ -1,6 +1,6 @@
1
1
  module Fog
2
- module Storage
3
- class AzureRM
2
+ module AzureRM
3
+ class Storage
4
4
  # This class provides the actual implemention for service calls.
5
5
  class Real
6
6
  # Generate a pre-signed URL for create an object in an Azure blob storage
@@ -1,6 +1,6 @@
1
1
  module Fog
2
- module Storage
3
- class AzureRM
2
+ module AzureRM
3
+ class Storage
4
4
  # This class provides the actual implementation for service calls.
5
5
  class Real
6
6
  def release_blob_lease(container_name, name, lease_id, options = {})
@@ -1,6 +1,6 @@
1
1
  module Fog
2
- module Storage
3
- class AzureRM
2
+ module AzureRM
3
+ class Storage
4
4
  # This class provides the actual implementation for service calls.
5
5
  class Real
6
6
  def release_container_lease(name, lease_id, options={})
@@ -1,6 +1,6 @@
1
1
  module Fog
2
- module Storage
3
- class AzureRM
2
+ module AzureRM
3
+ class Storage
4
4
  # This class provides the actual implementation for service calls.
5
5
  class Real
6
6
  # This class is used to store chunk data for page blob before uploading.
@@ -1,6 +1,6 @@
1
1
  module Fog
2
- module Storage
3
- class AzureRM
2
+ module AzureRM
3
+ class Storage
4
4
  # This class provides the actual implementation for service calls.
5
5
  class Real
6
6
  def wait_blob_copy_operation_to_finish(container_name, blob_name, copy_id, copy_status, timeout = nil)
@@ -1,11 +1,14 @@
1
1
  module Fog
2
- module Storage
2
+ module AzureRM
3
3
  # This class registers models, requests and collections
4
- class AzureRM < Fog::Service
4
+ class Storage < Fog::Service
5
5
  # Recognizes when creating data client
6
6
  recognizes :azure_storage_account_name
7
7
  recognizes :azure_storage_access_key
8
+ recognizes :azure_storage_token_signer
9
+ recognizes :azure_storage_endpoint
8
10
  recognizes :azure_storage_domain
11
+ recognizes :environment
9
12
 
10
13
  recognizes :debug
11
14
 
@@ -41,6 +44,7 @@ module Fog
41
44
  request :get_blob_https_url
42
45
  request :create_block_blob
43
46
  request :put_blob_block
47
+ request :put_blob_http_url
44
48
  request :put_blob_https_url
45
49
  request :put_object_url
46
50
  request :delete_blob
@@ -83,33 +87,82 @@ module Fog
83
87
  require 'securerandom'
84
88
  @debug = ENV['DEBUG'] || options[:debug]
85
89
  require 'azure/core/http/debug_filter' if @debug
90
+ require 'fog/azurerm/identity_encoding_filter'
86
91
  rescue LoadError => e
87
92
  retry if require('rubygems')
88
93
  raise e.message
89
94
  end
90
95
 
91
96
  return unless @azure_storage_account_name != options[:azure_storage_account_name] ||
92
- @azure_storage_access_key != options[:azure_storage_access_key]
97
+ @azure_storage_access_key != options[:azure_storage_access_key] ||
98
+ @azure_storage_token_signer != options[:azure_storage_token_signer]
93
99
 
94
100
  @azure_storage_account_name = options[:azure_storage_account_name]
95
101
  @azure_storage_access_key = options[:azure_storage_access_key]
102
+ @azure_storage_token_signer = options[:azure_storage_token_signer]
103
+ @azure_storage_endpoint = options[:azure_storage_endpoint]
96
104
  @azure_storage_domain = options[:azure_storage_domain]
97
105
 
98
- domain =
106
+ options[:environment] = 'AzureCloud' if options[:environment].nil?
107
+ @environment = options[:environment]
108
+
109
+ storage_blob_host =
110
+ @azure_storage_endpoint ||
99
111
  if @azure_storage_domain.nil? || @azure_storage_domain.empty?
100
112
  get_blob_endpoint(@azure_storage_account_name, true, @environment)
101
113
  else
102
114
  get_blob_endpoint_with_domain(@azure_storage_account_name, true, @azure_storage_domain)
103
115
  end
104
116
 
105
- azure_client = Azure::Storage::Common::Client.create(storage_account_name: @azure_storage_account_name,
106
- storage_access_key: @azure_storage_access_key,
107
- storage_blob_host: domain)
117
+ azure_client = Azure::Storage::Common::Client.create({
118
+ storage_account_name: @azure_storage_account_name,
119
+ storage_access_key: @azure_storage_access_key,
120
+ signer: @azure_storage_token_signer
121
+ }.compact)
122
+ azure_client.storage_blob_host = storage_blob_host
108
123
  @blob_client = Azure::Storage::Blob::BlobService.new(client: azure_client)
124
+ @blob_client.with_filter(Fog::AzureRM::IdentityEncodingFilter.new)
109
125
  @blob_client.with_filter(Azure::Storage::Common::Core::Filter::ExponentialRetryPolicyFilter.new)
110
126
  @blob_client.with_filter(Azure::Core::Http::DebugFilter.new) if @debug
111
- @signature_client = Azure::Storage::Common::Core::Auth::SharedAccessSignature.new(@azure_storage_account_name,
112
- @azure_storage_access_key)
127
+ end
128
+
129
+ private
130
+
131
+ def signature_client(requested_expiry)
132
+ access_key = @azure_storage_access_key.to_s
133
+ user_delegation_key = user_delegation_key(requested_expiry)
134
+
135
+ # invalidate cache when the delegation key changes
136
+ unless @signature_client_delegation_key == user_delegation_key
137
+ @signature_client_delegation_key = user_delegation_key
138
+ @signature_client = nil
139
+ end
140
+
141
+ @signature_client ||= Azure::Storage::Common::Core::Auth::SharedAccessSignature.new(
142
+ @azure_storage_account_name,
143
+ access_key,
144
+ user_delegation_key
145
+ )
146
+ end
147
+
148
+ def user_delegation_key(requested_expiry)
149
+ return nil unless @azure_storage_token_signer
150
+
151
+ @user_delegation_key_mutex ||= Mutex.new
152
+ @user_delegation_key_mutex.synchronize do
153
+ if @user_delegation_key_expiry.nil? || @user_delegation_key_expiry < requested_expiry
154
+ start = Time.now
155
+ expiry = start + Azure::Storage::Blob::BlobConstants::MAX_USER_DELEGATION_KEY_SECONDS
156
+
157
+ @user_delegation_key = @blob_client.get_user_delegation_key(
158
+ start,
159
+ expiry
160
+ )
161
+ @user_delegation_key_expiry = expiry
162
+ end
163
+ end
164
+
165
+ @user_delegation_key
113
166
  end
114
167
  end
115
168
  end
@@ -99,11 +99,6 @@ module Fog
99
99
  "#{protocol}://#{storage_account_name}.#{domain}"
100
100
  end
101
101
 
102
- def current_time
103
- time = Time.now.to_f.to_s
104
- time.split(/\W+/).join
105
- end
106
-
107
102
  # Parse storage blob/container to a hash
108
103
  def parse_storage_object(object)
109
104
  data = {}
@@ -1,5 +1,5 @@
1
1
  module Fog
2
2
  module AzureRM
3
- VERSION = '1.8.0'.freeze
3
+ VERSION = '1.9.0'.freeze
4
4
  end
5
5
  end
data/lib/fog/azurerm.rb CHANGED
@@ -11,14 +11,13 @@ require 'fog/azurerm/models/storage/sku_tier'
11
11
  require 'fog/azurerm/models/storage/kind'
12
12
 
13
13
  module Fog
14
- # Autoload Module for Storage
15
- module Storage
16
- autoload :AzureRM, File.expand_path('azurerm/storage', __dir__)
17
- end
18
-
19
14
  # Main AzureRM fog Provider Module
20
15
  module AzureRM
21
16
  extend Fog::Provider
17
+
18
+ # Autoload Module for Storage
19
+ autoload :Storage, File.expand_path('azurerm/storage', __dir__)
20
+
22
21
  service(:storage, 'Storage')
23
22
  end
24
23
  end
data/rakefile CHANGED
@@ -10,6 +10,10 @@ task :test do
10
10
  Dir.glob('test/requests/**/test_*.rb').each { |file| require File.expand_path file, __dir__ }
11
11
  end
12
12
 
13
+ task :integration do
14
+ Dir.glob('test/integration/*.rb').each { |file| require File.expand_path file, __dir__ }
15
+ end
16
+
13
17
  desc 'Generates a coverage report for minitest-cases using simple-cov'
14
18
  task :coverage do
15
19
  ENV['CODECLIMATE_REPO_TOKEN'] = nil
@@ -27,8 +31,3 @@ task :cc_coverage do
27
31
  Dir.glob('test/models/**/test_*.rb').each { |file| require File.expand_path file, __dir__ }
28
32
  Dir.glob('test/requests/**/test_*.rb').each { |file| require File.expand_path file, __dir__ }
29
33
  end
30
-
31
- desc 'Generates a coverage report for integration tests'
32
- task :integration_tests do
33
- Dir.glob('test/smoke_tests/**/test_*.rb').each { |file| require File.expand_path file, __dir__ }
34
- end
@@ -22,7 +22,7 @@ module ApiStub
22
22
  end
23
23
 
24
24
  def self.container_https_url
25
- 'https://sa.blob.core.windows.net/test_container?comp=list&restype=container'
25
+ 'https://mockaccount.blob.core.windows.net/test_container?comp=list&restype=container'
26
26
  end
27
27
 
28
28
  def self.container_list
@@ -34,7 +34,7 @@ module ApiStub
34
34
  end
35
35
 
36
36
  def self.blob_https_url
37
- 'https://sa.blob.core.windows.net/test_container/test_blob'
37
+ 'https://mockaccount.blob.core.windows.net/test_container/test_blob'
38
38
  end
39
39
 
40
40
  def self.blob_metadata
@@ -37,7 +37,7 @@ module ApiStub
37
37
  end
38
38
 
39
39
  def self.container_https_url
40
- 'https://sa.blob.core.windows.net/test_container?comp=list&restype=container'
40
+ 'https://mockaccount.blob.core.windows.net/test_container?comp=list&restype=container'
41
41
  end
42
42
 
43
43
  def self.container_metadata
@@ -46,13 +46,13 @@ module ApiStub
46
46
  def self.blob_https_url(environment = Fog::AzureRM::ENVIRONMENT_AZURE_CLOUD)
47
47
  case environment
48
48
  when Fog::AzureRM::ENVIRONMENT_AZURE_CHINA_CLOUD
49
- 'https://sa.blob.core.chinacloudapi.cn/test_container/test_blob'
49
+ 'https://mockaccount.blob.core.chinacloudapi.cn/test_container/test_blob'
50
50
  when Fog::AzureRM::ENVIRONMENT_AZURE_US_GOVERNMENT
51
- 'https://sa.blob.core.usgovcloudapi.net/test_container/test_blob'
51
+ 'https://mockaccount.blob.core.usgovcloudapi.net/test_container/test_blob'
52
52
  when Fog::AzureRM::ENVIRONMENT_AZURE_GERMAN_CLOUD
53
- 'https://sa.blob.core.cloudapi.de/test_container/test_blob'
53
+ 'https://mockaccount.blob.core.cloudapi.de/test_container/test_blob'
54
54
  else
55
- 'https://sa.blob.core.windows.net/test_container/test_blob'
55
+ 'https://mockaccount.blob.core.windows.net/test_container/test_blob'
56
56
  end
57
57
  end
58
58
 
@@ -1,14 +1,12 @@
1
1
  # Integration Tests
2
2
 
3
- To run Integration Tests, first enter following information from your Azure subscription in **credentials\azure.yml** file:
3
+ To run Integration Tests, first enter the following information for your test storage account into **credentials\azure.yml** file:
4
4
 
5
- - tenant_id
6
- - client_id
7
- - client_secret
8
- - subscription_id
5
+ - `azure_storage_account_name`
6
+ - `azure_storage_access_key`
9
7
 
10
- Then run **ruby file_name.rb** to run integration test for a specific service e.g. For integration tests of storage account, run:
8
+ Then run **bundle exec ruby file_name.rb** to run integration test for a specific service e.g. For integration tests for blobs, run:
11
9
 
12
- **ruby storage_account.rb**
10
+ **bundle exec ruby test/integration/blob.rb**
13
11
 
14
12
  Also make sure the **DEBUG** flag is set in your fog environment to see proper logging.
@@ -8,28 +8,11 @@ require 'yaml'
8
8
 
9
9
  azure_credentials = YAML.load_file(File.expand_path('credentials/azure.yml', __dir__))
10
10
 
11
- rs = Fog::Resources::AzureRM.new(
12
- tenant_id: azure_credentials['tenant_id'],
13
- client_id: azure_credentials['client_id'],
14
- client_secret: azure_credentials['client_secret'],
15
- subscription_id: azure_credentials['subscription_id']
16
- )
17
-
18
- storage = Fog::Storage::AzureRM.new(
19
- tenant_id: azure_credentials['tenant_id'],
20
- client_id: azure_credentials['client_id'],
21
- client_secret: azure_credentials['client_secret'],
22
- subscription_id: azure_credentials['subscription_id'],
23
- environment: azure_credentials['environment']
24
- )
25
-
26
11
  ########################################################################################################################
27
12
  ###################### Resource names #####################
28
13
  ########################################################################################################################
29
14
 
30
- time = current_time
31
- resource_group_name = "Blob-RG-#{time}"
32
- storage_account_name = "sa#{time}"
15
+ time = Time.now.to_i
33
16
  container_name = "con#{time}"
34
17
  test_container_name = "tcon#{time}"
35
18
 
@@ -38,36 +21,25 @@ test_container_name = "tcon#{time}"
38
21
  ########################################################################################################################
39
22
 
40
23
  begin
41
- resource_group = rs.resource_groups.create(
42
- name: resource_group_name,
43
- location: LOCATION
44
- )
45
-
46
- storage_account = storage.storage_accounts.create(
47
- name: storage_account_name,
48
- location: LOCATION,
49
- resource_group: resource_group_name
50
- )
51
-
52
- access_key = storage_account.get_access_keys[0].value
53
- Fog::Logger.debug access_key.inspect
54
24
  storage_data = Fog::Storage.new(
55
25
  provider: 'AzureRM',
56
- azure_storage_account_name: storage_account.name,
57
- azure_storage_access_key: access_key,
26
+ azure_storage_account_name: azure_credentials['azure_storage_account_name'],
27
+ azure_storage_access_key: azure_credentials['azure_storage_access_key'],
28
+ azure_storage_endpoint: azure_credentials['azure_storage_endpoint'],
58
29
  environment: azure_credentials['environment']
59
30
  )
31
+ scheme = URI.parse(azure_credentials.fetch('azure_storage_endpoint', 'https:')).scheme
60
32
 
61
33
  ########################################################################################################################
62
34
  ###################### Create Container ######################
63
35
  ########################################################################################################################
64
36
 
65
- storage_data.directories.create(
37
+ test_container1 = storage_data.directories.create(
66
38
  key: container_name,
67
39
  public: true
68
40
  )
69
41
 
70
- storage_data.directories.create(
42
+ test_container2 = storage_data.directories.create(
71
43
  key: test_container_name,
72
44
  public: false
73
45
  )
@@ -270,6 +242,24 @@ begin
270
242
 
271
243
  puts "Get a http URL with expires: #{test_blob.url(Time.now + 3600, scheme: 'http')}"
272
244
 
245
+ ########################################################################################################################
246
+ ###################### Test generated GET and PUT URLs ######################
247
+ ########################################################################################################################
248
+
249
+ url_blob_name = 'url-test.txt'
250
+ url_blob_content = 'Hello world.'
251
+ get_url = storage_data.public_send("get_blob_#{scheme}_url", container_name, url_blob_name, Time.now + 3600)
252
+ put_url = storage_data.public_send("put_blob_#{scheme}_url", container_name, url_blob_name, Time.now + 3600)
253
+
254
+ response = Faraday.put(put_url, url_blob_content, 'x-ms-blob-type' => 'BlockBlob')
255
+ raise unless response.success?
256
+ puts 'Uploaded blob using PUT blob URL'
257
+
258
+ response = Faraday.get(get_url)
259
+ raise unless response.success?
260
+ raise unless response.body == url_blob_content
261
+ puts 'Downloaded blob using GET blob URL'
262
+
273
263
  ########################################################################################################################
274
264
  ###################### Lease Blob ######################
275
265
  ########################################################################################################################
@@ -292,6 +282,8 @@ begin
292
282
  puts "Deleted blob: #{blob.destroy}"
293
283
  rescue => ex
294
284
  puts "Integration Test for blob is failing: #{ex.inspect}\n#{ex.backtrace.join("\n")}"
285
+ raise
295
286
  ensure
296
- resource_group.destroy unless resource_group.nil?
287
+ test_container1&.destroy
288
+ test_container2&.destroy
297
289
  end
@@ -8,28 +8,11 @@ require 'yaml'
8
8
 
9
9
  azure_credentials = YAML.load_file(File.expand_path('credentials/azure.yml', __dir__))
10
10
 
11
- rs = Fog::Resources::AzureRM.new(
12
- tenant_id: azure_credentials['tenant_id'],
13
- client_id: azure_credentials['client_id'],
14
- client_secret: azure_credentials['client_secret'],
15
- subscription_id: azure_credentials['subscription_id']
16
- )
17
-
18
- storage = Fog::Storage::AzureRM.new(
19
- tenant_id: azure_credentials['tenant_id'],
20
- client_id: azure_credentials['client_id'],
21
- client_secret: azure_credentials['client_secret'],
22
- subscription_id: azure_credentials['subscription_id'],
23
- environment: azure_credentials['environment']
24
- )
25
-
26
11
  ########################################################################################################################
27
12
  ###################### Resource names #####################
28
13
  ########################################################################################################################
29
14
 
30
- time = current_time
31
- resource_group_name = "Blob-RG-#{time}"
32
- storage_account_name = "sa#{time}"
15
+ time = Time.now.to_i
33
16
  container_name = "con#{time}"
34
17
  test_container_name = "tcon#{time}"
35
18
 
@@ -38,25 +21,10 @@ test_container_name = "tcon#{time}"
38
21
  ########################################################################################################################
39
22
 
40
23
  begin
41
- resource_group = rs.resource_groups.create(
42
- name: resource_group_name,
43
- location: LOCATION
44
- )
45
-
46
- storage_account_name = "sa#{current_time}"
47
-
48
- storage_account = storage.storage_accounts.create(
49
- name: storage_account_name,
50
- location: LOCATION,
51
- resource_group: resource_group_name
52
- )
53
-
54
- keys = storage_account.get_access_keys
55
- access_key = keys.first.value
56
-
57
- storage_data = Fog::Storage::AzureRM.new(
58
- azure_storage_account_name: storage_account.name,
59
- azure_storage_access_key: access_key,
24
+ storage_data = Fog::AzureRM::Storage.new(
25
+ azure_storage_account_name: azure_credentials['azure_storage_account_name'],
26
+ azure_storage_access_key: azure_credentials['azure_storage_access_key'],
27
+ azure_storage_endpoint: azure_credentials['azure_storage_endpoint'],
60
28
  environment: azure_credentials['environment']
61
29
  )
62
30
 
@@ -76,7 +44,7 @@ begin
76
44
  )
77
45
  puts "Created container: #{container.key}"
78
46
 
79
- storage_data.directories.create(
47
+ container2 = storage_data.directories.create(
80
48
  key: test_container_name,
81
49
  public: true
82
50
  )
@@ -155,6 +123,7 @@ begin
155
123
  puts "Deleted container: #{container.destroy}"
156
124
  rescue => ex
157
125
  puts "Integration Test for container is failing: #{ex.inspect}\n#{ex.backtrace.join("\n")}"
126
+ raise
158
127
  ensure
159
- resource_group.destroy unless resource_group.nil?
128
+ container2&.destroy
160
129
  end
@@ -1,5 +1,4 @@
1
- client_id: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
2
- client_secret: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
3
- subscription_id: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
4
- tenant_id: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
5
- environment: XXXXXXXX
1
+ azure_storage_account_name: devstoreaccount1
2
+ azure_storage_access_key: Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==
3
+ azure_storage_endpoint: http://azurite:10000/devstoreaccount1
4
+ environment: AzureCloud