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
@@ -0,0 +1,31 @@
1
+ #-------------------------------------------------------------------------
2
+ # # Copyright (c) Microsoft and contributors. All rights reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ #--------------------------------------------------------------------------
15
+
16
+ module Azure
17
+ class Client
18
+ include Azure::Configurable
19
+ include Azure::HttpClient
20
+ include Azure::ClientServices
21
+
22
+ def initialize(options = {})
23
+ reset!(options)
24
+ end
25
+
26
+ # Check if this client is configured with the same options
27
+ def same_options?(opts)
28
+ opts.hash == options.hash
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,98 @@
1
+ #-------------------------------------------------------------------------
2
+ # # Copyright (c) Microsoft and contributors. All rights reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ #--------------------------------------------------------------------------
15
+
16
+ module Azure
17
+ # The Azure::Configurable module provides quick access to the Azure services and initializes the service to use
18
+ # the configuration of the class it's mixed into.
19
+ module ClientServices
20
+ # Azure Blob service configured for this Azure client instance
21
+ # @return [Azure::Blob::BlobService]
22
+ def blobs(options = {})
23
+ @blobs ||= Azure::Blob::BlobService.new(default_client(options))
24
+ end
25
+
26
+ # Azure Queue service configured for this Azure client instance
27
+ # @return [Azure::Queue::QueueService]
28
+ def queues(options = {})
29
+ @queues ||= Azure::Queue::QueueService.new(default_client(options))
30
+ end
31
+
32
+ # Azure Table service configured for this Azure client instance
33
+ # @return [Azure::Table::TableService]
34
+ def tables(options = {})
35
+ @tables ||= Azure::Table::TableService.new(default_client(options))
36
+ end
37
+
38
+ # Azure Service Bus service configured for this Azure client instance
39
+ # @return [Azure::ServiceBus::ServiceBusService]
40
+ def service_bus(options = {})
41
+ @sb ||= Azure::ServiceBus::ServiceBusService.new(service_bus_host, default_client(options))
42
+ end
43
+
44
+ # Azure Virtual Image management service configured for this Azure client instance
45
+ # @return [Azure::VirtualMachineImageManagement::VirtualMachineImageManagementService]
46
+ def vm_image_management(options = {})
47
+ @vm_image_mgmt ||= Azure::VirtualMachineImageManagement::VirtualMachineImageManagementService.new(default_client(options))
48
+ end
49
+
50
+ # Azure Virtual Machine disk management service configured for this Azure client instance
51
+ # @return [Azure::VirtualMachineImageManagement::VirtualMachineDiskManagementService]
52
+ def vm_disk_management(options = {})
53
+ @vm_disk_mgmt ||= Azure::VirtualMachineImageManagement::VirtualMachineDiskManagementService.new(default_client(options))
54
+ end
55
+
56
+ # Azure Virtual Machine management service configured for this Azure client instance
57
+ # @return [Azure::VirtualMachineManagement::VirtualMachineManagementService]
58
+ def vm_management(options = {})
59
+ @vm_mgmt ||= Azure::VirtualMachineManagement::VirtualMachineManagementService.new(default_client(options))
60
+ end
61
+
62
+ # Azure SQL Database management service configured for this Azure client instance
63
+ # @return [Azure::SqlDatabaseManagement::SqlDatabaseManagementService]
64
+ def sql_database_management(options = {})
65
+ @sql_mgmt ||= Azure::SqlDatabaseManagement::SqlDatabaseManagementService.new(default_client(options))
66
+ end
67
+
68
+ # Azure Network management service configured for this Azure client instance
69
+ # @return [Azure::VirtualNetworkManagement::VirtualNetworkManagementService]
70
+ def network_management(options = {})
71
+ @network_mgmt ||= Azure::VirtualNetworkManagement::VirtualNetworkManagementService.new(default_client(options))
72
+ end
73
+
74
+ # Azure Cloud Service management service configured for this Azure client instance
75
+ # @return [Azure::CloudServiceManagement::CloudServiceManagementService]
76
+ def cloud_service_management(options = {})
77
+ @cs_mgmt ||= Azure::CloudServiceManagement::CloudServiceManagementService.new(default_client(options))
78
+ end
79
+
80
+ # Azure Storage management service configured for this Azure client instance
81
+ # @return [Azure::StorageManagement::StorageManagementService]
82
+ def storage_management(options = {})
83
+ @store_mgmt ||= Azure::StorageManagement::StorageManagementService.new(default_client(options))
84
+ end
85
+
86
+ # Azure Generic management service configured for this Azure client instance
87
+ # @return [Azure::BaseManagement::BaseManagementService]
88
+ def base_management(options = {})
89
+ @base_mgmt ||= Azure::BaseManagement::BaseManagementService.new(default_client(options))
90
+ end
91
+
92
+ private
93
+
94
+ def default_client(opts)
95
+ {client: self}.merge(opts || {})
96
+ end
97
+ end
98
+ end
@@ -19,10 +19,6 @@ module Azure
19
19
  class CloudServiceManagementService < BaseManagement::BaseManagementService
