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 +4 -4
- data/lib/corn.rb +31 -23
- data/lib/corn/config.rb +31 -0
- data/lib/corn/post.rb +9 -1
- data/lib/corn/rack/slow_request_profiler.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 939489a883d8ffc993fd10af0075cca1a36ecc6d
|
4
|
+
data.tar.gz: 477da0e4d9b6d50f618d9ac2faf7adf9ecf2696f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29f8ef1199f36c884dc5c53effc485f9fe91691f7a39cd2151e457995ac728242d59bbdfe27be019d011eaf831e99ead332138a2fcae7117635b1cb52f631e59
|
7
|
+
data.tar.gz: f082093672aed933a128c614edfa6b41f0c7fbf1418fd16464e55b606748663ec5c4c846d7802a068fd6848fca6a3c2ef554505d72af27a1adbd04236fc067ed
|
data/lib/corn.rb
CHANGED
@@ -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
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
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
|
32
|
-
|
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
|
data/lib/corn/config.rb
ADDED
@@ -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
|
data/lib/corn/post.rb
CHANGED
@@ -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
|
-
|
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}")
|
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.
|
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
|