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,7 +12,7 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
  #--------------------------------------------------------------------------
15
- require "azure/core/http/http_error"
15
+ require 'azure/core/http/http_error'
16
16
 
17
17
  module Azure
18
18
  module Core
@@ -23,7 +23,7 @@ module Azure
23
23
  # Public: Initialize a new response.
24
24
  #
25
25
  # http_response - A Net::HTTPResponse.
26
- def initialize(http_response, uri="")
26
+ def initialize(http_response, uri='')
27
27
  @http_response = http_response
28
28
  @uri = uri
29
29
  end
@@ -37,18 +37,11 @@ module Azure
37
37
  @http_response.body
38
38
  end
39
39
 
40
- # Public: Get the response status message.
41
- #
42
- # Returns a String.
43
- def message
44
- @http_response.message
45
- end
46
-
47
40
  # Public: Get the response status code.
48
41
  #
49
42
  # Returns a Fixnum.
50
43
  def status_code
51
- @http_response.code.to_i
44
+ @http_response.status
52
45
  end
53
46
 
54
47
  # Public: Check if this response was successful. A request is considered
@@ -56,14 +49,14 @@ module Azure
56
49
  #
57
50
  # Returns nil|false.
58
51
  def success?
59
- (200..399).include? status_code
52
+ @http_response.success?
60
53
  end
61
54
 
62
55
  # Public: Get all the response headers as a Hash.
63
56
  #
64
57
  # Returns a Hash.
65
58
  def headers
66
- @headers ||= HeaderHash.new(@http_response.to_hash)
59
+ @http_response.headers
67
60
  end
68
61
 
69
62
  # Public: Get an error that wraps this HTTP response, as long as this
@@ -77,56 +70,19 @@ module Azure
77
70
 
78
71
  alias_method :error, :exception
79
72
 
80
- # Since HTTP Headers are case insensitive, this class will
81
- # normalize them to lowercase. This also wraps Net::HTTPResponse
82
- # headers by returning their values as strings, not arrays, by selecting
83
- # the first value from the array.
84
- class HeaderHash < Hash
85
- # Public: Initialize the header hash.
86
- #
87
- # headers - A Hash of headers as returned from Net::HTTPResponse#to_hash.
88
- def initialize(headers)
89
- super
90
- headers = Hash[headers.map { |k,v| [k.downcase.freeze, v.first.freeze] }]
91
- replace(headers)
92
- end
93
-
94
- # Public: Get a header's value or nil if it's not present.
95
- #
96
- # header - A string with the header's name.
97
- #
98
- # Returns a String or nil.
99
- def [](header)
100
- super(header.downcase)
101
- end
102
-
103
- # Public: Get a header's value or a specified default.
104
- #
105
- # header - A string with the header's name.
106
- # default - A default value.
107
- #
108
- # Yields a block where you can specify the default value.
109
- #
110
- # Returns a String, or the specified default.
111
- def fetch(header, *default, &block)
112
- if (args = default.size) > 1
113
- raise ArgumentError, "wrong number of arguments(#{args + 1} for 2)"
114
- end
115
-
116
- super(header.downcase, *default, &block)
117
- end
118
- end
119
-
73
+ # TODO: This needs to be deleted and HttpError needs to be refactored to not rely on HttpResponse.
74
+ # The dependency on knowing the internal structure of HttpResponse breaks good design principles.
75
+ # The only reason this class exists is because the HttpError parses the HttpResponse to produce an error msg.
120
76
  class MockResponse
121
77
  def initialize(code, body, headers)
122
- @code = code.to_s
78
+ @status = code
123
79
  @body = body
124
80
  @headers = headers
125
81
  @headers.each { |k,v|
126
- @headers[k] = [v] unless v.respond_to? first
127
- }
82
+ @headers[k] = [v] unless v.respond_to? first
83
+ }
128
84
  end
129
- attr_accessor :code
85
+ attr_accessor :status
130
86
  attr_accessor :body
131
87
  attr_accessor :headers
132
88
 
@@ -12,7 +12,7 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
  #--------------------------------------------------------------------------
