gitlab-fog-azure-rm 1.8.0 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitlab-ci.yml +12 -0
- data/.rubocop_todo.yml +1 -1
- data/gitlab-fog-azure-rm.gemspec +3 -2
- data/lib/fog/azurerm/docs/storage.md +1 -1
- data/lib/fog/azurerm/identity_encoding_filter.rb +12 -0
- data/lib/fog/azurerm/models/storage/directories.rb +6 -6
- data/lib/fog/azurerm/models/storage/directory.rb +4 -4
- data/lib/fog/azurerm/models/storage/file.rb +6 -3
- data/lib/fog/azurerm/models/storage/files.rb +8 -8
- data/lib/fog/azurerm/models/storage/storage_account.rb +4 -4
- data/lib/fog/azurerm/models/storage/storage_accounts.rb +6 -6
- data/lib/fog/azurerm/requests/storage/acquire_blob_lease.rb +2 -2
- data/lib/fog/azurerm/requests/storage/acquire_container_lease.rb +2 -2
- data/lib/fog/azurerm/requests/storage/check_container_exists.rb +2 -2
- data/lib/fog/azurerm/requests/storage/commit_blob_blocks.rb +2 -2
- data/lib/fog/azurerm/requests/storage/compare_container_blobs.rb +2 -2
- data/lib/fog/azurerm/requests/storage/copy_blob.rb +2 -2
- data/lib/fog/azurerm/requests/storage/copy_blob_from_uri.rb +2 -2
- data/lib/fog/azurerm/requests/storage/copy_object.rb +2 -2
- data/lib/fog/azurerm/requests/storage/create_block_blob.rb +2 -2
- data/lib/fog/azurerm/requests/storage/create_container.rb +2 -2
- data/lib/fog/azurerm/requests/storage/create_page_blob.rb +2 -2
- data/lib/fog/azurerm/requests/storage/delete_blob.rb +2 -2
- data/lib/fog/azurerm/requests/storage/delete_blob_https_url.rb +4 -4
- data/lib/fog/azurerm/requests/storage/delete_container.rb +2 -2
- data/lib/fog/azurerm/requests/storage/delete_object.rb +2 -2
- data/lib/fog/azurerm/requests/storage/delete_object_url.rb +2 -2
- data/lib/fog/azurerm/requests/storage/get_blob.rb +2 -2
- data/lib/fog/azurerm/requests/storage/get_blob_http_url.rb +5 -5
- data/lib/fog/azurerm/requests/storage/get_blob_https_url.rb +6 -5
- data/lib/fog/azurerm/requests/storage/get_blob_properties.rb +2 -2
- data/lib/fog/azurerm/requests/storage/get_blob_url.rb +4 -4
- data/lib/fog/azurerm/requests/storage/get_container_acl.rb +2 -2
- data/lib/fog/azurerm/requests/storage/get_container_properties.rb +2 -2
- data/lib/fog/azurerm/requests/storage/get_container_url.rb +4 -4
- data/lib/fog/azurerm/requests/storage/get_object.rb +2 -2
- data/lib/fog/azurerm/requests/storage/get_object_url.rb +2 -2
- data/lib/fog/azurerm/requests/storage/list_blobs.rb +2 -2
- data/lib/fog/azurerm/requests/storage/list_containers.rb +2 -2
- data/lib/fog/azurerm/requests/storage/put_blob_block.rb +2 -2
- data/lib/fog/azurerm/requests/storage/put_blob_http_url.rb +39 -0
- data/lib/fog/azurerm/requests/storage/put_blob_https_url.rb +4 -4
- data/lib/fog/azurerm/requests/storage/put_blob_metadata.rb +2 -2
- data/lib/fog/azurerm/requests/storage/put_blob_pages.rb +2 -2
- data/lib/fog/azurerm/requests/storage/put_blob_properties.rb +2 -2
- data/lib/fog/azurerm/requests/storage/put_container_acl.rb +2 -2
- data/lib/fog/azurerm/requests/storage/put_container_metadata.rb +2 -2
- data/lib/fog/azurerm/requests/storage/put_object_url.rb +2 -2
- data/lib/fog/azurerm/requests/storage/release_blob_lease.rb +2 -2
- data/lib/fog/azurerm/requests/storage/release_container_lease.rb +2 -2
- data/lib/fog/azurerm/requests/storage/save_page_blob.rb +2 -2
- data/lib/fog/azurerm/requests/storage/wait_blob_copy_operation_to_finish.rb +2 -2
- data/lib/fog/azurerm/storage.rb +62 -9
- data/lib/fog/azurerm/utilities/general.rb +0 -5
- data/lib/fog/azurerm/version.rb +1 -1
- data/lib/fog/azurerm.rb +4 -5
- data/rakefile +4 -5
- data/test/api_stub/models/storage/directory.rb +1 -1
- data/test/api_stub/models/storage/file.rb +1 -1
- data/test/api_stub/requests/storage/directory.rb +1 -1
- data/test/api_stub/requests/storage/file.rb +4 -4
- data/test/integration/README.md +5 -7
- data/test/integration/blob.rb +28 -36
- data/test/integration/container.rb +8 -39
- data/test/integration/credentials/azure.yml +4 -5
- data/test/models/storage/test_directories.rb +5 -5
- data/test/models/storage/test_directory.rb +2 -2
- data/test/models/storage/test_file.rb +16 -4
- data/test/models/storage/test_files.rb +8 -8
- data/test/requests/storage/test_acquire_blob_lease.rb +2 -2
- data/test/requests/storage/test_acquire_container_lease.rb +2 -2
- data/test/requests/storage/test_check_container_exists.rb +1 -1
- data/test/requests/storage/test_commit_blob_blocks.rb +2 -2
- data/test/requests/storage/test_compare_container_blobs.rb +2 -2
- data/test/requests/storage/test_copy_blob.rb +2 -2
- data/test/requests/storage/test_copy_blob_from_uri.rb +2 -2
- data/test/requests/storage/test_create_block_blob.rb +2 -2
- data/test/requests/storage/test_create_container.rb +2 -2
- data/test/requests/storage/test_create_page_blob.rb +2 -2
- data/test/requests/storage/test_delete_blob.rb +2 -2
- data/test/requests/storage/test_delete_blob_https_url.rb +7 -10
- data/test/requests/storage/test_delete_container.rb +2 -2
- data/test/requests/storage/test_delete_object.rb +2 -2
- data/test/requests/storage/test_get_blob.rb +2 -2
- data/test/requests/storage/test_get_blob_encoding.rb +45 -0
- data/test/requests/storage/test_get_blob_http_url.rb +13 -9
- data/test/requests/storage/test_get_blob_https_url.rb +95 -13
- data/test/requests/storage/test_get_blob_properties.rb +2 -2
- data/test/requests/storage/test_get_blob_url.rb +15 -24
- data/test/requests/storage/test_get_container_acl.rb +2 -2
- data/test/requests/storage/test_get_container_properties.rb +2 -2
- data/test/requests/storage/test_get_container_url.rb +5 -8
- data/test/requests/storage/test_get_object.rb +2 -2
- data/test/requests/storage/test_list_blobs.rb +2 -2
- data/test/requests/storage/test_list_containers.rb +2 -2
- data/test/requests/storage/test_put_blob_block.rb +2 -2
- data/test/requests/storage/test_put_blob_http_url.rb +33 -0
- data/test/requests/storage/test_put_blob_https_url.rb +8 -11
- data/test/requests/storage/test_put_blob_metadata.rb +2 -2
- data/test/requests/storage/test_put_blob_pages.rb +2 -2
- data/test/requests/storage/test_put_blob_properties.rb +2 -2
- data/test/requests/storage/test_put_container_acl.rb +2 -2
- data/test/requests/storage/test_put_container_metadata.rb +2 -2
- data/test/requests/storage/test_release_blob_lease.rb +2 -2
- data/test/requests/storage/test_release_container_lease.rb +2 -2
- data/test/requests/storage/test_save_page_blob.rb +2 -2
- data/test/requests/storage/test_wait_blob_copy_operation_to_finish.rb +15 -6
- data/test/test_helper.rb +38 -690
- metadata +27 -20
- data/lib/fog/azurerm/models/resources/azure_resource.rb +0 -25
- data/lib/fog/azurerm/models/resources/azure_resources.rb +0 -40
- data/lib/fog/azurerm/models/resources/dependency.rb +0 -27
- data/lib/fog/azurerm/models/resources/deployment.rb +0 -65
- data/lib/fog/azurerm/models/resources/deployments.rb +0 -30
- data/lib/fog/azurerm/models/resources/provider.rb +0 -27
- data/lib/fog/azurerm/models/resources/provider_resource_type.rb +0 -22
- data/lib/fog/azurerm/models/resources/resource_group.rb +0 -34
- data/lib/fog/azurerm/models/resources/resource_groups.rb +0 -29
- data/test/integration/storage_account.rb +0 -135
- data/test/smoke_tests/compute/test_resource_group_smoke.rb +0 -37
@@ -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
|
3
|
-
class
|
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 =
|
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://
|
34
|
+
'https://mockaccount.blob.core.windows.net/test_container/test_blob?token'
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
data/lib/fog/azurerm/storage.rb
CHANGED
@@ -1,11 +1,14 @@
|
|
1
1
|
module Fog
|
2
|
-
module
|
2
|
+
module AzureRM
|
3
3
|
# This class registers models, requests and collections
|
4
|
-
class
|
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
|
-
|
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(
|
106
|
-
|
107
|
-
|
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
|
-
|
112
|
-
|
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 = {}
|
data/lib/fog/azurerm/version.rb
CHANGED
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://
|
25
|
+
'https://mockaccount.blob.core.windows.net/test_container?comp=list&restype=container'
|
26
26
|
end
|
27
27
|
|
28
28
|
def self.container_list
|
@@ -37,7 +37,7 @@ module ApiStub
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def self.container_https_url
|
40
|
-
'https://
|
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://
|
49
|
+
'https://mockaccount.blob.core.chinacloudapi.cn/test_container/test_blob'
|
50
50
|
when Fog::AzureRM::ENVIRONMENT_AZURE_US_GOVERNMENT
|
51
|
-
'https://
|
51
|
+
'https://mockaccount.blob.core.usgovcloudapi.net/test_container/test_blob'
|
52
52
|
when Fog::AzureRM::ENVIRONMENT_AZURE_GERMAN_CLOUD
|
53
|
-
'https://
|
53
|
+
'https://mockaccount.blob.core.cloudapi.de/test_container/test_blob'
|
54
54
|
else
|
55
|
-
'https://
|
55
|
+
'https://mockaccount.blob.core.windows.net/test_container/test_blob'
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
data/test/integration/README.md
CHANGED
@@ -1,14 +1,12 @@
|
|
1
1
|
# Integration Tests
|
2
2
|
|
3
|
-
To run Integration Tests, first enter following information
|
3
|
+
To run Integration Tests, first enter the following information for your test storage account into **credentials\azure.yml** file:
|
4
4
|
|
5
|
-
-
|
6
|
-
-
|
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
|
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
|
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.
|
data/test/integration/blob.rb
CHANGED
@@ -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 =
|
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:
|
57
|
-
azure_storage_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
|
-
|
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 =
|
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
|
-
|
42
|
-
|
43
|
-
|
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
|
-
|
128
|
+
container2&.destroy
|
160
129
|
end
|
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
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
|