20
20
  include Azure::Core::Utility
21
21
 
22
- def initialize
23
- super()
24
- end
25
-
26
22
  # Public: Creates a new cloud service in Microsoft Azure.
27
23
  #
28
24
  # ==== Attributes
@@ -56,7 +52,7 @@ module Azure
56
52
  Azure::Loggerx.info "Creating cloud service #{name}."
57
53
  request_path = '/services/hostedservices'
58
54
  body = Serialization.cloud_services_to_xml(name, options)
59
- request = BaseManagement::ManagementHttpRequest.new(:post, request_path, body)
55
+ request = client.management_request(:post, request_path, body)
60
56
  request.call
61
57
  end
62
58
  end
@@ -66,7 +62,7 @@ module Azure
66
62
  # Returns an array of Azure::CloudServiceManagement::CloudService objects
67
63
  def list_cloud_services
68
64
  request_path = '/services/hostedservices'
69
- request = BaseManagement::ManagementHttpRequest.new(:get, request_path, nil)
65
+ request = client.management_request(:get, request_path)
70
66
  response = request.call
71
67
  Serialization.cloud_services_from_xml(response)
72
68
  end
@@ -86,7 +82,7 @@ module Azure
86
82
 
87
83
  def get_cloud_service_properties(name)
88
84
  request_path = "/services/hostedservices/#{name}?embed-detail=true"
89
- request = BaseManagement::ManagementHttpRequest.new(:get, request_path)
85
+ request = client.management_request(:get, request_path)
90
86
  response = request.call
91
87
  Serialization.cloud_services_from_xml(response).first
92
88
  end
@@ -100,7 +96,7 @@ module Azure
100
96
  # Returns: None
101
97
  def delete_cloud_service(cloud_service_name)
102
98
  request_path= "/services/hostedservices/#{cloud_service_name}"
103
- request = BaseManagement::ManagementHttpRequest.new(:delete, request_path)
99
+ request = client.management_request(:delete, request_path)
104
100
  Azure::Loggerx.info "Deleting cloud service #{cloud_service_name}. \n"
105
101
  request.call
106
102
  end
@@ -119,7 +115,7 @@ module Azure
119
115
  def delete_cloud_service_deployment(cloud_service_name, slot='production')
120
116
  slot = 'production' unless slot
121
117
  request_path= "/services/hostedservices/#{cloud_service_name}/deploymentslots/#{slot}"
122
- request = BaseManagement::ManagementHttpRequest.new(:delete, request_path)
118
+ request = client.management_request(:delete, request_path)
123
119
  Azure::Loggerx.info "Deleting deployment of cloud service \"#{cloud_service_name}\" ..."
124
120
  request.call
125
121
  end
@@ -129,9 +125,11 @@ module Azure
129
125
  request_path= "/services/hostedservices/#{cloud_service_name}/certificates"
130
126
  body = Serialization.add_certificate_to_xml(data)
131
127
  Azure::Loggerx.info "Uploading certificate to cloud service #{cloud_service_name}..."
132
- request = BaseManagement::ManagementHttpRequest.new(:post, request_path, body)
128
+ request = client.management_request(:post, request_path, body)
133
129
  request.call
134
130
  end
135
131
  end
136
132
  end
137
133
  end
134
+
135
+ Azure::CloudServiceManagementService = Azure::CloudServiceManagement::CloudServiceManagementService
@@ -0,0 +1,290 @@
1
+ #-------------------------------------------------------------------------
2
+ # # Copyright (c) Microsoft and contributors. All rights reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ #--------------------------------------------------------------------------
15
+
16
+ module Azure
17
+ # The Azure::Configurable module provides basic configuration for Azure activities.
18
+ module Configurable
19
+
20
+ # @!attribute [w] storage_access_key
21
+ # @return [String] Azure Storage access key.
22
+ # @!attribute storage_account_name
23
+ # @return [String] Azure Storage account name
24
+ # @!attribute sb_access_key
25
+ # @return [String] Azure Service Bus access key
26
+ # @!attribute sb_sas_key
27
+ # @return [String] Azure Service Bus Shared Access Signature key
28
+ # @!attribute sb_sas_key_name
29
+ # @return [String] Azure Service Bus Shared Access Signature key name
30
+ # @!attribute sb_namespace
31
+ # @return [String] Azure Service Bus namespace
32
+ # @!attribute sb_issuer
33
+ # @return [String] Azure Service Bus issuer
34
+ # @!attribute ca_file
35
+ # @return [String] Location of the Certificate Authority bundle to be used for HTTPS
36
+ # @!attribute management_certificate
37
+ # @return [String|File] Azure Service Management certificate (pfx or pem)
38
+ # @!attribute subscription_id
39
+ # @return [String] Azure Subscription ID
40
+ # @!attribute http_private_key
41
+ # @return [String] Private key used for HTTPS certificate based authentication (derived from the management cert)
42
+ # @!attribute http_certificate_key
43
+ # @return [String] Public key used for HTTPS certificate based authentication (derived from the management cert)
44
+ # @!attribute sql_database_management_endpoint
45
+ # @return [String] Azure SQL database management endpoint. default: https://management.core.windows.net:8443/
46
+ # @!attribute storage_blob_host
47
+ # @return [String] Set the host for the Blob service. Only set this if you want
48
+ # something custom (like, for example, to point this to a LocalStorage
49
+ # emulator). This should be the complete host, including http:// at the
50
+ # start. When using the emulator, make sure to include your account name at
51
+ # the end.
52
+ # @!attribute storage_table_host
53
+ # @return [String] Get the host for this service. If you set something using #storage_table_host=,
54
+ # then we use that. Else we default to Azure's default hosts, based
55
+ # on your account name.
56
+ # @!attribute storage_queue_host
57
+ # @return [String] Set the host for the Queue service. Only set this if you want
58
+ # something custom (like, for example, to point this to a LocalStorage
59
+ # emulator). This should be the complete host, including http:// at the
60
+ # start. When using the emulator, make sure to include your account name at
61
+ # the end.
62
+ # @!attribute management_endpoint
63
+ # @return [String] Azure Service Management Endpoint. default: https://management.core.windows.net
64
+
65
+ attr_accessor :storage_access_key,
66
+ :storage_account_name,
67
+ :sb_access_key,
68
+ :sb_namespace,
69
+ :sb_sas_key,
70
+ :sb_sas_key_name,
71
+ :sb_issuer,
72
+ :ca_file,
73
+ :subscription_id
74
+
75
+ attr_reader :http_private_key,
76
+ :http_certificate_key,
77
+ :acs_host,
78
+ :service_bus_host
79
+
80
+ attr_writer :storage_table_host,
81
+ :storage_blob_host,
82
+ :storage_queue_host,
83
+ :sql_database_management_endpoint,
84
+ :management_endpoint
85
+
86
+ class << self
87
+
88
+ # List of configurable keys for {Azure::Client}
89
+ # @return [Array] of option keys
90
+ def keys
91
+ @keys ||= [
92
+ :storage_access_key,
93
+ :storage_account_name,
94
+ :sb_access_key,
95
+ :sb_sas_key,
96
+ :sb_sas_key_name,
97
+ :ca_file,
98
+ :sb_namespace,
99
+ :management_certificate,
100
+ :subscription_id,
101
+ :sql_database_management_endpoint,
102
+ :sb_issuer,
103
+ :storage_table_host,
104
+ :storage_blob_host,
105
+ :storage_queue_host,
106
+ :management_endpoint
107
+ ]
108
+ end
109
+ end
110
+
111
+ # Set configuration options using a block
112
+ def configure
113
+ yield self
114
+ end
115
+
116
+ # Reset configuration options to default values
117
+ def reset!(options = {})
118
+ Azure::Configurable.keys.each do |key|
119
+ value = if self == Azure
120
+ Azure::Default.options[key]
121
+ else
122
+ Azure.send(key)
123
+ end
124
+
125
+ if key == :management_certificate
126
+ @certificate_key = nil
127
+ @private_key = nil
128
+ send(:"#{key.to_s + '='}", value)
129
+ else
130
+ instance_variable_set(:"@#{key}", options.fetch(key, value))
131
+ end
132
+ end
133
+ self.send(:reset_agents!) if self.respond_to?(:reset_agents!)
134
+ self
135
+ end
136
+
137
+ alias setup reset!
138
+
139
+ def management_certificate
140
+ @management_certificate
141
+ end
142
+
143
+ # Set the management certificate via string or file (populates #http_private_key and #http_certificate_key)
144
+ # @param [String|File] the string or file representing the .pem or .pfx
145
+ def management_certificate=(cert_string_or_file)
146
+ self.send(:reset_agents!) if self.respond_to?(:reset_agents!)
147
+ if cert_string_or_file.nil?
148
+ @certificate_key = @private_key = @management_certificate = nil
149
+ else
150
+
151
+ # the pfx may have null chars which will raise an exception in File.file?
152
+ invalid_file_chars = cert_string_or_file.to_s =~ /\x00/
153
+
154
+ # validate only if input is file path
155
+ if !invalid_file_chars && File.file?(cert_string_or_file) && File.extname(cert_string_or_file).downcase =~ /(pem|pfx)$/
156
+ error_message = "Could not read from file '#{cert_string_or_file}'."
157
+ raise ArgumentError.new(error_message) unless test('r', cert_string_or_file)
158
+ end
159
+
160
+ # get the string representation of cert
161
+ cert_file = if !invalid_file_chars && File.file?(cert_string_or_file)
162
+ read_cert_from_file(cert_string_or_file)
163
+ else
164
+ cert_string_or_file
165
+ end
166
+
167
+ begin
168
+ if cert_file =~ /-----BEGIN CERTIFICATE-----/
169
+ # Parse pem content
170
+ @certificate_key = OpenSSL::X509::Certificate.new(cert_file)
171
+ @private_key = OpenSSL::PKey::RSA.new(cert_file)
172
+ else
173
+ # Parse pfx content
174
+ cert_content = OpenSSL::PKCS12.new(cert_file)
175
+ @certificate_key = OpenSSL::X509::Certificate.new(
176
+ cert_content.certificate.to_pem
177
+ )
178
+ @private_key = OpenSSL::PKey::RSA.new(cert_content.key.to_pem)
179
+ end
180
+ @management_certificate = cert_file
181
+ rescue OpenSSL::OpenSSLError => e
182
+ @certificate_key = nil
183
+ @private_key = nil
184
+ raise ArgumentError.new("Management certificate not valid. Error: #{e.message}")
185
+ end
186
+ end
187
+ end
188
+
189
+ # Private side of the management certificate
190
+ # @returns [OpenSSL::X509::Certificate]
191
+ def http_private_key
192
+ @private_key
193
+ end
194
+
195
+ # Public side of the management certificate
196
+ # @returns [OpenSSL::PKey::RSA]
197
+ def http_certificate_key
198
+ @certificate_key
199
+ end
200
+
201
+ def management_endpoint
202
+ normalize_endpoint do
203
+ if URI(@management_endpoint).scheme.nil?
204
+ "https://#{@management_endpoint}"
205
+ else
206
+ @management_endpoint
207
+ end
208
+ end
209
+ end
210
+
211
+ def sql_database_management_endpoint
212
+ normalize_endpoint do
213
+ if URI(@sql_database_management_endpoint).scheme.nil?
214
+ "https://#{@sql_database_management_endpoint}:8443"
215
+ else
216
+ @sql_database_management_endpoint
217
+ end
218
+ end
219
+ end
220
+
221
+ # Storage queue host
222
+ # @return [String]
223
+ def storage_queue_host
224
+ @storage_queue_host || default_host(:queue)
225
+ end
226
+
227
+ # Storage blob host
228
+ # @return [String]
229
+ def storage_blob_host
230
+ @storage_blob_host || default_host(:blob)
231
+ end
232
+
233
+ # Storage table host
234
+ # @return [String]
235
+ def storage_table_host
236
+ @storage_table_host || default_host(:table)
237
+ end
238
+
239
+ # Get the host for the ACS service.
240
+ # @return [String]
241
+ def acs_host
242
+ if sb_namespace.empty?
243
+ nil
244
+ else
245
+ "https://#{sb_namespace}-sb.accesscontrol.windows.net"
246
+ end
247
+ end
248
+
249
+ # Get the host for Service Bus based on the Service Bus Namespace.
250
+ # @return [String]
251
+ def service_bus_host
252
+ if sb_namespace.empty?
253
+ nil
254
+ else
255
+ "https://#{sb_namespace}.servicebus.windows.net"
256
+ end
257
+ end
258
+
259
+ def config
260
+ self
261
+ end
262
+
263
+ private
264
+
265
+ def default_host(service)
266
+ "https://#{storage_account_name}.#{service}.core.windows.net"
267
+ end
268
+
269
+ def read_cert_from_file(cert_file_path)
270
+ if File.extname(cert_file_path).downcase == '.pem'
271
+ File.read(cert_file_path)
272
+ else
273
+ File.binread(cert_file_path)
274
+ end
275
+ end
276
+
277
+ def normalize_endpoint
278
+ if block_given?
279
+ File.join(yield, '')
280
+ else
281
+ nil
282
+ end
283
+ end
284
+
285
+ def options
286
+ Hash[Azure::Configurable.keys.map { |key| [key, instance_variable_get(:"@#{key}")] }]
287
+ end
288
+
289
+ end
290
+ end