coverband-service-client 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9d70bb9e3268a13b06640e0437e517cf00ccc4030f2b7f2c20e7b314d26828e2
4
- data.tar.gz: 3400abcd93c90f5f8bb011757933dd08b0619ef907d3f2675a1326bb5eb7a102
3
+ metadata.gz: 613941985d4fb60122f3e35a84c5139a7aa1395008a443b3a3478eef59df2b30
4
+ data.tar.gz: 03eabff6d96401aede1ed1263fdc26a400e93fc4e26ad164977e6b77a4b9a4a7
5
5
  SHA512:
6
- metadata.gz: fd6972fc75a2e8320a6ce2f991e871df0fed4c6a1298e0d2a443c479d309aca58d56f6c9c0aa346731fec7e1a9e12836e2cdb18480bd687667804f7b3d2a802d
7
- data.tar.gz: e4bd36b15a82c5ab95fcc770909d04b3426d818a1468b90cf1f45667facd1f4fda9d37809c667c85b822b7b8651f3f8576d8323914c331bf207a6458bad81e99
6
+ metadata.gz: 2d800e7c8abc0056866a6f9f96b1c89b9c1fc2ebcd7f5bdc17477199445f5740cc968d795cca1ad9a2ca9951480f32b8960f8e4729e975c2f19eea69aa57c8e7
7
+ data.tar.gz: 32d5360aa6a50d722d53481f22736e8c47c05844b9372fdd3d1e993ea2209fbdd3043e66dd2c016aad04df7195cffeb124d9fa8ca4bd66ce361f75462a368ffa
data/Gemfile.lock CHANGED
@@ -1,17 +1,17 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- coverband-service-client (0.0.8)
4
+ coverband-service-client (0.0.9)
5
5
  coverband (~> 4.2.4)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- coverband (4.2.4)
10
+ coverband (4.2.5)
11
11
  redis
12
12
  minitest (5.14.0)
13
13
  rake (13.0.1)
14
- redis (4.1.3)
14
+ redis (4.1.4)
15
15
 
16
16
  PLATFORMS
17
17
  ruby
@@ -4,21 +4,26 @@ require 'coverband'
4
4
  require 'coverband/service/client/version'
5
5
  require 'securerandom'
6
6
 
7
- COVERBAND_ENV = ENV['RACK_ENV'] || ENV['RAILS_ENV'] || (defined?(Rails) ? Rails.env : 'unknown')
8
- COVERBAND_SERVICE_URL = ENV['COVERBAND_URL'] || 'https://coverband.io'
9
- COVERBAND_TIMEOUT = (COVERBAND_ENV == 'development') ? 5 : 1
10
- COVERBAND_ENABLE_DEV_MODE = ENV['COVERBAND_ENABLE_DEV_MODE'] || false
11
- COVERBAND_ENABLE_TEST_MODE = ENV['COVERBAND_ENABLE_TEST_MODE'] || false
12
- COVERBAND_PROCESS_TYPE = ENV['PROCESS_TYPE'] || 'unknown'
13
- COVERBAND_REPORT_PERIOD = (ENV['COVERBAND_REPORT_PERIOD'] || 600).to_i
14
-
15
7
  module Coverband
8
+ COVERBAND_ENV = ENV['RACK_ENV'] || ENV['RAILS_ENV'] || (defined?(Rails) ? Rails.env : 'unknown')
9
+ COVERBAND_SERVICE_URL = ENV['COVERBAND_URL'] || 'https://coverband.io'
10
+ COVERBAND_TIMEOUT = (COVERBAND_ENV == 'development') ? 5 : 1
11
+ COVERBAND_ENABLE_DEV_MODE = ENV['COVERBAND_ENABLE_DEV_MODE'] || false
12
+ COVERBAND_ENABLE_TEST_MODE = ENV['COVERBAND_ENABLE_TEST_MODE'] || false
13
+ COVERBAND_PROCESS_TYPE = ENV['PROCESS_TYPE'] || 'unknown'
14
+ COVERBAND_REPORT_PERIOD = (ENV['COVERBAND_REPORT_PERIOD'] || 600).to_i
15
+
16
+ def self.service_disabled_dev_test_env?
17
+ (COVERBAND_ENV == 'test' && !COVERBAND_ENABLE_TEST_MODE) ||
18
+ (COVERBAND_ENV == 'development' && !COVERBAND_ENABLE_DEV_MODE)
19
+ end
16
20
 
17
- if ((COVERBAND_ENV == 'test' && !COVERBAND_ENABLE_TEST_MODE) ||
18
- COVERBAND_ENV == 'development' && !COVERBAND_ENABLE_DEV_MODE
19
- )
21
+ if service_disabled_dev_test_env?
20
22
  def self.report_coverage
21
- # for now disable coverband reporting in test env by default
23
+ # for now disable coverband reporting in test & dev env by default
24
+ if Coverband.configuration.verbose
25
+ puts "Coverband: disabled for #{COVERBAND_ENV}, set COVERBAND_ENABLE_DEV_MODE or COVERBAND_ENABLE_TEST_MODE to enable"
26
+ end
22
27
  end
23
28
  end
24
29
 
@@ -40,6 +45,10 @@ module Coverband
40
45
  @runtime_env = opts.fetch(:runtime_env) { COVERBAND_ENV }
41
46
  end
42
47
 
