bits_service_client 3.3.0 → 3.4.0.pre.1
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 +4 -4
- data/.rubocop.yml +7 -1
- data/Gemfile +1 -0
- data/Guardfile +6 -4
- data/Rakefile +1 -0
- data/bits_service_client.gemspec +5 -1
- data/lib/bits_service_client/blob.rb +3 -2
- data/lib/bits_service_client/client.rb +17 -16
- data/lib/bits_service_client/errors.rb +1 -0
- data/lib/bits_service_client/logging_http_client.rb +18 -1
- data/lib/bits_service_client/resource_pool.rb +1 -1
- data/lib/bits_service_client/version.rb +1 -1
- data/lib/bits_service_client.rb +1 -0
- metadata +61 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d7684746adb5996dafb5100c93d96a42bbeae06
|
4
|
+
data.tar.gz: e79ddcd829e6e8bb761e23b387dbd629cd3057b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8cde1d30a5f69dcc48e0a4cac67517847ae64c0a4b118afe232f15a1a04ad71e12ebd2b95e028a4f32e80e71b22b0f3addb25efdead0228990cde01c40f5309
|
7
|
+
data.tar.gz: dc17b670fd6403cd8627e943a7083ccc593c56967413d93765eea0fc4a87564a89ec21c72fec4f2716c50923c25558f8c6df2004526d33ac1af1cb02ad92e3da
|
data/.rubocop.yml
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
AllCops:
|
2
|
-
TargetRubyVersion: 2.
|
2
|
+
TargetRubyVersion: 2.4
|
3
3
|
Include:
|
4
4
|
- '**/Gemfile'
|
5
5
|
- '**/Rakefile'
|
@@ -157,3 +157,9 @@ Style/WordArray:
|
|
157
157
|
|
158
158
|
Style/ZeroLengthPredicate:
|
159
159
|
Enabled: false
|
160
|
+
|
161
|
+
Metrics/BlockLength:
|
162
|
+
Exclude:
|
163
|
+
- 'Rakefile'
|
164
|
+
- '**/*.rake'
|
165
|
+
- 'spec/**/*.rb'
|
data/Gemfile
CHANGED
data/Guardfile
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
guard :bundler do
|
2
4
|
require 'guard/bundler'
|
3
5
|
require 'guard/bundler/verify'
|
@@ -12,12 +14,12 @@ end
|
|
12
14
|
|
13
15
|
guard :rspec, cmd: 'bundle exec rspec' do
|
14
16
|
watch(%r{^spec/.+_spec\.rb$})
|
15
|
-
watch(%r{^lib/bits_service_client/(.+)\.rb$}){|m| "spec/unit/bits_service_client/#{m[1]}_spec.rb"}
|
16
|
-
watch(%r{^lib/bits_service_client/client.rb$}){|m|
|
17
|
-
watch('spec/spec_helper.rb')
|
17
|
+
watch(%r{^lib/bits_service_client/(.+)\.rb$}) { |m| "spec/unit/bits_service_client/#{m[1]}_spec.rb" }
|
18
|
+
watch(%r{^lib/bits_service_client/client.rb$}) { |m| 'spec/unit/bits_service_client/bits_service_client_spec.rb' }
|
19
|
+
watch('spec/spec_helper.rb') { 'spec' }
|
18
20
|
end
|
19
21
|
|
20
22
|
guard :rubocop do
|
21
|
-
watch(
|
23
|
+
watch(/.+\.rb$/)
|
22
24
|
watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
|
23
25
|
end
|
data/Rakefile
CHANGED
data/bits_service_client.gemspec
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
# coding: utf-8
|
2
1
|
# frozen_string_literal: true
|
2
|
+
|
3
3
|
lib = File.expand_path('../lib', __FILE__)
|
4
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
5
|
require 'bits_service_client/version'
|
@@ -18,6 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
|
19
19
|
spec.add_dependency 'activesupport'
|
20
20
|
spec.add_dependency 'steno'
|
21
|
+
spec.add_dependency 'statsd-ruby', '~> 1.4'
|
21
22
|
|
22
23
|
spec.add_development_dependency 'bundler', '~> 1.11'
|
23
24
|
spec.add_development_dependency 'multipart-post'
|
@@ -27,4 +28,7 @@ Gem::Specification.new do |spec|
|
|
27
28
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
28
29
|
spec.add_development_dependency 'rubocop'
|
29
30
|
spec.add_development_dependency 'webmock', '= 2.3.1'
|
31
|
+
spec.add_development_dependency 'sinatra'
|
32
|
+
spec.add_development_dependency 'pry'
|
33
|
+
spec.add_development_dependency 'pry-nav'
|
30
34
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module BitsService
|
3
4
|
class Blob
|
4
5
|
attr_reader :key
|
@@ -8,7 +9,7 @@ module BitsService
|
|
8
9
|
@private_http_client = private_http_client
|
9
10
|
@vcap_request_id = vcap_request_id
|
10
11
|
@username = username
|
11
|
-
@password =password
|
12
|
+
@password = password
|
12
13
|
@resource_type = resource_type
|
13
14
|
@private_endpoint = private_endpoint
|
14
15
|
end
|
@@ -26,7 +27,7 @@ module BitsService
|
|
26
27
|
end
|
27
28
|
|
28
29
|
def public_upload_url
|
29
|
-
signed_url(key, verb: 'put')+'&async=true'
|
30
|
+
signed_url(key, verb: 'put') + '&async=true'
|
30
31
|
end
|
31
32
|
|
32
33
|
def internal_download_url
|
@@ -1,15 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'active_support/inflector'
|
3
4
|
require 'bits_service_client/logging_http_client'
|
4
5
|
require 'tmpdir'
|
5
|
-
require
|
6
|
+
require 'open3'
|
6
7
|
|
7
8
|
module BitsService
|
8
9
|
class Client
|
9
10
|
ResourceTypeNotPresent = Class.new(StandardError)
|
10
11
|
ConfigurationError = Class.new(StandardError)
|
11
12
|
|
12
|
-
def initialize(bits_service_options:, resource_type:, vcap_request_id: '', request_timeout_in_seconds: 900)
|
13
|
+
def initialize(bits_service_options:, resource_type:, vcap_request_id: '', request_timeout_in_seconds: 900, request_timeout_in_seconds_fast: 10)
|
13
14
|
@username = validated(bits_service_options, :username)
|
14
15
|
@password = validated(bits_service_options, :password)
|
15
16
|
@private_endpoint = validated_http_url(bits_service_options, :private_endpoint)
|
@@ -20,6 +21,7 @@ module BitsService
|
|
20
21
|
@vcap_request_id = vcap_request_id
|
21
22
|
|
22
23
|
@private_http_client = create_logging_http_client(@private_endpoint, bits_service_options, request_timeout_in_seconds)
|
24
|
+
@private_http_client_fast_timeout = create_logging_http_client(@private_endpoint, bits_service_options, request_timeout_in_seconds_fast)
|
23
25
|
@public_http_client = create_logging_http_client(@public_endpoint, bits_service_options, request_timeout_in_seconds)
|
24
26
|
end
|
25
27
|
|
@@ -28,7 +30,7 @@ module BitsService
|
|
28
30
|
end
|
29
31
|
|
30
32
|
def exists?(key)
|
31
|
-
response = @
|
33
|
+
response = @private_http_client_fast_timeout.head(resource_path(key), @vcap_request_id)
|
32
34
|
validate_response_code!([200, 302, 404], response)
|
33
35
|
|
34
36
|
response.code.to_i != 404
|
@@ -50,14 +52,14 @@ module BitsService
|
|
50
52
|
|
51
53
|
body = { :"#{@resource_type.to_s.singularize}" => UploadIO.new(source_path, 'application/octet-stream') }
|
52
54
|
|
53
|
-
if resources
|
55
|
+
if !resources.nil?
|
54
56
|
body[:resources] = resources.to_json
|
55
57
|
end
|
56
58
|
|
57
59
|
response = @private_http_client.do_request(Net::HTTP::Put::Multipart.new(resource_path(destination_key), body), @vcap_request_id)
|
58
60
|
validate_response_code!(201, response)
|
59
|
-
if response.body
|
60
|
-
logger.error(
|
61
|
+
if response.body.nil?
|
62
|
+
logger.error('UnexpectedMissingBody: expected body with json payload. Got empty body.')
|
61
63
|
|
62
64
|
fail BlobstoreError.new({
|
63
65
|
response_code: response.code,
|
@@ -66,8 +68,8 @@ module BitsService
|
|
66
68
|
}.to_json)
|
67
69
|
end
|
68
70
|
shas = JSON.parse(response.body, symbolize_names: true)
|
69
|
-
validate_keys_present!([
|
70
|
-
|
71
|
+
validate_keys_present!(%i[sha1 sha256], shas, response)
|
72
|
+
shas
|
71
73
|
end
|
72
74
|
|
73
75
|
def download_from_blobstore(source_key, destination_path, mode: nil)
|
@@ -92,9 +94,8 @@ module BitsService
|
|
92
94
|
end
|
93
95
|
|
94
96
|
def delete(key)
|
95
|
-
response = @
|
97
|
+
response = @private_http_client_fast_timeout.delete(resource_path(key), @vcap_request_id)
|
96
98
|
validate_response_code!([204, 404], response)
|
97
|
-
|
98
99
|
if response.code.to_i == 404
|
99
100
|
raise FileNotFound.new("Could not find object '#{key}', #{response.code}/#{response.body}")
|
100
101
|
end
|
@@ -117,17 +118,17 @@ module BitsService
|
|
117
118
|
end
|
118
119
|
|
119
120
|
def delete_all(_=nil)
|
120
|
-
raise NotImplementedError unless
|
121
|
+
raise NotImplementedError unless resource_type == :buildpack_cache
|
121
122
|
|
122
|
-
@
|
123
|
+
@private_http_client_fast_timeout.delete(resource_path(''), @vcap_request_id).tap do |response|
|
123
124
|
validate_response_code!(204, response)
|
124
125
|
end
|
125
126
|
end
|
126
127
|
|
127
128
|
def delete_all_in_path(path)
|
128
|
-
raise NotImplementedError unless
|
129
|
+
raise NotImplementedError unless resource_type == :buildpack_cache
|
129
130
|
|
130
|
-
@
|
131
|
+
@private_http_client_fast_timeout.delete(resource_path(path.to_s), @vcap_request_id).tap do |response|
|
131
132
|
validate_response_code!(204, response)
|
132
133
|
end
|
133
134
|
end
|
@@ -140,10 +141,10 @@ module BitsService
|
|
140
141
|
LoggingHttpClient.new(
|
141
142
|
Net::HTTP.new(endpoint.host, endpoint.port).tap do |c|
|
142
143
|
c.read_timeout = request_timeout_in_seconds
|
143
|
-
if bits_service_options.
|
144
|
+
if bits_service_options.key?(:ca_cert_path)
|
144
145
|
ca_cert_path = bits_service_options[:ca_cert_path]
|
145
146
|
else
|
146
|
-
logger.info(
|
147
|
+
logger.info('Using bits-service client with root ca certs only (no configured ca_cert_path).')
|
147
148
|
ca_cert_path = nil
|
148
149
|
end
|
149
150
|
enable_ssl(c, ca_cert_path) if endpoint.scheme == 'https'
|
@@ -1,9 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'statsd'
|
4
|
+
|
2
5
|
module BitsService
|
3
6
|
class LoggingHttpClient
|
4
7
|
def initialize(http_client)
|
5
8
|
@http_client = http_client
|
6
9
|
@logger = Steno.logger('cc.bits_service_client')
|
10
|
+
@statsd = Statsd.new
|
7
11
|
end
|
8
12
|
|
9
13
|
def get(path, vcap_request_id, credentials=nil)
|
@@ -37,9 +41,22 @@ module BitsService
|
|
37
41
|
|
38
42
|
request.add_field('X-VCAP-REQUEST-ID', vcap_request_id)
|
39
43
|
|
40
|
-
|
44
|
+
begin
|
45
|
+
response = @http_client.request(request)
|
41
46
|
@logger.info('Response', { code: response.code, vcap_request_id: vcap_request_id })
|
47
|
+
rescue Net::ReadTimeout => ex
|
48
|
+
@statsd.increment("cc.bits_#{request.method.downcase}.timeout")
|
49
|
+
|
50
|
+
@logger.info('Request timeout', {
|
51
|
+
method: request.method,
|
52
|
+
path: request.path,
|
53
|
+
address: @http_client.address,
|
54
|
+
port: @http_client.port,
|
55
|
+
vcap_request_id: vcap_request_id,
|
56
|
+
})
|
57
|
+
raise ex
|
42
58
|
end
|
59
|
+
response
|
43
60
|
end
|
44
61
|
end
|
45
62
|
end
|
data/lib/bits_service_client.rb
CHANGED
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: 3.
|
4
|
+
version: 3.4.0.pre.1
|
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: 2018-
|
14
|
+
date: 2018-12-07 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: activesupport
|
@@ -41,6 +41,20 @@ dependencies:
|
|
41
41
|
- - ">="
|
42
42
|
- !ruby/object:Gem::Version
|
43
43
|
version: '0'
|
44
|
+
- !ruby/object:Gem::Dependency
|
45
|
+
name: statsd-ruby
|
46
|
+
requirement: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - "~>"
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '1.4'
|
51
|
+
type: :runtime
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - "~>"
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '1.4'
|
44
58
|
- !ruby/object:Gem::Dependency
|
45
59
|
name: bundler
|
46
60
|
requirement: !ruby/object:Gem::Requirement
|
@@ -153,6 +167,48 @@ dependencies:
|
|
153
167
|
- - '='
|
154
168
|
- !ruby/object:Gem::Version
|
155
169
|
version: 2.3.1
|
170
|
+
- !ruby/object:Gem::Dependency
|
171
|
+
name: sinatra
|
172
|
+
requirement: !ruby/object:Gem::Requirement
|
173
|
+
requirements:
|
174
|
+
- - ">="
|
175
|
+
- !ruby/object:Gem::Version
|
176
|
+
version: '0'
|
177
|
+
type: :development
|
178
|
+
prerelease: false
|
179
|
+
version_requirements: !ruby/object:Gem::Requirement
|
180
|
+
requirements:
|
181
|
+
- - ">="
|
182
|
+
- !ruby/object:Gem::Version
|
183
|
+
version: '0'
|
184
|
+
- !ruby/object:Gem::Dependency
|
185
|
+
name: pry
|
186
|
+
requirement: !ruby/object:Gem::Requirement
|
187
|
+
requirements:
|
188
|
+
- - ">="
|
189
|
+
- !ruby/object:Gem::Version
|
190
|
+
version: '0'
|
191
|
+
type: :development
|
192
|
+
prerelease: false
|
193
|
+
version_requirements: !ruby/object:Gem::Requirement
|
194
|
+
requirements:
|
195
|
+
- - ">="
|
196
|
+
- !ruby/object:Gem::Version
|
197
|
+
version: '0'
|
198
|
+
- !ruby/object:Gem::Dependency
|
199
|
+
name: pry-nav
|
200
|
+
requirement: !ruby/object:Gem::Requirement
|
201
|
+
requirements:
|
202
|
+
- - ">="
|
203
|
+
- !ruby/object:Gem::Version
|
204
|
+
version: '0'
|
205
|
+
type: :development
|
206
|
+
prerelease: false
|
207
|
+
version_requirements: !ruby/object:Gem::Requirement
|
208
|
+
requirements:
|
209
|
+
- - ">="
|
210
|
+
- !ruby/object:Gem::Version
|
211
|
+
version: '0'
|
156
212
|
description:
|
157
213
|
email:
|
158
214
|
- rizwanreza@gmail.com
|
@@ -195,12 +251,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
195
251
|
version: '0'
|
196
252
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
197
253
|
requirements:
|
198
|
-
- - "
|
254
|
+
- - ">"
|
199
255
|
- !ruby/object:Gem::Version
|
200
|
-
version:
|
256
|
+
version: 1.3.1
|
201
257
|
requirements: []
|
202
258
|
rubyforge_project:
|
203
|
-
rubygems_version: 2.6.14.
|
259
|
+
rubygems_version: 2.6.14.3
|
204
260
|
signing_key:
|
205
261
|
specification_version: 4
|
206
262
|
summary: Bits Services client for Cloud Foundry
|