ruby_build_info 1.0.1 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ODEwN2I1YjZiMmQ3YzZkOTgwZDE2Mjc0OTgwYzlmYzg1MjliY2EzYw==
5
- data.tar.gz: !binary |-
6
- MzlkMzY1OWI3MjM4NDdjOGRkMmIwOTQ0Mzc4MjlhMjJiN2MzYTI5Ng==
2
+ SHA1:
3
+ metadata.gz: 6f664f0fad026a58de5ab4471f4bb860186bf865
4
+ data.tar.gz: a7d8311cf396e390987e306c396e5d2fd1c2da7e
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- NGI0ZjRlYmUxM2E1NWIwZjM4MmRmNmEzMTFiNGY1NzE1ODVmYjc3OGFhZTFi
10
- NTNkZTg5NThiN2E5ZmQ2NjZiNzNhMzI1N2YyZWNkNDM5ZTA5MmUyZTFhZDEy
11
- OGI3YjJlZmFjODg5OTgyZmE0MGEyZDU2MDliNWYxMzRkMTc2NmY=
12
- data.tar.gz: !binary |-
13
- ZmFiOWM3YjdmNTVjOTc3NjAzMDA2ZDc4NmRiNWYxNjMyMWI3MTM5ZWU0MjU4
14
- N2E0ODQxM2U4NmRjZjdiN2MxYjk4MzUyYTg5OWUyMjk4ODc4MzJmYzg4Zjk2
15
- MzcxZmZiZTIxMTlhYzJjMjZkNmNmNTVhYmVkYjQ0MzM4M2I0YzU=
6
+ metadata.gz: deb863d152672d96f1351b3408b7fd93d1ceb7ed5aa5979b9756aefb006e6663b7947d029383707dadc57f01d7b340069921263da1ebde558897e9b4e71fd8df
7
+ data.tar.gz: 5ee808c131ece7f48e1c45af96f071e9c39f583748ee1894121f994aa35264a7a5b871382e647bbc7f400057a8006f91517550455d5f7f2a4cfc11eb59c68303
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.5
data/Gemfile CHANGED
@@ -1,4 +1,8 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ group :development, :test do
4
+ gem 'pry-plus-byebug'
5
+ end
6
+
3
7
  # Specify your gem's dependencies in ruby_build_info.gemspec
4
8
  gemspec
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
- # BuildInfo
1
+ # RubyBuildInfo [![Gem Version](https://badge.fury.io/rb/ruby_build_info@2x.png)](http://badge.fury.io/rb/ruby_build_info) [![Build Status](https://travis-ci.org/adamgeorgeson/ruby_build_info.svg)](https://travis-ci.org/adamgeorgeson/ruby_build_info)
2
2
 
3
- Rack middleware to output build information such as version control, bundled gems, and specified files to a webpage.
3
+ Rack middleware to output build information such as version control, bundled gems, and specified files to JSON.
4
4
 
5
- ## Installation
5
+ ## Installation / Usage
6
6
 
7
7
  Add this line to your application's Gemfile:
8
8
 
@@ -16,19 +16,122 @@ Or install it yourself as:
16
16
 
17
17
  $ gem install ruby_build_info
18
18
 
19
- ## Usage
19
+ In your `config\environment\development.rb` or environment file of your choosing:
20
20
 
21
- In your `config\environment\development.rb` or environment file of your choosing*:
22
-
23
21
  config.middleware.use(RubyBuildInfo::Middleware)
24
22
 
25
- By default this will output Git revision, and output of `bundle show`.
23
+ By default this will output Git revision if available, and output of `bundle show`.
26
24
 
27
25
  You can specify an array optional file paths, such as version files.
28
26
 
29
27
  config.middleware.use(RubyBuildInfo::Middleware, file_paths: ['../custom_file_1', '../custom_file_2'])
30
28
 