48
+ def logger
49
+ Coverband.configuration.logger
50
+ end
51
+
43
52
  def clear!
44
53
  # TBD
45
54
  end
@@ -53,11 +62,15 @@ module Coverband
53
62
  0
54
63
  end
55
64
 
65
+ def api_key
66
+ ENV['COVERBAND_API_KEY'] || Coverband.configuration.api_key
67
+ end
68
+
56
69
  # TODO: no longer get by type just get both reports in a single request
57
70
  def coverage(local_type = nil, opts = {})
58
71
  local_type ||= opts.key?(:override_type) ? opts[:override_type] : type
59
72
  uri = URI("#{coverband_url}/api/coverage/#{ENV['COVERBAND_ID']}?type=#{local_type}")
60
- req = Net::HTTP::Get.new(uri, 'Content-Type' => 'application/json', 'Coverband-Token' => ENV['COVERBAND_API_KEY'])
73
+ req = Net::HTTP::Get.new(uri, 'Content-Type' => 'application/json', 'Coverband-Token' => api_key)
61
74
  res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http|
62
75
  http.request(req)
63
76
  end
@@ -70,7 +83,6 @@ module Coverband
70
83
  end
71
84
 
72
85
  def save_report(report)
73
- #puts caller.join(',')
74
86
  return if report.empty?
75
87
 
76
88
  # TODO: do we need dup
@@ -99,12 +111,18 @@ module Coverband
99
111
  private
100
112
 
101
113
  def save_coverage(data)
114
+ if api_key.nil?
115
+ puts "Coverband: Error: no Coverband API key was found!"
116
+ end
117
+
102
118
  uri = URI("#{coverband_url}/api/collector")
119
+ logger&.info "Coverband: saving #{uri}" if Coverband.configuration.verbose
103
120
  req = Net::HTTP::Post.new(uri,
104
121
  'Content-Type' => 'application/json',
105
- 'Coverband-Token' => ENV['COVERBAND_API_KEY'])
106
- # puts "sending #{data}"
122
+ 'Coverband-Token' => api_key)
107
123
  req.body = { remote_uuid: SecureRandom.uuid, data: data }.to_json
124
+
125
+ logger&.info "Coverband: saving #{req.body}" if Coverband.configuration.verbose
108
126
  res = Net::HTTP.start(
109
127
  uri.hostname,
110
128
  uri.port,
@@ -155,6 +173,10 @@ module Coverband
155
173
 
156
174
  private
157
175
 
176
+ def logger
177
+ Coverband.configuration.logger
178
+ end
179
+
158
180
  def save_tracked_views(views:, reported_time:)
159
181
  uri = URI("#{COVERBAND_SERVICE_URL}/api/collector")
160
182
  req = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json', 'Coverband-Token' => ENV['COVERBAND_API_KEY'])
@@ -180,19 +202,39 @@ module Coverband
180
202
  end
181
203
  end
182
204
 
205
+ module Coverband
206
+ class Configuration
207
+ attr_accessor :api_key
208
+ end
209
+ end
210
+
183
211
  Coverband.configure do |config|
184
212
  # Use The Test Service Adapter
185
- config.store = Coverband::Adapters::Service.new(COVERBAND_SERVICE_URL)
213
+ config.store = Coverband::Adapters::Service.new(Coverband::COVERBAND_SERVICE_URL)
186
214
 
187
215
  # default to tracking views true
188
- config.track_views = ENV['COVERBAND_DISABLE_VIEW_TRACKER'] ? false : true
216
+ config.track_views = if ENV['COVERBAND_DISABLE_VIEW_TRACKER']
217
+ false
218
+ elsif Coverband.service_disabled_dev_test_env?
219
+ false
220
+ else
221
+ true
222
+ end
189
223
 
190
224
  # report every 10m by default
191
- config.background_reporting_sleep_seconds = COVERBAND_ENV == 'production' ? COVERBAND_REPORT_PERIOD : 60
225
+ config.background_reporting_sleep_seconds = Coverband::COVERBAND_ENV == 'production' ? Coverband::COVERBAND_REPORT_PERIOD : 60
192
226
  # add a wiggle to avoid service stampede
193
- config.reporting_wiggle = COVERBAND_ENV == 'production' ? 90 : 6
227
+ config.reporting_wiggle = Coverband::COVERBAND_ENV == 'production' ? 90 : 6
194
228
 
195
- if COVERBAND_ENV == 'test'
229
+ if Coverband::COVERBAND_ENV == 'test'
196
230
  config.background_reporting_enabled = false
197
231
  end
198
232
  end
233
+
234
+ # NOTE: it is really hard to bypass / overload our config we should fix this in Coverband
235
+ # this hopefully detects anyone that has both gems and was trying to configure Coverband themselves.
236
+ if File.exist?('./config/coverband.rb')
237
+ puts "Warning: config/coverband.rb found, this overrides coverband service allowing one to setup open source Coverband"
238
+ end
239
+
240
+ Coverband.configure('./config/coverband_service.rb') if File.exist?('./config/coverband_service.rb')
@@ -1,7 +1,7 @@
1
1
  module Coverband
2
2
  module Service
3
3
  module Client
4
- VERSION = '0.0.8'
4
+ VERSION = '0.0.9'
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coverband-service-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Mayer
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2020-05-02 00:00:00.000000000 Z
12
+ date: 2020-05-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler