bits_service_client 0.2.2.pre.8 → 0.2.2.pre.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eb0bcb367d39f853361a544498f59409ed01da87
4
- data.tar.gz: 721ba2b9da42b314e9bb9fed090563225fb34a64
3
+ metadata.gz: 8ffe244bb3268bff64c983b8c9bb706e2dc7b134
4
+ data.tar.gz: 9c5dced93c1563f94ee1da10106e71761b52fd38
5
5
  SHA512:
6
- metadata.gz: fc71a774e1faf08210fb86e3699f2a39589512dfbcdd3b9877c4cf951d0082d8f90119b07b69a699747c48f53364c3e4fea5bc38b309949149dd77bc2911f8f7
7
- data.tar.gz: 89528ee1fde851dc083866810e0fdf2464d818794e50432cebada5594d8662a1aae08de312f46c495e1e87786001d07b90ddc539c2d88e2fe03b831c04a42e98
6
+ metadata.gz: 7556eee77c0e6b4b813b677306f59387a718722716f6e3725e69193fbe2a3f6bcc9a7c8577b25bc821473f15bea7c4caf9525e40337557aac9932ab9307811c4
7
+ data.tar.gz: 6f4e47a725c021a74012627bbeb8fdb44368681f5289c36ebe245e974d8e72a231f4495c9b0e0f73dd41081aee9bfb43241c8d284b5e68636c69c7a2d44f7e86
@@ -16,20 +16,9 @@ module BitsService
16
16
  raise ResourceTypeNotPresent.new('Must specify resource type') unless resource_type
17
17
  @resource_type = resource_type
18
18
  @vcap_request_id = vcap_request_id
19
- @private_http_client = LoggingHttpClient.new(
20
- Net::HTTP.new(@private_endpoint.host, @private_endpoint.port).tap do |c|
21
- c.read_timeout = request_timeout_in_seconds
22
- c.use_ssl = true if @private_endpoint.scheme.start_with?('https')
23
- c.verify_mode = OpenSSL::SSL::VERIFY_PEER if @private_endpoint.scheme.start_with?('https')
24
- end
25
- )
26
- @public_http_client = LoggingHttpClient.new(
27
- Net::HTTP.new(@public_endpoint.host, @public_endpoint.port).tap do |c|
28
- c.read_timeout = request_timeout_in_seconds
29
- c.use_ssl = true if @public_endpoint.scheme.start_with?('https')
30
- c.verify_mode = OpenSSL::SSL::VERIFY_PEER if @public_endpoint.scheme.start_with?('https')
31
- end
32
- )
19
+
20
+ @private_http_client = create_logging_http_client(@private_endpoint, bits_service_options, request_timeout_in_seconds)
21
+ @public_http_client = create_logging_http_client(@public_endpoint, bits_service_options, request_timeout_in_seconds)
33
22
  end
34
23
 
35
24
  def local?
@@ -132,6 +121,25 @@ module BitsService
132
121
 
133
122
  attr_reader :resource_type
134
123
 
124
+ def create_logging_http_client(endpoint, bits_service_options, request_timeout_in_seconds)
125
+ LoggingHttpClient.new(
126
+ Net::HTTP.new(endpoint.host, endpoint.port).tap do |c|
127
+ c.read_timeout = request_timeout_in_seconds
128
+ enable_ssl(c, validated(bits_service_options, :ca_cert_path)) if endpoint.scheme == 'https'
129
+ end
130
+ )
131
+ end
132
+
133
+ def enable_ssl(http_client, ca_cert_path)
134
+ cert_store = OpenSSL::X509::Store.new
135
+ cert_store.set_default_paths
136
+ cert_store.add_file ca_cert_path
137
+
138
+ http_client.use_ssl = true
139
+ http_client.verify_mode = OpenSSL::SSL::VERIFY_PEER
140
+ http_client.cert_store = cert_store
141
+ end
142
+
135
143
  def generate_private_url(guid)
136
144
  path = resource_path(guid)
137
145
 
@@ -1,11 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
  module BitsService
3
3
  class ResourcePool
4
- def initialize(endpoint:, request_timeout_in_seconds:, vcap_request_id: '')
4
+ def initialize(endpoint:, request_timeout_in_seconds:, vcap_request_id: '', ca_cert_path: nil)
5
5
  @endpoint = URI.parse(endpoint)
6
6
  @request_timeout_in_seconds = request_timeout_in_seconds
7
7
  @vcap_request_id = vcap_request_id
8
8
  @logger = Steno.logger('cc.bits_service_client')
9
+ @ca_cert_path = ca_cert_path
9
10
  end
10
11
 
11
12
  def matches(resources_json)
@@ -94,7 +95,20 @@ module BitsService
94
95
  end
95
96
 
96
97
  def http_client
97
- @http_client ||= Net::HTTP.new(endpoint.host, endpoint.port).tap { |c| c.read_timeout = @request_timeout_in_seconds }
98
+ @http_client ||= Net::HTTP.new(endpoint.host, endpoint.port).tap do |c|
99
+ c.read_timeout = @request_timeout_in_seconds
100
+ enable_ssl(c, @ca_cert_path) if endpoint.scheme == 'https'
101
+ end
102
+ end
103
+
104
+ def enable_ssl(http_client, ca_cert_path)
105
+ cert_store = OpenSSL::X509::Store.new
106
+ cert_store.set_default_paths
107
+ cert_store.add_file ca_cert_path if ca_cert_path
108
+
109
+ http_client.use_ssl = true
110
+ http_client.verify_mode = OpenSSL::SSL::VERIFY_PEER
111
+ http_client.cert_store = cert_store
98
112
  end
99
113
  end
100
114
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module BitsServiceClient
3
- VERSION = '0.2.2.pre.8'
3
+ VERSION = '0.2.2.pre.9'
4
4
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  require 'json'
3
3
  require 'net/http/post/multipart'
4
+ require 'openssl'
4
5
 
5
6
  require 'bits_service_client/version'
6
7
  require 'bits_service_client/blob'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bits_service_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2.pre.8
4
+ version: 0.2.2.pre.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rizwan Reza
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2017-10-09 00:00:00.000000000 Z
14
+ date: 2017-10-10 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: steno