31
- *Unless it's production.rb - then I don't condone that.
29
+ You can also provide an optional token in your environment file. When provided, you must pass the token as a parameter to access the endpoint.
30
+
31
+ config.middleware.use(RubyBuildInfo::Middleware, token: 'foo')
32
+ http:://localhost:3000/build_info?token=foo
33
+
34
+ Go to `/build_info` in your Ruby application to see output, supplying `token` paramater if configured.
35
+
36
+ ## Example Output
37
+
38
+ ```
39
+ {
40
+ "git": "2015-02-09 a94bb12 (HEAD, tag: v9.9.9, testing_build_info)",
41
+ "Rails::Info": {
42
+ "Ruby version": "2.1.5-p273 (x86_64-darwin14.0)",
43
+ "RubyGems version": "2.2.2",
44
+ "Rack version": "1.5",
45
+ "Rails version": "4.1.8",
46
+ "JavaScript Runtime": "JavaScriptCore",
47
+ "Active Record version": "4.1.8",
48
+ "Action Pack version": "4.1.8",
49
+ "Action View version": "4.1.8",
50
+ "Action Mailer version": "4.1.8",
51
+ "Active Support version": "4.1.8",
52
+ "Middleware": [
53
+ "Rack::Sendfile",
54
+ "ActionDispatch::Static",
55
+ "Rack::Lock",
56
+ "#<ActiveSupport::Cache::Strategy::LocalCache::Middleware:0x007fb8b17f3228>",
57
+ "Rack::Runtime",
58
+ "Rack::MethodOverride",
59
+ "ActionDispatch::RequestId",
60
+ "Rails::Rack::Logger",
61
+ "ActionDispatch::ShowExceptions",
62
+ "ActionDispatch::DebugExceptions",
63
+ "ActionDispatch::RemoteIp",
64
+ "ActionDispatch::Reloader",
65
+ "ActionDispatch::Callbacks",
66
+ "ActiveRecord::Migration::CheckPending",
67
+ "ActiveRecord::ConnectionAdapters::ConnectionManagement",
68
+ "ActiveRecord::QueryCache",
69
+ "ActionDispatch::Cookies",
70
+ "ActionDispatch::Session::CookieStore",
71
+ "ActionDispatch::Flash",
72
+ "ActionDispatch::ParamsParser",
73
+ "Rack::Head",
74
+ "Rack::ConditionalGet",
75
+ "Rack::ETag",
76
+ "RubyBuildInfo::Middleware"
77
+ ],
78
+ "Application root": "/Users/adamgeorgeson/dev/git_app",
79
+ "Environment": "development",
80
+ "Database adapter": "sqlite3",
81
+ "Database schema version": 0
82
+ },
83
+ "gems": [
84
+ "Gems included by the bundle:",
85
+ "actionmailer (4.1.8)",
86
+ "actionpack (4.1.8)",
87
+ "actionview (4.1.8)",
88
+ "activemodel (4.1.8)",
89
+ "activerecord (4.1.8)",
90
+ "activesupport (4.1.8)",
91
+ "arel (5.0.1.20140414130214)",
92
+ "builder (3.2.2)",
93
+ "bundler (1.8.0)",
94
+ "coffee-rails (4.0.1)",
95
+ "coffee-script (2.3.0)",
96
+ "coffee-script-source (1.9.0)",
97
+ "erubis (2.7.0)",
98
+ "execjs (2.3.0)",
99
+ "hike (1.2.3)",
100
+ "i18n (0.7.0)",
101
+ "jbuilder (2.2.6)",
102
+ "jquery-rails (3.1.2)",
103
+ "json (1.8.2)",
104
+ "mail (2.6.3)",
105
+ "mime-types (2.4.3)",
106
+ "minitest (5.5.1)",
107
+ "multi_json (1.10.1)",
108
+ "rack (1.5.2)",
109
+ "rack-test (0.6.3)",
110
+ "rails (4.1.8)",
111
+ "railties (4.1.8)",
112
+ "rake (10.4.2)",
113
+ "rdoc (4.2.0)",
114
+ "ruby_build_info (1.0.1)",
115
+ "sass (3.2.19)",
116
+ "sass-rails (4.0.5)",
117
+ "sdoc (0.4.1)",
118
+ "spring (1.3.1)",
119
+ "sprockets (2.12.3)",
120
+ "sprockets-rails (2.2.4)",
121
+ "sqlite3 (1.3.10)",
122
+ "thor (0.19.1)",
123
+ "thread_safe (0.3.4)",
124
+ "tilt (1.4.1)",
125
+ "turbolinks (2.5.3)",
126
+ "tzinfo (1.2.2)",
127
+ "uglifier (2.7.0)"
128
+ ]
129
+ }
130
+ ```
131
+
132
+ ## Viewing tools
133
+ When viewing JSON in a browser, you can use a plugin for a prettier
134
+ view. An example Chrome extension: https://github.com/gildas-lormeau/JSONView-for-Chrome
32
135
 
