azure 0.7.0.pre → 0.7.0.pre2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.env_sample +3 -1
- data/.gitignore +15 -0
- data/LICENSE.txt +1 -1
- data/README.md +322 -248
- data/Rakefile +3 -1
- data/azure.gemspec +18 -14
- data/lib/azure.rb +124 -38
- data/lib/azure/base_management/base_management_service.rb +57 -69
- data/lib/azure/base_management/location.rb +1 -1
- data/lib/azure/base_management/management_http_request.rb +55 -58
- data/lib/azure/base_management/serialization.rb +5 -0
- data/lib/azure/base_management/sql_management_http_request.rb +10 -20
- data/lib/azure/blob/auth/shared_access_signature.rb +82 -76
- data/lib/azure/blob/blob_service.rb +196 -171
- data/lib/azure/client.rb +31 -0
- data/lib/azure/client_services.rb +98 -0
- data/lib/azure/cloud_service_management/cloud_service_management_service.rb +8 -10
- data/lib/azure/configurable.rb +290 -0
- data/lib/azure/core/auth/authorizer.rb +1 -1
- data/lib/azure/core/auth/shared_key.rb +48 -40
- data/lib/azure/core/auth/shared_key_lite.rb +9 -9
- data/lib/azure/core/auth/signer.rb +15 -12
- data/lib/azure/core/error.rb +2 -3
- data/lib/azure/core/filtered_service.rb +4 -3
- data/lib/azure/core/http/http_error.rb +10 -12
- data/lib/azure/core/http/http_request.rb +82 -69
- data/lib/azure/core/http/http_response.rb +12 -56
- data/lib/azure/core/http/signer_filter.rb +3 -4
- data/lib/azure/core/service.rb +8 -25
- data/lib/azure/core/signed_service.rb +7 -5
- data/lib/azure/core/utility.rb +45 -6
- data/lib/azure/default.rb +126 -0
- data/lib/azure/http_client.rb +85 -0
- data/lib/azure/queue/queue.rb +0 -1
- data/lib/azure/queue/queue_service.rb +6 -4
- data/lib/azure/queue/serialization.rb +0 -1
- data/lib/azure/service/storage_service.rb +9 -6
- data/lib/azure/service_bus/auth/shared_access_signer.rb +44 -0
- data/lib/azure/service_bus/auth/wrap_service.rb +5 -4
- data/lib/azure/service_bus/auth/wrap_signer.rb +14 -6
- data/lib/azure/service_bus/service_bus_service.rb +34 -30
- data/lib/azure/sql_database_management/errors.rb +11 -0
- data/lib/azure/sql_database_management/firewall_rule.rb +30 -0
- data/lib/azure/sql_database_management/serialization.rb +40 -53
- data/lib/azure/sql_database_management/sql_database_management_service.rb +141 -130
- data/lib/azure/sql_database_management/{sql_database.rb → sql_server.rb} +4 -3
- data/lib/azure/storage_management/storage_management_service.rb +9 -10
- data/lib/azure/table/auth/shared_key.rb +17 -50
- data/lib/azure/table/auth/shared_key_lite.rb +3 -3
- data/lib/azure/table/serialization.rb +24 -24
- data/lib/azure/table/table_service.rb +21 -18
- data/lib/azure/version.rb +1 -1
- data/lib/azure/virtual_machine_image_management/virtual_machine_image_management_service.rb +6 -12
- data/lib/azure/virtual_machine_management/serialization.rb +4 -1
- data/lib/azure/virtual_machine_management/virtual_machine.rb +1 -0
- data/lib/azure/virtual_machine_management/virtual_machine_management_service.rb +29 -37
- data/lib/azure/virtual_network_management/virtual_network_management_service.rb +5 -6
- data/test/fixtures/list_locations.xml +150 -0
- data/test/fixtures/list_sql_database.xml +6 -18
- data/test/fixtures/list_sql_server_firewall.xml +18 -18
- data/test/fixtures/management_certificate.pfx +0 -0
- data/test/fixtures/virtual_machine.xml +1 -0
- data/test/integration/affinity_group/Create_Affinity_test.rb +1 -1
- data/test/integration/affinity_group/Update_Affinity_test.rb +4 -0
- data/test/integration/blob/blob_gb18030_test.rb +29 -29
- data/test/integration/blob/blob_pages_test.rb +16 -16
- data/test/integration/blob/container/create_container_test.rb +6 -6
- data/test/integration/blob/container/root_container_test.rb +2 -1
- data/test/integration/database/create_sql_server_firewall_test.rb +26 -31
- data/test/integration/database/create_sql_server_test.rb +6 -6
- data/test/integration/database/delete_sql_server_firewall_test.rb +18 -24
- data/test/integration/database/delete_sql_server_test.rb +9 -22
- data/test/integration/database/list_sql_server_firewall_test.rb +7 -8
- data/test/integration/database/list_sql_servers_test.rb +4 -4
- data/test/integration/database/reset_password_sql_server_test.rb +9 -11
- data/test/integration/location/RoleSize_List_test.rb +35 -0
- data/test/integration/queue/list_queues_test.rb +0 -1
- data/test/integration/service_bus/queues_scenario_test.rb +11 -11
- data/test/integration/service_bus/queues_test.rb +2 -2
- data/test/integration/service_bus/subscriptions_test.rb +25 -25
- data/test/integration/service_bus/topics_scenario_test.rb +6 -6
- data/test/integration/service_bus/topics_test.rb +15 -15
- data/test/integration/table/query_entities_test.rb +1 -0
- data/test/integration/table/table_acl_test.rb +9 -9
- data/test/integration/test_helper.rb +11 -9
- data/test/integration/vm/VM_Create_test.rb +23 -20
- data/test/integration/vnet/Virtual_Network_list_test.rb +1 -1
- data/test/test_helper.rb +5 -0
- data/test/unit/affinity_group/affinity_group_test.rb +4 -4
- data/test/unit/base_management/base_management_service_test.rb +19 -0
- data/test/unit/base_management/location_test.rb +6 -6
- data/test/unit/base_management/role_size_test.rb +50 -0
- data/test/unit/blob/auth/shared_access_signature_test.rb +19 -19
- data/test/unit/blob/blob_service_test.rb +583 -582
- data/test/unit/cloud_service_management/cloud_service_management_service_test.rb +2 -2
- data/test/unit/config/azure_test.rb +112 -0
- data/test/unit/config/client_test.rb +37 -0
- data/test/unit/core/auth/shared_key_lite_test.rb +15 -15
- data/test/unit/core/auth/shared_key_test.rb +26 -26
- data/test/unit/core/http/http_error_test.rb +13 -14
- data/test/unit/core/http/http_request_test.rb +78 -53
- data/test/unit/core/http/http_response_test.rb +2 -27
- data/test/unit/core/http/retry_policy_test.rb +3 -3
- data/test/unit/core/utility_test.rb +122 -0
- data/test/unit/database/serialization_test.rb +17 -20
- data/test/unit/database/sql_database_server_service_test.rb +97 -40
- data/test/unit/http_client_test.rb +74 -0
- data/test/unit/service/storage_service_test.rb +105 -101
- data/test/unit/storage_management/storage_management_service_test.rb +28 -28
- data/test/unit/virtual_machine_image_management/virtual_machine_image_management_service_test.rb +4 -4
- data/test/unit/virtual_machine_management/virtual_machine_management_service_test.rb +37 -20
- data/test/unit/vnet/virtual_network_management_service_test.rb +1 -1
- metadata +91 -20
- data/lib/azure/core.rb +0 -41
- data/lib/azure/core/configuration.rb +0 -218
@@ -12,189 +12,200 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
#--------------------------------------------------------------------------
|
15
|
+
|
16
|
+
require 'socket'
|
17
|
+
require 'azure/sql_database_management/sql_server'
|
18
|
+
require 'azure/sql_database_management/firewall_rule'
|
15
19
|
require 'azure/sql_database_management/serialization'
|
20
|
+
require 'azure/sql_database_management/errors'
|
16
21
|
|
17
22
|
module Azure
|
18
23
|
module SqlDatabaseManagement
|
24
|
+
# Service for managing SQL Azure servers and databases
|
19
25
|
class SqlDatabaseManagementService < BaseManagement::BaseManagementService
|
20
26
|
|
21
|
-
|
22
|
-
super()
|
23
|
-
end
|
24
|
-
|
25
|
-
# Public: Gets a list of database servers available under the
|
26
|
-
# current subscription.
|
27
|
+
# Gets a list of database servers available under the current subscription.
|
27
28
|
#
|
28
|
-
#
|
29
|
+
# @see http://msdn.microsoft.com/en-us/library/azure/gg715269.aspx
|
29
30
|
#
|
30
|
-
#
|
31
|
+
# @return Array<Azure::SqlDatabaseManagement::SqlServer>
|
31
32
|
def list_servers
|
32
|
-
|
33
|
-
|
34
|
-
response = request.call
|
35
|
-
Serialization.databases_from_xml(response)
|
33
|
+
response = client.sql_management_request(:get, servers_path).call
|
34
|
+
Serialization.servers_from_xml(response)
|
36
35
|
end
|
37
36
|
|
38
|
-
#
|
37
|
+
# Create a new sql server in Microsoft Azure.
|
39
38
|
#
|
40
|
-
#
|
39
|
+
# @param login [String] The administrator login name.
|
40
|
+
# @param password [String] The administrator login password.
|
41
|
+
# @param location [String] The location where the database server will be created.
|
42
|
+
# @param version [String|Integer] The version of the SQL server (default 12.0)
|
41
43
|
#
|
42
|
-
#
|
43
|
-
# * +password+ - String. The administrator login password.
|
44
|
-
# * +:location+ - String. The location where the database server will be created.
|
44
|
+
# @see https://msdn.microsoft.com/en-us/library/azure/dn505699.aspx
|
45
45
|
#
|
46
|
-
#
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
46
|
+
# @return [Azure::SqlDatabaseManagement::SqlServer]
|
47
|
+
def create_server(login, password, location, version = 12.0)
|
48
|
+
body = Serialization.server_to_xml(login, password, location, version)
|
49
|
+
server_names = list_servers.map(&:name)
|
50
|
+
created_server = nil
|
51
|
+
|
52
|
+
begin
|
53
|
+
response = client.sql_management_request(:post, servers_path, body: body, warn: true).call
|
54
|
+
created_server = Serialization.server_name_from_xml(response, login, location, version)
|
55
|
+
rescue RuntimeError => ex
|
56
|
+
if ex.message =~ /Please retry the request/
|
57
|
+
created_server = list_servers.reject{|server| server_names.include?(server.name)}.first
|
58
|
+
# sometimes the service returns 500, but it doesn't really mean it.
|
59
|
+
#
|
60
|
+
# If the operation returns success, the operation is complete and the server is created immediately. If the
|
61
|
+
# operation fails because of a user error, a server is not created. If there is a communication error or
|
62
|
+
# internal server error, you should check the status of the operation using List Servers.
|
63
|
+
#
|
64
|
+
raise unless created_server
|
65
|
+
else
|
66
|
+
raise
|
67
|
+
end
|
68
|
+
end
|
69
|
+
Azure::Loggerx.info "SQL database server #{created_server.name} is created." if created_server
|
70
|
+
created_server
|
57
71
|
end
|
58
72
|
|
59
|
-
#
|
60
|
-
# subscription id from Microsoft Azure.
|
61
|
-
#
|
62
|
-
# ==== Attributes
|
73
|
+
# Deletes the specified database server of given subscription id from Microsoft Azure.
|
63
74
|
#
|
64
|
-
#
|
75
|
+
# @param name [String] SqlServer name.
|
65
76
|
#
|
66
|
-
#
|
77
|
+
# @see http://msdn.microsoft.com/en-us/library/azure/gg715285.aspx
|
67
78
|
#
|
68
|
-
#
|
79
|
+
# @return [void]
|
69
80
|
def delete_server(name)
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
request.call
|
74
|
-
Azure::Loggerx.info "Deleted database server #{name}."
|
75
|
-
end
|
81
|
+
ensure_server_exists!(name)
|
82
|
+
client.sql_management_request(:delete, servers_path(name)).call
|
83
|
+
Azure::Loggerx.info "Deleted database server #{name}."
|
76
84
|
end
|
77
85
|
|
78
|
-
#
|
79
|
-
#
|
80
|
-
#
|
81
|
-
# ==== Attributes
|
86
|
+
# Sets the administrative password of a SQL Database server for a subscription. Will raise
|
87
|
+
# Azure::SqlManagement::Error if server does not exist.
|
82
88
|
#
|
83
|
-
#
|
84
|
-
#
|
89
|
+
# @param name [String] SqlServer name.
|
90
|
+
# @param password [String] SqlServer new password.
|
85
91
|
#
|
86
|
-
#
|
92
|
+
# @see http://msdn.microsoft.com/en-us/library/azure/gg715272.aspx
|
87
93
|
#
|
88
|
-
#
|
94
|
+
# @return [void]
|
89
95
|
def reset_password(name, password)
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
end
|
96
|
+
ensure_server_exists!(name)
|
97
|
+
body = Serialization.reset_password_to_xml(password)
|
98
|
+
request_path = servers_path + "#{name}?op=ResetPassword"
|
99
|
+
request = client.sql_management_request(:post, request_path, body)
|
100
|
+
request.call
|
101
|
+
Azure::Loggerx.info "Password for server #{name} changed successfully."
|
97
102
|
end
|
98
103
|
|
99
|
-
#
|
100
|
-
# subscription adds a new server-level firewall or updates an
|
101
|
-
# existing server-level firewall rule for a SQL Database server.
|
102
|
-
#
|
103
|
-
# ==== Attributes
|
104
|
-
#
|
105
|
-
# * +server_name+ - String. Database server name.
|
106
|
-
# * +rule_name+ - String. Database server new password.
|
104
|
+
# Adds a new server-level firewall or updates an existing server-level firewall rule for a SQL Database server.
|
107
105
|
#
|
108
|
-
#
|
106
|
+
# @param server_name [String] SqlServer server name.
|
107
|
+
# @param rule_name [String] Firewall rule name.
|
108
|
+
# @param start_ip [String] The lowest IP address in the range of the server-level firewall setting.
|
109
|
+
# IP addresses equal to or greater than this can attempt to connect to the server.
|
110
|
+
# The lowest possible IP address is 0.0.0.0. (default: first local public ip)
|
111
|
+
# @param end_ip [String] The highest IP address in the range of the server-level firewall setting. IP
|
112
|
+
# addresses equal to or less than this can attempt to connect to the server. The
|
113
|
+
# highest possible IP address is 255.255.255.255. (default: first local public ip)
|
109
114
|
#
|
110
|
-
#
|
111
|
-
# * +:start_ip_address+ - String. Start of the IP Range
|
112
|
-
# * +:end_ip_address+ - String. End of the IP Range
|
113
|
-
#
|
114
|
-
# See http://msdn.microsoft.com/en-us/library/azure/gg715280.aspx
|
115
|
+
# @see http://msdn.microsoft.com/en-us/library/azure/gg715280.aspx
|
115
116
|
#
|
116
|
-
#
|
117
|
-
def set_sql_server_firewall_rule(server_name, rule_name,
|
118
|
-
|
119
|
-
|
117
|
+
# @return [void]
|
118
|
+
def set_sql_server_firewall_rule(server_name, rule_name, start_ip = public_ipv4, end_ip = public_ipv4)
|
119
|
+
|
120
|
+
if [server_name, rule_name, start_ip, end_ip].any? { |arg| arg.nil? || arg.empty? || !arg.kind_of?(String) }
|
121
|
+
raise ArgumentError.new('Missing or empty parameter server_name, rule_name, start_ip or end_ip')
|
120
122
|
end
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
else
|
127
|
-
request_path = "/servers/#{server_name}/firewallrules/#{rule_name}?op=AutoDetectClientIP"
|
128
|
-
method = :post
|
129
|
-
end
|
130
|
-
request = BaseManagement::SqlManagementHttpRequest.new(method, request_path, body)
|
131
|
-
request.headers['x-ms-version'] = '1.0'
|
132
|
-
request.uri = URI.parse(Azure.config.sql_database_management_endpoint + Azure.config.subscription_id + request_path)
|
133
|
-
# Management certificate authentication Endpoint throws errors for this operation. Need to re-visit
|
134
|
-
# this once the Azure API is working.
|
135
|
-
|
136
|
-
request.call
|
137
|
-
Azure::Loggerx.info "Added server-level firewall rule #{rule_name}."
|
123
|
+
|
124
|
+
fw_rule = FirewallRule.new do |rule|
|
125
|
+
rule.name = rule_name
|
126
|
+
rule.start_ip_address = start_ip
|
127
|
+
rule.end_ip_address = end_ip
|
138
128
|
end
|
129
|
+
|
130
|
+
body = Serialization.firewall_rule_to_xml(fw_rule)
|
131
|
+
method = if list_sql_server_firewall_rules(server_name).any? { |rule| rule.name == rule_name }
|
132
|
+
# the rule exists, so we need to update the rule
|
133
|
+
:put
|
134
|
+
else
|
135
|
+
# the rule doesn't exist, so we need to create the rule
|
136
|
+
:post
|
137
|
+
end
|
138
|
+
request_path = servers_path "#{server_name}/firewallrules/#{method == :put ? rule_name : ''}"
|
139
|
+
client.sql_management_request(method, request_path, body).call
|
140
|
+
Azure::Loggerx.info "Modified server-level firewall rule #{rule_name}."
|
139
141
|
end
|
140
142
|
|
141
|
-
#
|
142
|
-
#
|
143
|
-
#
|
144
|
-
# ==== Attributes
|
143
|
+
# Gets a list of server-level firewall rules set for SQL database servers. Will raise
|
144
|
+
# Azure::SqlManagement::Error if server does not exist.
|
145
145
|
#
|
146
|
-
#
|
146
|
+
# @param server_name [String] Database server name.
|
147
147
|
#
|
148
|
-
#
|
148
|
+
# @see http://msdn.microsoft.com/en-us/library/azure/gg715278.aspx
|
149
149
|
#
|
150
|
-
#
|
150
|
+
# @return [Array<Azure::SqlDatabaseManagement::FirewallRule>]
|
151
151
|
def list_sql_server_firewall_rules(server_name)
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
response = request.call
|
156
|
-
Serialization.database_firewall_from_xml(response)
|
157
|
-
end
|
152
|
+
ensure_server_exists!(server_name)
|
153
|
+
response = client.sql_management_request(:get, servers_path("#{server_name}/firewallrules")).call
|
154
|
+
Serialization.database_firewall_from_xml(response)
|
158
155
|
end
|
159
156
|
|
160
|
-
#
|
157
|
+
# Deletes a server-level firewall rule from a SQL Database server. Will raise
|
158
|
+
# Azure::SqlManagement::Error if server does not exist.
|
161
159
|
#
|
162
|
-
#
|
160
|
+
# @param server_name [String] SQL database server name.
|
161
|
+
# @param rule_name [String] SQL database server firewall rule name.
|
163
162
|
#
|
164
|
-
#
|
165
|
-
# * +rule_name+ - String. SQL database server firewall rule name.
|
163
|
+
# @see http://msdn.microsoft.com/en-us/library/azure/gg715277.aspx
|
166
164
|
#
|
167
|
-
#
|
168
|
-
#
|
169
|
-
# Returns: None
|
165
|
+
# @return [void]
|
170
166
|
def delete_sql_server_firewall_rule(server_name, rule_name)
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
request_path = "/servers/#{server_name}/firewallrules/#{rule_name}"
|
176
|
-
request = BaseManagement::SqlManagementHttpRequest.new(:delete, request_path)
|
177
|
-
request.call
|
167
|
+
ensure_server_exists!(server_name)
|
168
|
+
if list_sql_server_firewall_rules(server_name).any? { |rule| rule.name == rule_name }
|
169
|
+
request_path = servers_path "#{server_name}/firewallrules/#{rule_name}"
|
170
|
+
client.sql_management_request(:delete, request_path).call
|
178
171
|
Azure::Loggerx.info "Deleted server-level firewall rule #{rule_name}."
|
172
|
+
else
|
173
|
+
raise RuleDoesNotExist.new("Firewall rule named #{rule_name} does not exist for server named #{server_name}")
|
179
174
|
end
|
180
175
|
end
|
181
176
|
|
182
177
|
private
|
183
178
|
|
184
|
-
def
|
185
|
-
if
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
179
|
+
def servers_path(end_path = '')
|
180
|
+
'/servers' + if end_path.start_with?('/')
|
181
|
+
end_path
|
182
|
+
elsif end_path.empty?
|
183
|
+
''
|
184
|
+
else
|
185
|
+
"/#{end_path}"
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
# Ensures the a database server of a given name exists and raises Azure::SqlManagement::ServerDoesNotExist if it
|
190
|
+
# does not exist
|
191
|
+
#
|
192
|
+
# @param server_name [String] The name of the Azure SQL Server
|
193
|
+
# @return [void] Returns true if the server exists
|
194
|
+
def ensure_server_exists!(server_name)
|
195
|
+
raise ServerDoesNotExist.new("Server named #{server_name} does not exist.") unless server_exists?(server_name)
|
196
|
+
end
|
197
|
+
|
198
|
+
def server_exists?(server_name)
|
199
|
+
ArgumentError.new('Servername cannot be empty or null.') if server_name.empty?
|
200
|
+
list_servers.any? { |server| server.name == server_name }
|
201
|
+
end
|
202
|
+
|
203
|
+
def public_ipv4
|
204
|
+
@public_ip ||= `curl -s whatismyip.akamai.com`
|
196
205
|
end
|
197
206
|
|
198
207
|
end
|
199
208
|
end
|
200
209
|
end
|
210
|
+
|
211
|
+
Azure::SqlDatabaseManagementService = Azure::SqlDatabaseManagement::SqlDatabaseManagementService
|
@@ -14,7 +14,7 @@
|
|
14
14
|
#--------------------------------------------------------------------------
|
15
15
|
module Azure
|
16
16
|
module SqlDatabaseManagement
|
17
|
-
class
|
17
|
+
class SqlServer
|
18
18
|
|
19
19
|
def initialize
|
20
20
|
yield self if block_given?
|
@@ -23,8 +23,9 @@ module Azure
|
|
23
23
|
attr_accessor :name
|
24
24
|
attr_accessor :administrator_login
|
25
25
|
attr_accessor :location
|
26
|
-
attr_accessor :
|
27
|
-
attr_accessor :
|
26
|
+
attr_accessor :fully_qualified_domain_name
|
27
|
+
attr_accessor :version
|
28
|
+
attr_accessor :state
|
28
29
|
|
29
30
|
end
|
30
31
|
end
|
@@ -18,16 +18,13 @@ module Azure
|
|
18
18
|
module StorageManagement
|
19
19
|
# Provides Storage Management API
|
20
20
|
class StorageManagementService < BaseManagement::BaseManagementService
|
21
|
-
def initialize
|
22
|
-
super()
|
23
|
-
end
|
24
21
|
# Public: Gets a list of storage accounts available under the
|
25
22
|
# current subscription.
|
26
23
|
#
|
27
24
|
# Returns an array of Azure::StorageManagement::StorageAccount objects
|
28
25
|
def list_storage_accounts
|
29
26
|
request_path = '/services/storageservices'
|
30
|
-
request =
|
27
|
+
request = client.management_request(:get, request_path)
|
31
28
|
response = request.call
|
32
29
|
Serialization.storage_services_from_xml(response)
|
33
30
|
end
|
@@ -54,7 +51,7 @@ module Azure
|
|
54
51
|
# Returns the storage account
|
55
52
|
def get_storage_account_properties(name)
|
56
53
|
request_path = "/services/storageservices/#{name}"
|
57
|
-
request =
|
54
|
+
request = client.management_request(:get, request_path)
|
58
55
|
response = request.call
|
59
56
|
Serialization.storage_services_from_xml(response).first
|
60
57
|
end
|
@@ -97,7 +94,7 @@ module Azure
|
|
97
94
|
Azure::Loggerx.info "Creating Storage Account #{name}."
|
98
95
|
body = Serialization.storage_services_to_xml(name, options)
|
99
96
|
request_path = '/services/storageservices'
|
100
|
-
request =
|
97
|
+
request = client.management_request(:post, request_path, body: body)
|
101
98
|
request.call
|
102
99
|
end
|
103
100
|
end
|
@@ -134,7 +131,7 @@ module Azure
|
|
134
131
|
Azure::Loggerx.info "Account '#{name}' exists, updating..."
|
135
132
|
body = Serialization.storage_update_to_xml options
|
136
133
|
request_path = "/services/storageservices/#{name}"
|
137
|
-
request =
|
134
|
+
request = client.management_request(:put, request_path, body)
|
138
135
|
request.call
|
139
136
|
else
|
140
137
|
Azure::Loggerx.warn "Storage Account '#{name}' does not exist. Skipped..."
|
@@ -154,7 +151,7 @@ module Azure
|
|
154
151
|
def delete_storage_account(name)
|
155
152
|
Azure::Loggerx.info "Deleting Storage Account #{name}."
|
156
153
|
request_path = "/services/storageservices/#{name}"
|
157
|
-
request =
|
154
|
+
request = client.management_request(:delete, request_path)
|
158
155
|
request.call
|
159
156
|
rescue => e
|
160
157
|
e.message
|
@@ -175,7 +172,7 @@ module Azure
|
|
175
172
|
if get_storage_account name
|
176
173
|
path = "/services/storageservices/#{name}/keys?action=regenerate"
|
177
174
|
body = Serialization.regenerate_storage_account_keys_to_xml key_type
|
178
|
-
request =
|
175
|
+
request = client.management_request(:post, path, body)
|
179
176
|
response = request.call
|
180
177
|
Serialization.storage_account_keys_from_xml(response)
|
181
178
|
else
|
@@ -196,7 +193,7 @@ module Azure
|
|
196
193
|
def get_storage_account_keys(name)
|
197
194
|
if get_storage_account name
|
198
195
|
path = "/services/storageservices/#{name}/keys"
|
199
|
-
request =
|
196
|
+
request = client.management_request(:get, path)
|
200
197
|
response = request.call
|
201
198
|
Serialization.storage_account_keys_from_xml(response)
|
202
199
|
else
|
@@ -206,3 +203,5 @@ module Azure
|
|
206
203
|
end
|
207
204
|
end
|
208
205
|
end
|
206
|
+
|
207
|
+
Azure::StorageManagementService = Azure::StorageManagement::StorageManagementService
|
@@ -12,80 +12,47 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
#--------------------------------------------------------------------------
|
15
|
-
require
|
16
|
-
|
17
|
-
require "azure/core/configuration"
|
18
|
-
require "azure/core/auth/signer"
|
15
|
+
require 'cgi'
|
16
|
+
require 'azure/core/auth/signer'
|
19
17
|
|
20
18
|
module Azure
|
21
19
|
module Table
|
22
20
|
module Auth
|
23
|
-
class SharedKey < Azure::Core::Auth::
|
21
|
+
class SharedKey < Azure::Core::Auth::SharedKey
|
24
22
|
# The account name
|
25
23
|
attr :account_name
|
26
24
|
|
27
|
-
# Public: Initialize the Signer.
|
28
|
-
#
|
29
|
-
# account_name - The account name. Defaults to the one in the
|
30
|
-
# global configuration.
|
31
|
-
# access_key - The access_key encoded in Base64. Defaults to the
|
32
|
-
# one in the global configuration.
|
33
|
-
def initialize(account_name=Azure.config.storage_account_name, access_key=Azure.config.storage_access_key)
|
34
|
-
@account_name = account_name
|
35
|
-
super(access_key)
|
36
|
-
end
|
37
|
-
|
38
|
-
# Public: The name of the strategy.
|
39
|
-
#
|
40
|
-
# Returns a String.
|
41
|
-
def name
|
42
|
-
"SharedKey"
|
43
|
-
end
|
44
|
-
|
45
|
-
# Public: Generate a request signature.
|
46
|
-
#
|
47
|
-
# verb - The HTTP request method.
|
48
|
-
# uri - The URI of the request we're signing.
|
49
|
-
# headers - A Hash of HTTP request headers.
|
50
|
-
#
|
51
|
-
# Returns a Base64 String signed with HMAC.
|
52
|
-
def sign(method, uri, headers)
|
53
|
-
signature = super(signable_string(method, uri, headers))
|
54
|
-
return "#{account_name}:#{signature}"
|
55
|
-
end
|
56
|
-
|
57
25
|
# Generate the string to sign.
|
58
26
|
#
|
59
|
-
#
|
60
|
-
# uri
|
61
|
-
# headers
|
27
|
+
# @param method [Symbol] The HTTP request method.
|
28
|
+
# @param uri [URI] The URI of the request we're signing.
|
29
|
+
# @param headers [Hash] The HTTP request headers.
|
62
30
|
#
|
63
31
|
# Returns a plain text string.
|
64
32
|
def signable_string(method, uri, headers)
|
65
33
|
[
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
34
|
+
method.to_s.upcase,
|
35
|
+
headers.fetch('Content-MD5', ''),
|
36
|
+
headers.fetch('Content-Type', ''),
|
37
|
+
headers.fetch('Date') { headers.fetch('x-ms-date') },
|
38
|
+
canonicalized_resource(uri)
|
71
39
|
].join("\n")
|
72
40
|
end
|
73
41
|
|
74
42
|
# Calculate the Canonicalized Resource string for a request.
|
75
43
|
#
|
76
|
-
# uri
|
44
|
+
# @param uri [URI] The request's URI.
|
77
45
|
#
|
78
|
-
#
|
46
|
+
# @return [String] with the canonicalized resource.
|
79
47
|
def canonicalized_resource(uri)
|
80
|
-
resource = "
|
48
|
+
resource = "/#{account_name}#{uri.path}"
|
81
49
|
|
82
|
-
comp = CGI.parse(uri.query.to_s).fetch(
|
83
|
-
if
|
84
|
-
resource = [resource, "comp=" + comp[0]].join("?")
|
85
|
-
end
|
50
|
+
comp = CGI.parse(uri.query.to_s).fetch('comp', nil)
|
51
|
+
resource = [resource, 'comp=' + comp[0]].join('?') if comp
|
86
52
|
|
87
53
|
resource
|
88
54
|
end
|
55
|
+
|
89
56
|
end
|
90
57
|
end
|
91
58
|
end
|