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.
Files changed (116) hide show
  1. checksums.yaml +4 -4
  2. data/.env_sample +3 -1
  3. data/.gitignore +15 -0
  4. data/LICENSE.txt +1 -1
  5. data/README.md +322 -248
  6. data/Rakefile +3 -1
  7. data/azure.gemspec +18 -14
  8. data/lib/azure.rb +124 -38
  9. data/lib/azure/base_management/base_management_service.rb +57 -69
  10. data/lib/azure/base_management/location.rb +1 -1
  11. data/lib/azure/base_management/management_http_request.rb +55 -58
  12. data/lib/azure/base_management/serialization.rb +5 -0
  13. data/lib/azure/base_management/sql_management_http_request.rb +10 -20
  14. data/lib/azure/blob/auth/shared_access_signature.rb +82 -76
  15. data/lib/azure/blob/blob_service.rb +196 -171
  16. data/lib/azure/client.rb +31 -0
  17. data/lib/azure/client_services.rb +98 -0
  18. data/lib/azure/cloud_service_management/cloud_service_management_service.rb +8 -10
  19. data/lib/azure/configurable.rb +290 -0
  20. data/lib/azure/core/auth/authorizer.rb +1 -1
  21. data/lib/azure/core/auth/shared_key.rb +48 -40
  22. data/lib/azure/core/auth/shared_key_lite.rb +9 -9
  23. data/lib/azure/core/auth/signer.rb +15 -12
  24. data/lib/azure/core/error.rb +2 -3
  25. data/lib/azure/core/filtered_service.rb +4 -3
  26. data/lib/azure/core/http/http_error.rb +10 -12
  27. data/lib/azure/core/http/http_request.rb +82 -69
  28. data/lib/azure/core/http/http_response.rb +12 -56
  29. data/lib/azure/core/http/signer_filter.rb +3 -4
  30. data/lib/azure/core/service.rb +8 -25
  31. data/lib/azure/core/signed_service.rb +7 -5
  32. data/lib/azure/core/utility.rb +45 -6
  33. data/lib/azure/default.rb +126 -0
  34. data/lib/azure/http_client.rb +85 -0
  35. data/lib/azure/queue/queue.rb +0 -1
  36. data/lib/azure/queue/queue_service.rb +6 -4
  37. data/lib/azure/queue/serialization.rb +0 -1
  38. data/lib/azure/service/storage_service.rb +9 -6
  39. data/lib/azure/service_bus/auth/shared_access_signer.rb +44 -0
  40. data/lib/azure/service_bus/auth/wrap_service.rb +5 -4
  41. data/lib/azure/service_bus/auth/wrap_signer.rb +14 -6
  42. data/lib/azure/service_bus/service_bus_service.rb +34 -30
  43. data/lib/azure/sql_database_management/errors.rb +11 -0
  44. data/lib/azure/sql_database_management/firewall_rule.rb +30 -0
  45. data/lib/azure/sql_database_management/serialization.rb +40 -53
  46. data/lib/azure/sql_database_management/sql_database_management_service.rb +141 -130
  47. data/lib/azure/sql_database_management/{sql_database.rb → sql_server.rb} +4 -3
  48. data/lib/azure/storage_management/storage_management_service.rb +9 -10
  49. data/lib/azure/table/auth/shared_key.rb +17 -50
  50. data/lib/azure/table/auth/shared_key_lite.rb +3 -3
  51. data/lib/azure/table/serialization.rb +24 -24
  52. data/lib/azure/table/table_service.rb +21 -18
  53. data/lib/azure/version.rb +1 -1
  54. data/lib/azure/virtual_machine_image_management/virtual_machine_image_management_service.rb +6 -12
  55. data/lib/azure/virtual_machine_management/serialization.rb +4 -1
  56. data/lib/azure/virtual_machine_management/virtual_machine.rb +1 -0
  57. data/lib/azure/virtual_machine_management/virtual_machine_management_service.rb +29 -37
  58. data/lib/azure/virtual_network_management/virtual_network_management_service.rb +5 -6
  59. data/test/fixtures/list_locations.xml +150 -0
  60. data/test/fixtures/list_sql_database.xml +6 -18
  61. data/test/fixtures/list_sql_server_firewall.xml +18 -18
  62. data/test/fixtures/management_certificate.pfx +0 -0
  63. data/test/fixtures/virtual_machine.xml +1 -0
  64. data/test/integration/affinity_group/Create_Affinity_test.rb +1 -1
  65. data/test/integration/affinity_group/Update_Affinity_test.rb +4 -0
  66. data/test/integration/blob/blob_gb18030_test.rb +29 -29
  67. data/test/integration/blob/blob_pages_test.rb +16 -16
  68. data/test/integration/blob/container/create_container_test.rb +6 -6
  69. data/test/integration/blob/container/root_container_test.rb +2 -1
  70. data/test/integration/database/create_sql_server_firewall_test.rb +26 -31
  71. data/test/integration/database/create_sql_server_test.rb +6 -6
  72. data/test/integration/database/delete_sql_server_firewall_test.rb +18 -24
  73. data/test/integration/database/delete_sql_server_test.rb +9 -22
  74. data/test/integration/database/list_sql_server_firewall_test.rb +7 -8
  75. data/test/integration/database/list_sql_servers_test.rb +4 -4
  76. data/test/integration/database/reset_password_sql_server_test.rb +9 -11
  77. data/test/integration/location/RoleSize_List_test.rb +35 -0
  78. data/test/integration/queue/list_queues_test.rb +0 -1
  79. data/test/integration/service_bus/queues_scenario_test.rb +11 -11
  80. data/test/integration/service_bus/queues_test.rb +2 -2
  81. data/test/integration/service_bus/subscriptions_test.rb +25 -25
  82. data/test/integration/service_bus/topics_scenario_test.rb +6 -6
  83. data/test/integration/service_bus/topics_test.rb +15 -15
  84. data/test/integration/table/query_entities_test.rb +1 -0
  85. data/test/integration/table/table_acl_test.rb +9 -9
  86. data/test/integration/test_helper.rb +11 -9
  87. data/test/integration/vm/VM_Create_test.rb +23 -20
  88. data/test/integration/vnet/Virtual_Network_list_test.rb +1 -1
  89. data/test/test_helper.rb +5 -0
  90. data/test/unit/affinity_group/affinity_group_test.rb +4 -4
  91. data/test/unit/base_management/base_management_service_test.rb +19 -0
  92. data/test/unit/base_management/location_test.rb +6 -6
  93. data/test/unit/base_management/role_size_test.rb +50 -0
  94. data/test/unit/blob/auth/shared_access_signature_test.rb +19 -19
  95. data/test/unit/blob/blob_service_test.rb +583 -582
  96. data/test/unit/cloud_service_management/cloud_service_management_service_test.rb +2 -2
  97. data/test/unit/config/azure_test.rb +112 -0
  98. data/test/unit/config/client_test.rb +37 -0
  99. data/test/unit/core/auth/shared_key_lite_test.rb +15 -15
  100. data/test/unit/core/auth/shared_key_test.rb +26 -26
  101. data/test/unit/core/http/http_error_test.rb +13 -14
  102. data/test/unit/core/http/http_request_test.rb +78 -53
  103. data/test/unit/core/http/http_response_test.rb +2 -27
  104. data/test/unit/core/http/retry_policy_test.rb +3 -3
  105. data/test/unit/core/utility_test.rb +122 -0
  106. data/test/unit/database/serialization_test.rb +17 -20
  107. data/test/unit/database/sql_database_server_service_test.rb +97 -40
  108. data/test/unit/http_client_test.rb +74 -0
  109. data/test/unit/service/storage_service_test.rb +105 -101
  110. data/test/unit/storage_management/storage_management_service_test.rb +28 -28
  111. data/test/unit/virtual_machine_image_management/virtual_machine_image_management_service_test.rb +4 -4
  112. data/test/unit/virtual_machine_management/virtual_machine_management_service_test.rb +37 -20
  113. data/test/unit/vnet/virtual_network_management_service_test.rb +1 -1
  114. metadata +91 -20
  115. data/lib/azure/core.rb +0 -41
  116. 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
