azure-storage-common 1.1.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/azure/core.rb +47 -0
- data/lib/azure/core/auth/authorizer.rb +36 -0
- data/lib/azure/core/auth/shared_key.rb +125 -0
- data/lib/azure/core/auth/shared_key_lite.rb +48 -0
- data/lib/azure/core/auth/signer.rb +51 -0
- data/lib/azure/core/default.rb +23 -0
- data/lib/azure/core/error.rb +21 -0
- data/lib/azure/core/filtered_service.rb +45 -0
- data/lib/azure/core/http/debug_filter.rb +36 -0
- data/lib/azure/core/http/http_error.rb +135 -0
- data/lib/azure/core/http/http_filter.rb +53 -0
- data/lib/azure/core/http/http_request.rb +194 -0
- data/lib/azure/core/http/http_response.rb +102 -0
- data/lib/azure/core/http/retry_policy.rb +84 -0
- data/lib/azure/core/http/signer_filter.rb +33 -0
- data/lib/azure/core/service.rb +46 -0
- data/lib/azure/core/signed_service.rb +45 -0
- data/lib/azure/core/utility.rb +244 -0
- data/lib/azure/core/version.rb +33 -0
- data/lib/azure/http_response_helper.rb +38 -0
- data/lib/azure/storage/common.rb +26 -26
- data/lib/azure/storage/common/autoload.rb +62 -61
- data/lib/azure/storage/common/client.rb +162 -162
- data/lib/azure/storage/common/client_options.rb +363 -363
- data/lib/azure/storage/common/client_options_error.rb +41 -41
- data/lib/azure/storage/common/configurable.rb +212 -212
- data/lib/azure/storage/common/core.rb +35 -35
- data/lib/azure/storage/common/core/auth/anonymous_signer.rb +43 -43
- data/lib/azure/storage/common/core/auth/shared_access_signature.rb +30 -30
- data/lib/azure/storage/common/core/auth/shared_access_signature_generator.rb +399 -352
- data/lib/azure/storage/common/core/auth/shared_access_signature_signer.rb +57 -57
- data/lib/azure/storage/common/core/auth/shared_key.rb +60 -60
- data/lib/azure/storage/common/core/auth/token_signer.rb +43 -43
- data/lib/azure/storage/common/core/autoload.rb +53 -53
- data/lib/azure/storage/common/core/error.rb +43 -43
- data/lib/azure/storage/common/core/filter/exponential_retry_filter.rb +64 -64
- data/lib/azure/storage/common/core/filter/linear_retry_filter.rb +55 -55
- data/lib/azure/storage/common/core/filter/retry_filter.rb +300 -300
- data/lib/azure/storage/common/core/http_client.rb +79 -69
- data/lib/azure/storage/common/core/sr.rb +85 -85
- data/lib/azure/storage/common/core/token_credential.rb +64 -64
- data/lib/azure/storage/common/core/utility.rb +255 -255
- data/lib/azure/storage/common/default.rb +868 -868
- data/lib/azure/storage/common/service/access_policy.rb +37 -37
- data/lib/azure/storage/common/service/cors.rb +38 -38
- data/lib/azure/storage/common/service/cors_rule.rb +48 -48
- data/lib/azure/storage/common/service/enumeration_results.rb +32 -32
- data/lib/azure/storage/common/service/geo_replication.rb +40 -40
- data/lib/azure/storage/common/service/logging.rb +47 -47
- data/lib/azure/storage/common/service/metrics.rb +45 -45
- data/lib/azure/storage/common/service/retention_policy.rb +37 -37
- data/lib/azure/storage/common/service/serialization.rb +335 -335
- data/lib/azure/storage/common/service/signed_identifier.rb +40 -40
- data/lib/azure/storage/common/service/storage_service.rb +322 -322
- data/lib/azure/storage/common/service/storage_service_properties.rb +48 -48
- data/lib/azure/storage/common/service/storage_service_stats.rb +39 -39
- data/lib/azure/storage/common/service/user_delegation_key.rb +50 -0
- data/lib/azure/storage/common/version.rb +49 -49
- metadata +60 -18
@@ -1,41 +1,41 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
#-------------------------------------------------------------------------
|
4
|
-
# # Copyright (c) Microsoft and contributors. All rights reserved.
|
5
|
-
#
|
6
|
-
# The MIT License(MIT)
|
7
|
-
|
8
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
9
|
-
# of this software and associated documentation files(the "Software"), to deal
|
10
|
-
# in the Software without restriction, including without limitation the rights
|
11
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
12
|
-
# copies of the Software, and to permit persons to whom the Software is
|
13
|
-
# furnished to do so, subject to the following conditions :
|
14
|
-
|
15
|
-
# The above copyright notice and this permission notice shall be included in
|
16
|
-
# all copies or substantial portions of the Software.
|
17
|
-
|
18
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
19
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
20
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
21
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
22
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
23
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
24
|
-
# THE SOFTWARE.
|
25
|
-
#--------------------------------------------------------------------------
|
26
|
-
|
27
|
-
require "azure/storage/common/core"
|
28
|
-
|
29
|
-
module Azure::Storage::Common
|
30
|
-
class InvalidConnectionStringError < Core::StorageError
|
31
|
-
def initialize(message = Azure::Storage::Common::Core::SR::INVALID_CONNECTION_STRING)
|
32
|
-
super(message)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
class InvalidOptionsError < Core::StorageError
|
37
|
-
def initialize(message = Azure::Storage::Common::Core::SR::INVALID_CLIENT_OPTIONS)
|
38
|
-
super(message)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#-------------------------------------------------------------------------
|
4
|
+
# # Copyright (c) Microsoft and contributors. All rights reserved.
|
5
|
+
#
|
6
|
+
# The MIT License(MIT)
|
7
|
+
|
8
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
9
|
+
# of this software and associated documentation files(the "Software"), to deal
|
10
|
+
# in the Software without restriction, including without limitation the rights
|
11
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
12
|
+
# copies of the Software, and to permit persons to whom the Software is
|
13
|
+
# furnished to do so, subject to the following conditions :
|
14
|
+
|
15
|
+
# The above copyright notice and this permission notice shall be included in
|
16
|
+
# all copies or substantial portions of the Software.
|
17
|
+
|
18
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
19
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
20
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
21
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
22
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
23
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
24
|
+
# THE SOFTWARE.
|
25
|
+
#--------------------------------------------------------------------------
|
26
|
+
|
27
|
+
require "azure/storage/common/core"
|
28
|
+
|
29
|
+
module Azure::Storage::Common
|
30
|
+
class InvalidConnectionStringError < Core::StorageError
|
31
|
+
def initialize(message = Azure::Storage::Common::Core::SR::INVALID_CONNECTION_STRING)
|
32
|
+
super(message)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class InvalidOptionsError < Core::StorageError
|
37
|
+
def initialize(message = Azure::Storage::Common::Core::SR::INVALID_CLIENT_OPTIONS)
|
38
|
+
super(message)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -1,212 +1,212 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
#-------------------------------------------------------------------------
|
4
|
-
# # Copyright (c) Microsoft and contributors. All rights reserved.
|
5
|
-
#
|
6
|
-
# The MIT License(MIT)
|
7
|
-
|
8
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
9
|
-
# of this software and associated documentation files(the "Software"), to deal
|
10
|
-
# in the Software without restriction, including without limitation the rights
|
11
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
12
|
-
# copies of the Software, and to permit persons to whom the Software is
|
13
|
-
# furnished to do so, subject to the following conditions :
|
14
|
-
|
15
|
-
# The above copyright notice and this permission notice shall be included in
|
16
|
-
# all copies or substantial portions of the Software.
|
17
|
-
|
18
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
19
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
20
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
21
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
22
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
23
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
24
|
-
# THE SOFTWARE.
|
25
|
-
#--------------------------------------------------------------------------
|
26
|
-
|
27
|
-
module Azure::Storage::Common
|
28
|
-
# The Azure::Storage::Common::Configurable module provides basic configuration for Azure storage activities.
|
29
|
-
module Configurable
|
30
|
-
# @!attribute [w] storage_access_key
|
31
|
-
# @return [String] Azure Storage access key.
|
32
|
-
# @!attribute storage_account_name
|
33
|
-
# @return [String] Azure Storage account name.
|
34
|
-
# @!attribute storage_connection_string
|
35
|
-
# @return [String] Azure Storage connection string.
|
36
|
-
# @!attribute storage_blob_host
|
37
|
-
# @return [String] Set the host for the Blob service. Only set this if you want
|
38
|
-
# something custom (like, for example, to point this to a LocalStorage
|
39
|
-
# emulator). This should be the complete host, including http:// at the
|
40
|
-
# start. When using the emulator, make sure to include your account name at
|
41
|
-
# the end.
|
42
|
-
# @!attribute storage_table_host
|
43
|
-
# @return [String] Set the host for the Table service. Only set this if you want
|
44
|
-
# something custom (like, for example, to point this to a LocalStorage
|
45
|
-
# emulator). This should be the complete host, including http:// at the
|
46
|
-
# start. When using the emulator, make sure to include your account name at
|
47
|
-
# the end.
|
48
|
-
# @!attribute storage_queue_host
|
49
|
-
# @return [String] Set the host for the Queue service. Only set this if you want
|
50
|
-
# something custom (like, for example, to point this to a LocalStorage
|
51
|
-
# emulator). This should be the complete host, including http:// at the
|
52
|
-
# start. When using the emulator, make sure to include your account name at
|
53
|
-
# the end.
|
54
|
-
|
55
|
-
attr_accessor :storage_access_key,
|
56
|
-
:storage_account_name,
|
57
|
-
:storage_connection_string,
|
58
|
-
:storage_sas_token
|
59
|
-
|
60
|
-
attr_writer :storage_table_host,
|
61
|
-
:storage_blob_host,
|
62
|
-
:storage_queue_host,
|
63
|
-
:storage_file_host,
|
64
|
-
:storage_table_host_secondary,
|
65
|
-
:storage_blob_host_secondary,
|
66
|
-
:storage_queue_host_secondary,
|
67
|
-
:storage_file_host_secondary
|
68
|
-
|
69
|
-
attr_reader :signer
|
70
|
-
|
71
|
-
class << self
|
72
|
-
# List of configurable keys for {Azure::Client}
|
73
|
-
# @return [Array] of option keys
|
74
|
-
def keys
|
75
|
-
@keys ||= [
|
76
|
-
:storage_access_key,
|
77
|
-
:storage_account_name,
|
78
|
-
:storage_connection_string,
|
79
|
-
:storage_sas_token,
|
80
|
-
:storage_table_host,
|
81
|
-
:storage_blob_host,
|
82
|
-
:storage_queue_host,
|
83
|
-
:storage_file_host,
|
84
|
-
:signer
|
85
|
-
]
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
# Set configuration options using a block
|
90
|
-
def configure
|
91
|
-
yield self
|
92
|
-
end
|
93
|
-
|
94
|
-
def config
|
95
|
-
self
|
96
|
-
end
|
97
|
-
|
98
|
-
# Reset configuration options to default values
|
99
|
-
def reset_config!(options = {})
|
100
|
-
Azure::Storage::Common::Configurable.keys.each do |key|
|
101
|
-
value =
|
102
|
-
if self == Azure::Storage::Common
|
103
|
-
Azure::Storage::Common::Default.options[key]
|
104
|
-
else
|
105
|
-
self.send(key)
|
106
|
-
end
|
107
|
-
instance_variable_set(:"@#{key}", options.fetch(key, value))
|
108
|
-
|
109
|
-
# Set the secondary endpoint if the primary one is given
|
110
|
-
if key.to_s.include? "host"
|
111
|
-
instance_variable_set(:"@#{key}_secondary", secondary_endpoint(options.fetch(key, value)))
|
112
|
-
end
|
113
|
-
end
|
114
|
-
self.send(:reset_agents!) if self.respond_to?(:reset_agents!)
|
115
|
-
setup_signer_for_service(options[:api_version])
|
116
|
-
self
|
117
|
-
end
|
118
|
-
|
119
|
-
alias setup reset_config!
|
120
|
-
|
121
|
-
# Storage queue host
|
122
|
-
# @return [String]
|
123
|
-
def storage_queue_host(isSecondary = false)
|
124
|
-
if isSecondary
|
125
|
-
@storage_queue_host_secondary || default_host(:queue, true)
|
126
|
-
else
|
127
|
-
@storage_queue_host || default_host(:queue, false)
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
# Storage blob host
|
132
|
-
# @return [String]
|
133
|
-
def storage_blob_host(isSecondary = false)
|
134
|
-
if isSecondary
|
135
|
-
@storage_blob_host_secondary || default_host(:blob, true)
|
136
|
-
else
|
137
|
-
@storage_blob_host || default_host(:blob, false)
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
# Storage table host
|
142
|
-
# @return [String]
|
143
|
-
def storage_table_host(isSecondary = false)
|
144
|
-
if isSecondary
|
145
|
-
@storage_table_host_secondary || default_host(:table, true)
|
146
|
-
else
|
147
|
-
@storage_table_host || default_host(:table, false)
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
# Storage file host
|
152
|
-
# @return [String]
|
153
|
-
def storage_file_host(isSecondary = false)
|
154
|
-
if isSecondary
|
155
|
-
@storage_file_host_secondary || default_host(:file, true)
|
156
|
-
else
|
157
|
-
@storage_file_host || default_host(:file, false)
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
private
|
162
|
-
|
163
|
-
def default_host(service, isSecondary = false)
|
164
|
-
"https://#{storage_account_name}#{isSecondary ? "-secondary" : ""}.#{service}.core.windows.net" if storage_account_name
|
165
|
-
end
|
166
|
-
|
167
|
-
def setup_options
|
168
|
-
opts = {}
|
169
|
-
Azure::Storage::Common::Configurable.keys.map do |key|
|
170
|
-
opts[key] = self.send(key) if self.send(key)
|
171
|
-
end
|
172
|
-
opts
|
173
|
-
end
|
174
|
-
|
175
|
-
def account_name_from_endpoint(endpoint)
|
176
|
-
return nil if endpoint.nil?
|
177
|
-
uri = URI::parse endpoint
|
178
|
-
fields = uri.host.split "."
|
179
|
-
fields[0]
|
180
|
-
end
|
181
|
-
|
182
|
-
def secondary_endpoint(primary_endpoint)
|
183
|
-
return nil if primary_endpoint.nil?
|
184
|
-
account_name = account_name_from_endpoint primary_endpoint
|
185
|
-
primary_endpoint.sub account_name, account_name + "-secondary"
|
186
|
-
end
|
187
|
-
|
188
|
-
def determine_account_name
|
189
|
-
if instance_variable_get(:@storage_account_name).nil?
|
190
|
-
hosts = [@storage_blob_host, @storage_table_host, @storage_queue_host, @storage_file_host]
|
191
|
-
account_name = nil;
|
192
|
-
hosts.each do |host|
|
193
|
-
parsed = account_name_from_endpoint host
|
194
|
-
if account_name.nil?
|
195
|
-
account_name = parsed
|
196
|
-
elsif !account_name.nil? && !parsed.nil? && (account_name <=> parsed) != (0)
|
197
|
-
raise InvalidOptionsError, "Ambiguous account name in service hosts."
|
198
|
-
end
|
199
|
-
end
|
200
|
-
raise InvalidOptionsError, "Cannot identify account name." if account_name.nil?
|
201
|
-
@storage_account_name = account_name
|
202
|
-
end
|
203
|
-
end
|
204
|
-
|
205
|
-
def setup_signer_for_service(api_ver)
|
206
|
-
if @storage_sas_token
|
207
|
-
determine_account_name
|
208
|
-
@signer = Azure::Storage::Common::Core::Auth::SharedAccessSignatureSigner.new api_ver, @storage_account_name, @storage_sas_token
|
209
|
-
end
|
210
|
-
end
|
211
|
-
end
|
212
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#-------------------------------------------------------------------------
|
4
|
+
# # Copyright (c) Microsoft and contributors. All rights reserved.
|
5
|
+
#
|
6
|
+
# The MIT License(MIT)
|
7
|
+
|
8
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
9
|
+
# of this software and associated documentation files(the "Software"), to deal
|
10
|
+
# in the Software without restriction, including without limitation the rights
|
11
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
12
|
+
# copies of the Software, and to permit persons to whom the Software is
|
13
|
+
# furnished to do so, subject to the following conditions :
|
14
|
+
|
15
|
+
# The above copyright notice and this permission notice shall be included in
|
16
|
+
# all copies or substantial portions of the Software.
|
17
|
+
|
18
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
19
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
20
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
21
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
22
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
23
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
24
|
+
# THE SOFTWARE.
|
25
|
+
#--------------------------------------------------------------------------
|
26
|
+
|
27
|
+
module Azure::Storage::Common
|
28
|
+
# The Azure::Storage::Common::Configurable module provides basic configuration for Azure storage activities.
|
29
|
+
module Configurable
|
30
|
+
# @!attribute [w] storage_access_key
|
31
|
+
# @return [String] Azure Storage access key.
|
32
|
+
# @!attribute storage_account_name
|
33
|
+
# @return [String] Azure Storage account name.
|
34
|
+
# @!attribute storage_connection_string
|
35
|
+
# @return [String] Azure Storage connection string.
|
36
|
+
# @!attribute storage_blob_host
|
37
|
+
# @return [String] Set the host for the Blob service. Only set this if you want
|
38
|
+
# something custom (like, for example, to point this to a LocalStorage
|
39
|
+
# emulator). This should be the complete host, including http:// at the
|
40
|
+
# start. When using the emulator, make sure to include your account name at
|
41
|
+
# the end.
|
42
|
+
# @!attribute storage_table_host
|
43
|
+
# @return [String] Set the host for the Table service. Only set this if you want
|
44
|
+
# something custom (like, for example, to point this to a LocalStorage
|
45
|
+
# emulator). This should be the complete host, including http:// at the
|
46
|
+
# start. When using the emulator, make sure to include your account name at
|
47
|
+
# the end.
|
48
|
+
# @!attribute storage_queue_host
|
49
|
+
# @return [String] Set the host for the Queue service. Only set this if you want
|
50
|
+
# something custom (like, for example, to point this to a LocalStorage
|
51
|
+
# emulator). This should be the complete host, including http:// at the
|
52
|
+
# start. When using the emulator, make sure to include your account name at
|
53
|
+
# the end.
|
54
|
+
|
55
|
+
attr_accessor :storage_access_key,
|
56
|
+
:storage_account_name,
|
57
|
+
:storage_connection_string,
|
58
|
+
:storage_sas_token
|
59
|
+
|
60
|
+
attr_writer :storage_table_host,
|
61
|
+
:storage_blob_host,
|
62
|
+
:storage_queue_host,
|
63
|
+
:storage_file_host,
|
64
|
+
:storage_table_host_secondary,
|
65
|
+
:storage_blob_host_secondary,
|
66
|
+
:storage_queue_host_secondary,
|
67
|
+
:storage_file_host_secondary
|
68
|
+
|
69
|
+
attr_reader :signer
|
70
|
+
|
71
|
+
class << self
|
72
|
+
# List of configurable keys for {Azure::Client}
|
73
|
+
# @return [Array] of option keys
|
74
|
+
def keys
|
75
|
+
@keys ||= [
|
76
|
+
:storage_access_key,
|
77
|
+
:storage_account_name,
|
78
|
+
:storage_connection_string,
|
79
|
+
:storage_sas_token,
|
80
|
+
:storage_table_host,
|
81
|
+
:storage_blob_host,
|
82
|
+
:storage_queue_host,
|
83
|
+
:storage_file_host,
|
84
|
+
:signer
|
85
|
+
]
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
# Set configuration options using a block
|
90
|
+
def configure
|
91
|
+
yield self
|
92
|
+
end
|
93
|
+
|
94
|
+
def config
|
95
|
+
self
|
96
|
+
end
|
97
|
+
|
98
|
+
# Reset configuration options to default values
|
99
|
+
def reset_config!(options = {})
|
100
|
+
Azure::Storage::Common::Configurable.keys.each do |key|
|
101
|
+
value =
|
102
|
+
if self == Azure::Storage::Common
|
103
|
+
Azure::Storage::Common::Default.options[key]
|
104
|
+
else
|
105
|
+
self.send(key)
|
106
|
+
end
|
107
|
+
instance_variable_set(:"@#{key}", options.fetch(key, value))
|
108
|
+
|
109
|
+
# Set the secondary endpoint if the primary one is given
|
110
|
+
if key.to_s.include? "host"
|
111
|
+
instance_variable_set(:"@#{key}_secondary", secondary_endpoint(options.fetch(key, value)))
|
112
|
+
end
|
113
|
+
end
|
114
|
+
self.send(:reset_agents!) if self.respond_to?(:reset_agents!)
|
115
|
+
setup_signer_for_service(options[:api_version])
|
116
|
+
self
|
117
|
+
end
|
118
|
+
|
119
|
+
alias setup reset_config!
|
120
|
+
|
121
|
+
# Storage queue host
|
122
|
+
# @return [String]
|
123
|
+
def storage_queue_host(isSecondary = false)
|
124
|
+
if isSecondary
|
125
|
+
@storage_queue_host_secondary || default_host(:queue, true)
|
126
|
+
else
|
127
|
+
@storage_queue_host || default_host(:queue, false)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
# Storage blob host
|
132
|
+
# @return [String]
|
133
|
+
def storage_blob_host(isSecondary = false)
|
134
|
+
if isSecondary
|
135
|
+
@storage_blob_host_secondary || default_host(:blob, true)
|
136
|
+
else
|
137
|
+
@storage_blob_host || default_host(:blob, false)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
# Storage table host
|
142
|
+
# @return [String]
|
143
|
+
def storage_table_host(isSecondary = false)
|
144
|
+
if isSecondary
|
145
|
+
@storage_table_host_secondary || default_host(:table, true)
|
146
|
+
else
|
147
|
+
@storage_table_host || default_host(:table, false)
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
# Storage file host
|
152
|
+
# @return [String]
|
153
|
+
def storage_file_host(isSecondary = false)
|
154
|
+
if isSecondary
|
155
|
+
@storage_file_host_secondary || default_host(:file, true)
|
156
|
+
else
|
157
|
+
@storage_file_host || default_host(:file, false)
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
private
|
162
|
+
|
163
|
+
def default_host(service, isSecondary = false)
|
164
|
+
"https://#{storage_account_name}#{isSecondary ? "-secondary" : ""}.#{service}.core.windows.net" if storage_account_name
|
165
|
+
end
|
166
|
+
|
167
|
+
def setup_options
|
168
|
+
opts = {}
|
169
|
+
Azure::Storage::Common::Configurable.keys.map do |key|
|
170
|
+
opts[key] = self.send(key) if self.send(key)
|
171
|
+
end
|
172
|
+
opts
|
173
|
+
end
|
174
|
+
|
175
|
+
def account_name_from_endpoint(endpoint)
|
176
|
+
return nil if endpoint.nil?
|
177
|
+
uri = URI::parse endpoint
|
178
|
+
fields = uri.host.split "."
|
179
|
+
fields[0]
|
180
|
+
end
|
181
|
+
|
182
|
+
def secondary_endpoint(primary_endpoint)
|
183
|
+
return nil if primary_endpoint.nil?
|
184
|
+
account_name = account_name_from_endpoint primary_endpoint
|
185
|
+
primary_endpoint.sub account_name, account_name + "-secondary"
|
186
|
+
end
|
187
|
+
|
188
|
+
def determine_account_name
|
189
|
+
if instance_variable_get(:@storage_account_name).nil?
|
190
|
+
hosts = [@storage_blob_host, @storage_table_host, @storage_queue_host, @storage_file_host]
|
191
|
+
account_name = nil;
|
192
|
+
hosts.each do |host|
|
193
|
+
parsed = account_name_from_endpoint host
|
194
|
+
if account_name.nil?
|
195
|
+
account_name = parsed
|
196
|
+
elsif !account_name.nil? && !parsed.nil? && (account_name <=> parsed) != (0)
|
197
|
+
raise InvalidOptionsError, "Ambiguous account name in service hosts."
|
198
|
+
end
|
199
|
+
end
|
200
|
+
raise InvalidOptionsError, "Cannot identify account name." if account_name.nil?
|
201
|
+
@storage_account_name = account_name
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
def setup_signer_for_service(api_ver)
|
206
|
+
if @storage_sas_token
|
207
|
+
determine_account_name
|
208
|
+
@signer = Azure::Storage::Common::Core::Auth::SharedAccessSignatureSigner.new api_ver, @storage_account_name, @storage_sas_token
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|