corn 0.4.2 → 0.4.3

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
  SHA1:
3
- metadata.gz: 3ce59d3b72f284db34d07ce896040fa38633a346
4
- data.tar.gz: 7c0f808633dc19752eea4fc865665c6cc67f0f2e
3
+ metadata.gz: 939489a883d8ffc993fd10af0075cca1a36ecc6d
4
+ data.tar.gz: 477da0e4d9b6d50f618d9ac2faf7adf9ecf2696f
5
5
  SHA512:
6
- metadata.gz: 42f77f91d007c9fce606299e14c0b991313ac4d92af218c95cbc1737848876b3d1845365ac1d87b59d0e67f12bc3440d5f85ed04d7439078d8d5503db6d2d9e6
7
- data.tar.gz: 38d9d3f6b32cacf7973bf8c4186c7015ea01348df29d409b9d4a6676c06257981cf3e4cf2e10bdc3a7598151d12f98d0de249393a56d062eec2f01e23c404c00
6
+ metadata.gz: 29f8ef1199f36c884dc5c53effc485f9fe91691f7a39cd2151e457995ac728242d59bbdfe27be019d011eaf831e99ead332138a2fcae7117635b1cb52f631e59
7
+ data.tar.gz: f082093672aed933a128c614edfa6b41f0c7fbf1418fd16464e55b606748663ec5c4c846d7802a068fd6848fca6a3c2ef554505d72af27a1adbd04236fc067ed
@@ -1,25 +1,37 @@
1
1
  require 'rubygems'
2
- require 'sampling_prof'
3
- require 'net/http'
4
- require 'net/https'
5
- require 'corn/rack'
6
2
  require 'logger'
3
+ require 'corn/config'
4
+ require 'corn/rack'
7
5
 
8
6
  module Corn
9
- module_function
10
-
11
- def rack_slow_request_profiler
12
- Rack::SlowRequestProfiler
13
- end
14
-
15
- def host
16
- ENV['CORN_HOST']
17
- end
18
-
19
- def client_id
20
- ENV['CORN_CLIENT_ID']
21
- end
7
+ include Config
8
+
9
+ # Set configurations or get current configurations.
10
+ #
11
+ # host: corn server host
12
+ # client_id: corn project client id
13
+ # logger: a Logger object, e.g. Rails.logger.
14
+ #
15
+ # Configurations for posting data back to Corn server
16
+ #
17
+ # ssl_verify_peer:
18
+ # true: set verify_mode to OpenSSL::SSL::VERIFY_PEER
19
+ # false: set verify_mode to OpenSSL::SSL::VERIFY_NONE
20
+ # default to false
21
+ # ssl_ca_file: Net::HTTPSession#ca_file
22
+ # ssl_ca_path: Net::HTTPSession#ca_path
23
+ # see Ruby Net::HTTP document for details
24
+ #
25
+ config({
26
+ :logger => Logger.new(STDOUT),
27
+ :host => ENV['CORN_HOST'],
28
+ :client_id => ENV['CORN_CLIENT_ID'],
29
+ :ssl_verify_peer => false,
30
+ :ssl_ca_file => nil,
31
+ :ssl_ca_path => nil
32
+ })
22
33
 
34
+ module_function
23
35
  def configured?
24
36
  !!(host && client_id)
25
37
  end
@@ -28,11 +40,7 @@ module Corn
28
40
  File.join(host, 'profile_data')
29
41
  end
30
42
 
31
- def logger=(l)
32
- @logger = l
33
- end
34
-
35
- def logger
36
- @logger ||= Logger.new(STDOUT)
43
+ def rack_slow_request_profiler
44
+ Rack::SlowRequestProfiler
37
45
  end
38
46
  end
@@ -0,0 +1,31 @@
1
+
2
+ module Corn
3
+ module Config
4
+ def self.included(base)
5
+ base.extend(ClassMethods)
6
+ end
7
+
8
+ module ClassMethods
9
+ def config(hash={})
10
+ @config ||= {}
11
+ if hash.empty?
12
+ @config
13
+ else
14
+ @config.merge!(hash)
15
+ hash.each do |key, value|
16
+ if self.respond_to?(key)
17
+ next
18
+ end
19
+ q = !!value == value ? '?' : ''
20
+ self.class_eval <<-RUBY, __FILE__, __LINE__
21
+ def self.#{key}#{q}
22
+ @config[:#{key}]
23
+ end
24
+ RUBY
25
+ end
26
+ @config
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -1,3 +1,5 @@
1
+ require 'net/http'
2
+ require 'net/https'
1
3
  require 'thread'
2
4
 
3
5
  module Corn
@@ -36,7 +38,13 @@ module Corn
36
38
  http = Net::HTTP.new(uri.host, uri.port)
37
39
  if uri.scheme == 'https'
38
40
  http.use_ssl = true
39
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE if ENV['CORN_SKIP_SSL_VERIFY']
41
+ if Corn.ssl_verify_peer
42
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
43
+ http.ca_file = Corn.ssl_ca_file if Corn.ssl_ca_file
44
+ http.ca_path = Corn.ssl_ca_path if Corn.ssl_ca_path
45
+ else
46
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
47
+ end
40
48
  end
41
49
  res = http.request(req)
42
50
  Corn.logger.info("Corn report submitted to #{submit_url}")
@@ -1,5 +1,5 @@
1
- require 'sampling_prof'
2
1
  require 'corn/post'
2
+ require 'sampling_prof'
3
3
 
4
4
  module Corn
5
5
  module Rack
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: corn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Xiao Li
@@ -35,6 +35,7 @@ extra_rdoc_files: []
35
35
  files:
36
36
  - README.md
37
37
  - lib/corn.rb
38
+ - lib/corn/config.rb
38
39
  - lib/corn/post.rb
39
40
  - lib/corn/rack.rb
40
41
  - lib/corn/rack/slow_request_profiler.rb