- def initialize
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
- # See http://msdn.microsoft.com/en-us/library/azure/gg715269.aspx
29
+ # @see http://msdn.microsoft.com/en-us/library/azure/gg715269.aspx
29
30
  #
30
- # Returns an array of Azure::SqlDatabaseManagement::SqlDatabase objects
31
+ # @return Array<Azure::SqlDatabaseManagement::SqlServer>
31
32
  def list_servers
32
- request_path = '/servers'
33
- request = BaseManagement::SqlManagementHttpRequest.new(:get, request_path, nil)
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
- # Public: Create a new database server in Microsoft Azure.
37
+ # Create a new sql server in Microsoft Azure.
39
38
  #
40
- # ==== Attributes
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
- # * +login+ - String. The administrator login name.
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
- # See http://msdn.microsoft.com/en-us/library/azure/gg715274.aspx
47
- #
48
- # Returns Azure::SqlDatabaseManagement::SqlDatabase object
49
- def create_server(login, password, location)
50
- body = Serialization.database_to_xml(login, password, location)
51
- request_path = '/servers'
52
- request = BaseManagement::SqlManagementHttpRequest.new(:post, request_path, body)
53
- response = request.call
54
- sql_server = Serialization.server_name_from_xml(response, login, location)
55
- Azure::Loggerx.info "SQL database server #{sql_server.name} is created." if sql_server
56
- sql_server
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
- # Public: Deletes the specified database server of given
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
- # * +name+ - String. Database server name.
75
+ # @param name [String] SqlServer name.
65
76
  #