15
- require "azure/core/http/http_filter"
15
+ require 'azure/core/http/http_filter'
16
16
 
17
17
  module Azure
18
18
  module Core
@@ -24,11 +24,10 @@ module Azure
24
24
  end
25
25
 
26
26
  def call(req, _next)
27
- signature = @signer.sign(req.method, req.uri, req.headers)
28
- req.headers["Authorization"] = "#{@signer.name} #{signature}"
27
+ @signer.sign_request(req)
29
28
  _next.call
30
29
  end
31
30
  end
32
31
  end
33
32
  end
34
- end
33
+ end
@@ -21,36 +21,19 @@ module Azure
21
21
 
22
22
  # Create a new instance of the Service
23
23
  #
24
- # host - String. The hostname. (optional, Default empty)
25
- def initialize(host='')
24
+ # @param host [String] The hostname. (optional, Default empty)
25
+ # @param options [Hash] options including {:client} (optional, Default {})
26
+ def initialize(host='', options = {})
26
27
  @host = host
28
+ @client = options[:client] || Azure
27
29
  end
28
30
 
29
- attr_accessor :host
30
-
31
- def call(method, uri, body=nil, headers=nil)
32
- if headers && !body.nil?
33
- if headers['Content-Encoding'].nil?
34
- headers['Content-Encoding'] = body.encoding.to_s
35
- else
36
- body.force_encoding(headers['Content-Encoding'])
37
- end
38
- end
39
-
40
- request = Core::Http::HttpRequest.new(method, uri, body)
41
- request.headers.merge!(headers) if headers
42
-
43
- request.headers['connection'] = 'keep-alive' if request.respond_to? :headers
31
+ attr_accessor :host, :client
44
32
 
33
+ def call(method, uri, body=nil, headers={})
34
+ request = Core::Http::HttpRequest.new(method, uri, body: body, headers: headers, client: @client)
45
35
  yield request if block_given?
46
-
47
- response = request.call
48
-
49
- if !response.nil? && !response.body.nil? && response.headers['content-encoding']
50
- response.body.force_encoding(response.headers['content-encoding'])
51
- end
52
-
53
- response
36
+ request.call
54
37
  end
55
38
 
56
39
  def generate_uri(path='', query={})
@@ -23,11 +23,13 @@ module Azure
23
23
 
24
24
  # Create a new instance of the SignedService
25
25
  #
26
- # signer - Azure::Core::Auth::Signer. An implementation of Signer used for signing requests. (optional, Default=Azure::Core::Auth::SharedKey.new)
27
- # account_name - String. The account name (optional, Default=Azure.config.storage_account_name)
28
- def initialize(signer=Core::Auth::SharedKey.new, account_name=Azure.config.storage_account_name)
29
- super()
30
- @account_name = account_name
26
+ # @param signer [Azure::Core::Auth::Signer]. An implementation of Signer used for signing requests. (optional, Default=Azure::Core::Auth::SharedKey.new)
27
+ # @param account_name [String] The account name (optional, Default=Azure.config.storage_account_name)
28
+ # @param options [Hash] options
29
+ def initialize(signer=nil, account_name=nil, options={})
30
+ super('', options)
31
+ signer ||= Core::Auth::SharedKey.new(client.storage_account_name, client.storage_access_key)
32
+ @account_name = account_name || client.storage_account_name
31
33
  @signer = signer
32
34
  filters.unshift Core::Http::SignerFilter.new(signer) if signer
33
35
  end
@@ -94,38 +94,75 @@ module Azure
94
94
  cert
95
95
  end
96
96
 
97
+ def initialize_external_logger(logger)
98
+ Loggerx.initialize_external_logger(logger)
99
+ end
97
100
  end
98
101
 
99
102
  # Logger
100
103
  module Logger
101
104
  class << self
105
+ attr_accessor :logger
106
+
102
107
  def info(msg)
103
- puts msg.bold.white
108
+ if logger.nil?
109
+ puts msg.bold.white
110
+ else
111
+ logger.info(msg)
112
+ end
104
113
  end
105
114
 
106
115
  def error_with_exit(msg)