33
136
  ## Contributing
34
137
 
data/RELEASENOTES.md CHANGED
@@ -1,4 +1,9 @@
1
- # 1.0.0
1
+ # 1.1.0
2
+
3
+ ### Changes
4
+ * Support to protect endpoint by configuring a token.
5
+
6
+ # 1.0.0 / 1.0.1
2
7
 
3
8
  ### Changes
4
9
  * Initial release
data/Rakefile CHANGED
@@ -1,2 +1,5 @@
1
1
  require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+ task :default => :spec
4
+ RSpec::Core::RakeTask.new
2
5
 
@@ -5,12 +5,16 @@ module RubyBuildInfo
5
5
  def initialize(app, options = {})
6
6
  @app = app
7
7
  @file_paths = options[:file_paths]
8
+ @token = options[:token]
8
9
  end
9
10
 
10
11
  def call(env)
11
12
  if env['PATH_INFO'] == '/build_info'
13
+ @env = env
14
+ return @app.call(env) unless token_valid?
15
+
12
16
  @build_info = {}
13
- @build_info[:git] = git_revision if git_revision
17
+ @build_info[:git] = git_revision unless git_revision.empty?
14
18
  read_file_paths
15
19
  rails_info
16
20
  @build_info[:gems] = bundle_show
@@ -32,7 +36,7 @@ module RubyBuildInfo
32
36
  end
33
37
 
34
38
  def read_file_paths
35
- unless @file_paths.nil?
39
+ if @file_paths
36
40
  @file_paths.each do |file|
37
41
  raise "File does not exist: #{file}" unless File.exist? file
38
42
  @build_info[file] = `less #{file}`
@@ -40,11 +44,31 @@ module RubyBuildInfo
40
44
  end
41
45
  end
42
46
 
47
+ def params
48
+ query_string = @env['QUERY_STRING']
49
+ return nil if query_string.nil?
50
+ Hash[query_string.split('&').map{ |q| q.split('=') }]
51
+ end
52
+
53
+ def rails_defined?
54
+ defined? Rails
55
+ end
56
+
43
57
  def rails_info
44
- if defined? Rails
58
+ if rails_defined?
45
59
  result = Rails::Info.properties
46
60
  @build_info['Rails::Info'] = Hash[result]
47
61
  end
48
62
  end
63
+
64
+ def token_param
65
+ params['token'] if params
66
+ end
67
+
68
+ def token_valid?
69
+ return true if @token.nil?
70
+ return false if token_param.nil?
71
+ token_param == @token
72
+ end
49
73
  end
50
74
  end
@@ -1,3 +1,3 @@
1
1
  module RubyBuildInfo
2
- VERSION = "1.0.1"
2
+ VERSION = "1.1.1"
3
3
  end
@@ -18,9 +18,9 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ['lib']
20
20
 