66
- # See http://msdn.microsoft.com/en-us/library/azure/gg715285.aspx
77
+ # @see http://msdn.microsoft.com/en-us/library/azure/gg715285.aspx
67
78
  #
68
- # Returns: None
79
+ # @return [void]
69
80
  def delete_server(name)
70
- if get_sql_server(name)
71
- request_path = "/servers/#{name}"
72
- request = BaseManagement::SqlManagementHttpRequest.new(:delete, request_path)
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
- # Public: Sets the administrative password of a SQL Database server
79
- # for a subscription.
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
- # * +name+ - String. Database server name.
84
- # * +password+ - String. Database server new password.
89
+ # @param name [String] SqlServer name.
90
+ # @param password [String] SqlServer new password.
85
91
  #
86
- # See http://msdn.microsoft.com/en-us/library/azure/gg715272.aspx
92
+ # @see http://msdn.microsoft.com/en-us/library/azure/gg715272.aspx
87
93
  #
88
- # Returns: None
94
+ # @return [void]
89
95
  def reset_password(name, password)
90
- if get_sql_server(name)
91
- body = Serialization.reset_password_to_xml(password)
92
- request_path = "/servers/#{name}?op=ResetPassword"
93
- request = BaseManagement::SqlManagementHttpRequest.new(:post, request_path, body)
94
- request.call
95
- Azure::Loggerx.info "Password for server #{name} changed successfully."
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
- # Public: The Set Server Firewall Rule operation for the given
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
- # ==== Options
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
- # Accepted key/value pairs are:
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
- # Returns: None
117
- def set_sql_server_firewall_rule(server_name, rule_name, options = {})
118
- unless server_name.class == String && rule_name.class == String
119
- raise "Missing parameter server_name or rule_name."
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
- if get_sql_server(server_name)
122
- if options[:start_ip_address] || options[:end_ip_address]
123
- body = Serialization.firewall_rule_to_xml(options)
124
- request_path = "/servers/#{server_name}/firewallrules/#{rule_name}"
125
- method = :put
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
- # Public: Gets a list of server-level firewall rules set for
142
- # SQL database server.
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
- # * +server_name+ - String. Database server name.
146
+ # @param server_name [String] Database server name.
147
147
  #