107
- puts msg.bold.red
116
+ if logger.nil?
117
+ puts msg.bold.red
118
+ else
119
+ logger.error(msg)
120
+ end
121
+
108
122
  raise msg.bold.red
109
123
  end
110
124
 
111
125
  def warn(msg)
112
- puts msg.yellow
126
+ if logger.nil?
127
+ puts msg.yellow
128
+ else
129
+ logger.warn(msg)
130
+ end
131
+
113
132
  msg
114
133
  end
115
134
 
116
135
  def error(msg)
117
- puts msg.bold.red
136
+ if logger.nil?
137
+ puts msg.bold.red
138
+ else
139
+ logger.error(msg)
140
+ end
141
+
118
142
  msg
119
143
  end
120
144
 
121
145
  def exception_message(msg)
122
- print msg.bold.red
146
+ if logger.nil?
147
+ puts msg.bold.red
148
+ else
149
+ logger.warn(msg)
150
+ end
151
+
123
152
  raise msg.bold.red
124
153
  end
125
154
 
126
155
  def success(msg)
127
156
  msg_with_new_line = msg + "\n"
128
- print msg_with_new_line.green
157
+ if logger.nil?
158
+ print msg_with_new_line.green
159
+ else
160
+ logger.info(msg)
161
+ end
162
+ end
163
+
164
+ def initialize_external_logger(logger)
165
+ @logger = logger
129
166
  end
130
167
  end
131
168
  end
@@ -203,3 +240,5 @@ class IPAddr
203
240
  end
204
241
  end
205
242
  end