21
- spec.add_dependency 'rack'
21
+ spec.add_dependency 'rack', '~> 1.0'
22
22
 
23
- spec.add_development_dependency 'bundler', '~> 1.6'
24
- spec.add_development_dependency 'rake'
25
- spec.add_development_dependency 'rspec'
23
+ spec.add_development_dependency 'bundler', '~> 1.7'
24
+ spec.add_development_dependency 'rake', '~> 10.4'
25
+ spec.add_development_dependency 'rspec', '~> 3.2'
26
26
  end
@@ -1,4 +1,5 @@
1
1
  require 'spec_helper'
2
+ require 'support/info'
2
3
 
3
4
  describe RubyBuildInfo::Middleware do
4
5
  subject{ described_class.new(app) }
@@ -14,6 +15,7 @@ describe RubyBuildInfo::Middleware do
14
15
  before do
15
16
  allow(subject).to receive(:bundle_show).and_return('bundle show')
16
17
  allow(subject).to receive(:git_revision).and_return('git revision')
18
+ allow(subject).to receive(:rails_defined?).and_return false
17
19
  end
18
20
 
19
21
  describe 'unrecognized path' do
@@ -24,17 +26,43 @@ describe RubyBuildInfo::Middleware do
24
26
  end
25
27
 
26
28
  describe '/build_info' do
27
- before do
28
- @response = server.get('/build_info')
29
- end
29
+ let(:example_response) { "{\n \"git\": \"git revision\",\n \"gems\": \"bundle show\"\n}" }
30
+
31
+ context 'when a token configured' do
32
+ subject{ described_class.new(app, token: 'foo') }
33
+ let(:server){ Rack::MockRequest.new(subject) }
34
+
35
+ it 'outputs build info when token matches param' do
36
+ @response = server.get('/build_info?token=foo&param2=value2')
37
+ expect(@response.body).to_not eq 'Foo'
38
+ expect(@response.body).to eq example_response
39
+ expect(@response.status). to eq 200
40
+ end
30
41
 
31
- it 'outputs build info' do
32
- expect(@response.body).to_not eq 'Foo'
33
- expect(@response.body).to eq "{\n \"git\": \"git revision\",\n \"gems\": \"bundle show\"\n}"
42
+ it 'does not output build info when token does not match param' do
43
+ @response = server.get('/build_info?param1=value1&token=bar')
44
+ expect(@response.body).to eq 'Foo'
45
+ expect(@response.body).to_not eq example_response
46
+ expect(@response.status). to eq 200
47
+ end
34
48
  end
35
49
 
36
- it 'returns HTTP status 200' do
37
- expect(@response.status). to eq 200
50
+ context 'when a token is not configured' do
51
+ subject{ described_class.new(app) }
52
+ let(:server){ Rack::MockRequest.new(subject) }
53
+
54
+ before do
55
+ @response = server.get('/build_info')
56
+ end
57
+
58
+ it 'outputs build info' do
59
+ expect(@response.body).to_not eq 'Foo'
60
+ expect(@response.body).to eq example_response
61
+ end
62
+
63
+ it 'returns HTTP status 200' do
64
+ expect(@response.status). to eq 200
65
+ end
38
66
  end
39
67
  end
40
68
 
@@ -62,28 +90,27 @@ describe RubyBuildInfo::Middleware do
62
90
  let(:server){ Rack::MockRequest.new(subject) }
63
91
 
64
92
  it 'returns content of the file' do
93
+ expected_response = "{\n \"git\": \"git revision\",\n \"./spec/support/platform_version\": \"1.2.3\\n\",\n \"gems\": \"bundle show\"\n}"
65
94
  @response = server.get('/build_info')
66
- expect(@response.body).to eq "{\n \"git\": \"git revision\",\n \"./spec/support/platform_version\": \"1.2.3\\n\",\n \"gems\": \"bundle show\"\n}"
95
+ expect(@response.body).to eq expected_response
67
96
  end