148
- # See http://msdn.microsoft.com/en-us/library/azure/gg715278.aspx
148
+ # @see http://msdn.microsoft.com/en-us/library/azure/gg715278.aspx
149
149
  #
150
- # Returns an array of firewall
150
+ # @return [Array<Azure::SqlDatabaseManagement::FirewallRule>]
151
151
  def list_sql_server_firewall_rules(server_name)
152
- if get_sql_server(server_name)
153
- request_path = "/servers/#{server_name}/firewallrules"
154
- request = BaseManagement::SqlManagementHttpRequest.new(:get, request_path)
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
- # Public: Deletes a server-level firewall rule from a SQL Database server.
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
- # ==== Attributes
160
+ # @param server_name [String] SQL database server name.
161
+ # @param rule_name [String] SQL database server firewall rule name.
163
162
  #
164
- # * +name+ - String. SQL database server name.
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
- # See http://msdn.microsoft.com/en-us/library/azure/gg715277.aspx
168
- #
169
- # Returns: None
165
+ # @return [void]
170
166
  def delete_sql_server_firewall_rule(server_name, rule_name)
171
- if !list_sql_server_firewall_rules(server_name).collect{|x| x[:rule]}.include?(rule_name)
172
- error = "The specified firewall rule #{rule_name} does not exist."
173
- raise error
174
- elsif get_sql_server(server_name)
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 get_sql_server(server_name)
185
- if server_name.empty?
186
- error = Azure::Error::Error.new("DatabaseServerNotFound", 40645, "Servername cannot be empty or null.")
187
- else
188
- sql_server = list_servers.collect(&:name).include?(server_name)
189
- if sql_server
190
- return sql_server
191
- else
192
- error = Azure::Error::Error.new("DatabaseServerNotFound", 40647, "Subscription #{Azure.config.subscription_id} does not have server #{server_name}.")
193
- end
194
- end
195
- raise error if error
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 SqlDatabase
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 :feature_name
27
- attr_accessor :feature_value
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 = Azure::BaseManagement::ManagementHttpRequest.new(:get, request_path, nil)
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 = Azure::BaseManagement::ManagementHttpRequest.new(:get, request_path, nil)
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 = Azure::BaseManagement::ManagementHttpRequest.new(:post, request_path, body)
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 = Azure::BaseManagement::ManagementHttpRequest.new(:put, request_path, body)
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 = Azure::BaseManagement::ManagementHttpRequest.new(:delete, request_path)
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 = Azure::BaseManagement::ManagementHttpRequest.new(:post, path, body)
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 = Azure::BaseManagement::ManagementHttpRequest.new(:get, path)
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 "cgi"
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::Signer
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
- # verb - The HTTP request method.
60
- # uri - The URI of the request we're signing.
61
- # headers - A Hash of HTTP request 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
- method.to_s.upcase,
67
- headers.fetch("Content-MD5", ""),
68
- headers.fetch("Content-Type", ""),
69
- headers.fetch("Date") { headers.fetch("x-ms-date") },
70
- canonicalized_resource(uri)
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 - The request's URI.
44
+ # @param uri [URI] The request's URI.
77
45
  #
78
- # Returns a String with the canonicalized resource.
46
+ # @return [String] with the canonicalized resource.
79
47
  def canonicalized_resource(uri)
80
- resource = "/%s%s" % [account_name, uri.path]
48
+ resource = "/#{account_name}#{uri.path}"
81
49
 
82
- comp = CGI.parse(uri.query.to_s).fetch("comp", nil)
83
- if (comp)
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