243
+
244
+ Azure::Loggerx = Azure::Core::Logger
@@ -0,0 +1,126 @@
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
+
18
+ # Default configuration options for {Client}
19
+ module Default
20
+ # Default API endpoint
21
+ SERVICE_MANAGEMENT_ENDPOINT = 'https://management.core.windows.net'.freeze
22
+
23
+ # Default User Agent header string
24
+ USER_AGENT = "Azure-SDK-For-Ruby/#{Azure::Version}".freeze
25
+
26
+ class << self
27
+
28
+ # Configuration options
29
+ # @return [Hash]
30
+ def options
31
+ Hash[Azure::Configurable.keys.map{|key| [key, send(key)]}]
32
+ end
33
+
34
+ # Default storage access key
35
+ # @return [String]
36
+ def storage_access_key
37
+ ENV['AZURE_STORAGE_ACCESS_KEY']
38
+ end
39
+
40
+ # Default storage account name
41
+ # @return [String]
42
+ def storage_account_name
43
+ ENV['AZURE_STORAGE_ACCOUNT']
44
+ end
45
+
46
+ # Default storage table host
47
+ # @return [String]
48
+ def storage_table_host
49
+ ENV['AZURE_STORAGE_TABLE_HOST']
50
+ end
51
+
52
+ # Default storage blob host
53
+ # @return [String]
54
+ def storage_blob_host
55
+ ENV['AZURE_STORAGE_BLOB_HOST']
56
+ end
57
+
58
+ # Default storage queue host
59
+ # @return [String]
60
+ def storage_queue_host
61
+ ENV['AZURE_STORAGE_QUEUE_HOST']
62
+ end
63
+
64
+ # Default service bus namespace
65
+ # @return [String]
66
+ def sb_namespace
67
+ ENV['AZURE_SERVICEBUS_NAMESPACE']
68
+ end
69
+
70
+ # Default service bus access key
71
+ # @return [String]
72
+ def sb_access_key
73
+ ENV['AZURE_SERVICEBUS_ACCESS_KEY']
74
+ end
75
+
76
+ # Default service bus Shared Access Policy key
77
+ # @return [String]
78
+ def sb_sas_key
79
+ ENV['AZURE_SERVICEBUS_SAS_KEY']
80
+ end
81
+
82
+ # Default service bus Shared Access Policy key name
83
+ # @return [String]
84
+ def sb_sas_key_name
85
+ ENV['AZURE_SERVICEBUS_SAS_KEY_NAME']
86
+ end
87
+
88
+ # Default service bus issuer
89
+ # @return [String]
90
+ def sb_issuer
91
+ ENV['AZURE_SERVICEBUS_ISSUER'] || 'owner'
92
+ end
93
+
94
+ # Default management certificate to use for management activeities
95
+ # @return [String]
96
+ def management_certificate
97
+ ENV['AZURE_MANAGEMENT_CERTIFICATE']
98
+ end
99
+
100
+ # Default subscription to use for management activities
101
+ # @return [String]
102
+ def subscription_id
103
+ ENV['AZURE_SUBSCRIPTION_ID']
104
+ end
105
+
106
+ # Default Azure management endpoint
107
+ # @return [String]
108
+ def management_endpoint
109
+ ENV['AZURE_MANAGEMENT_ENDPOINT'] || (SERVICE_MANAGEMENT_ENDPOINT + '/')
110
+ end
111
+
112
+ # Default SQL database management endpoint
113
+ # @return [String]
114
+ def sql_database_management_endpoint
115
+ ENV['AZURE_SQL_DATABASE_MANAGEMENT_ENDPOINT'] || "#{SERVICE_MANAGEMENT_ENDPOINT}:8443/"
116
+ end
117
+
118
+ # Default Certificate Authority bundle to be used for https
119
+ # @return [String]
120
+ def ca_file
121
+ ENV['SSL_CERT_FILE']
122
+ end
123
+
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,85 @@
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
+ module HttpClient
18
+
19
+ # Creates a new management request for the current configuration
20
+ # @param method [Symbol] the HTTP method
21
+ # @param path [URI] the path to the management resource
22
+ # @param options_or_body [Hash|Body] options which can include body
23
+ def management_request(method, path, options_or_body = {})
24
+ options_or_body ||= {}
25
+ options = if options_or_body.is_a?(Hash)
26
+ options_or_body
27
+ else
28
+ {body: options_or_body}
29
+ end
30
+ BaseManagement::ManagementHttpRequest.new(method, path, {client: self}.merge(options))
31
+ end
32
+
33
+ # Creates a new management request for the current configuration
34
+ # @param method [Symbol] the HTTP method
35
+ # @param path [URI] the path to the management resource
36
+ # @param options_or_body [Hash|Body] options which can include body
37
+ def sql_management_request(method, path, options_or_body = {})
38
+ options_or_body ||= {}
39
+ options = if options_or_body.is_a?(Hash)
40
+ options_or_body
41
+ else
42
+ {body: options_or_body}
43
+ end
44
+ puts [method, path, options]
45
+ BaseManagement::SqlManagementHttpRequest.new(method, path, {client: self}.merge(options))
46
+ end
47
+
48
+ # Returns the http agent based on uri
49
+ # @param uri [URI|String] the base uri (scheme, host, port) of the http endpoint
50
+ # @return [Net::HTTP] http agent for a given uri
51
+ def agents(uri)
52
+ uri = URI.parse(uri) if uri.is_a?(String)
53
+ key = uri.scheme.to_s + uri.host.to_s + uri.port.to_s
54
+ @agents ||= {}
55
+ unless @agents.key?(key)
56
+ @agents[key] = build_http(uri)
57
+ end
58
+ @agents[key]
59
+ end
60
+
61
+ # Empties all the http agents
62
+ def reset_agents!
63
+ @agents = nil
64
+ end
65
+
66
+ private
67
+
68
+ def build_http(uri)
69
+ ssl_options = {}
70
+ if uri.scheme.downcase == 'https'
71
+ ssl_options[:ca_file] = self.ca_file if self.ca_file
72
+ ssl_options[:verify] = true
73
+ end
74
+
75
+ proxy_options = if ENV['HTTP_PROXY'] || ENV['HTTPS_PROXY']
76
+ ENV['HTTP_PROXY'] ? URI::parse(ENV['HTTP_PROXY']) : URI::parse(ENV['HTTPS_PROXY'])
77
+ end || nil
78
+
79
+ Faraday.new(uri, ssl: ssl_options, proxy: proxy_options) do |conn|
80
+ conn.use FaradayMiddleware::FollowRedirects
81
+ conn.adapter Faraday.default_adapter
82
+ end
83
+ end
84
+ end
85
+ end