68
97
  end
69
98
  end
70
99
 
71
100
  describe 'Rails::Info' do
72
- before do
73
- @response = server.get('/build_info')
74
- end
75
-
76
101
  context 'when rails is not defined' do
77
102
  it 'does not output rails info' do
103
+ @response = server.get('/build_info')
78
104
  expect(@response.body).to_not include "Rails::Info"
79
105
  end
80
106
  end
81
107
 
82
108
  context 'when rails is defined' do
83
- xit 'outputs rails info' do
84
- rails = double('Rails', :env => :production)
85
- Object.send(:const_set, :Rails, rails)
86
- expect(Rails).to receive(:env).and_return('production')
109
+ before do
110
+ end
111
+ it 'outputs rails info' do
112
+ allow(subject).to receive(:rails_defined?).and_return true
113
+ @response = server.get('/build_info')
87
114
  expect(@response.body).to include "Rails::Info"
88
115
  end
89
116
  end
data/spec/spec_helper.rb CHANGED
@@ -16,6 +16,9 @@
16
16
  # users commonly want.
17
17
  #
18
18
  # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19
+
20
+ require 'pry-rescue/rspec'
21
+
19
22
  RSpec.configure do |config|
20
23
  config.requires = ['ruby_build_info']
21
24
  # rspec-expectations config goes here. You can use an alternate
@@ -0,0 +1,7 @@
1
+ module Rails
2
+ module Info
3
+ def self.properties
4
+ {'key1' => 'value1'}
5
+ end
6
+ end
7
+ end
metadata CHANGED
@@ -1,71 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_build_info
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Georgeson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-12 00:00:00.000000000 Z
11
+ date: 2015-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '1.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '1.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.6'
33
+ version: '1.7'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.6'
40
+ version: '1.7'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: '10.4'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: '10.4'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ! '>='
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: '3.2'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ! '>='
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: '3.2'
69
69
  description: Rack middleware to output build information such as version control,
70
70
  bundled gems, and specified files to json.
71
71
  email:
@@ -74,7 +74,8 @@ executables: []
74
74
  extensions: []
75
75
  extra_rdoc_files: []
76
76
  files:
77
- - .gitignore
77
+ - ".gitignore"
78
+ - ".travis.yml"
78
79
  - Gemfile
79
80
  - LICENSE.txt
80
81
  - README.md
@@ -86,6 +87,7 @@ files:
86
87
  - ruby_build_info.gemspec
87
88
  - spec/middleware_spec.rb
88
89
  - spec/spec_helper.rb
90
+ - spec/support/info.rb
89
91
  - spec/support/platform_version
90
92
  homepage: https://github.com/adamgeorgeson/ruby_build_info
91
93
  licenses:
@@ -97,17 +99,17 @@ require_paths:
97
99
  - lib
98
100
  required_ruby_version: !ruby/object:Gem::Requirement
99
101
  requirements:
100
- - - ! '>='
102
+ - - ">="
101
103
  - !ruby/object:Gem::Version
102
104
  version: '0'
103
105
  required_rubygems_version: !ruby/object:Gem::Requirement
104
106
  requirements:
105
- - - ! '>='
107
+ - - ">="
106
108
  - !ruby/object:Gem::Version
107
109
  version: '0'
108
110
  requirements: []
109
111
  rubyforge_project:
110
- rubygems_version: 2.2.2
112
+ rubygems_version: 2.4.6
111
113
  signing_key:
112
114
  specification_version: 4
113
115
  summary: Rack middleware to output build information such as version control, bundled
@@ -115,4 +117,6 @@ summary: Rack middleware to output build information such as version control, bu
115
117
  test_files:
116
118
  - spec/middleware_spec.rb
117
119
  - spec/spec_helper.rb
120
+ - spec/support/info.rb
118
121
  - spec/support/platform_version
122
+ has_rdoc: