conjur-rack-heartbeat 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 787168e29f4219e9b151d18ca6b9316b1c872ade
4
+ data.tar.gz: a8cde571d1fb2b9873dd1b49bf872a41d8b3df79
5
+ SHA512:
6
+ metadata.gz: 4112db2d4e98f16d60dd52c8b3465a1ed0116d635cffaa8986c87a5eaf7798ae1a5b6bf7b9ae6b9a2a15eac6b546bd7724a08ffcba313e4fd6260317cd8837e1
7
+ data.tar.gz: b780e23f6ed4d3a155b7e301de7e165e1dd1c54907bac1bf4c8c73fb58de61fbf4bd31d5d6a634d45c64a53ba2a115b2adb17dfeac1c7028b4612bf874c7e5da
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ report.xml
2
+ *.gem
3
+ *.rbc
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/.project ADDED
@@ -0,0 +1,18 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <projectDescription>
3
+ <name>rack-heartbeat</name>
4
+ <comment></comment>
5
+ <projects>
6
+ </projects>
7
+ <buildSpec>
8
+ <buildCommand>
9
+ <name>com.aptana.ide.core.unifiedBuilder</name>
10
+ <arguments>
11
+ </arguments>
12
+ </buildCommand>
13
+ </buildSpec>
14
+ <natures>
15
+ <nature>com.aptana.ruby.core.rubynature</nature>
16
+ <nature>com.aptana.projects.webnature</nature>
17
+ </natures>
18
+ </projectDescription>
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'coveralls', :group => :test, :require => false
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 James Cox [https://github.com/imajes]
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # Rack::Heartbeat
2
+
3
+ A tiny gem that installs a Rack middleware to respond to heartbeat requests. This saves you all the trouble of creating custom controllers, routes, and static files, and prevents your logs from bloating.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'conjur-rack-heartbeat'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install conjur-rack-heartbeat
18
+
19
+ ## Usage
20
+
21
+ Once the gem is installed, you're done. Just `curl -X OPTIONS localhost:3000` to get a text response with "OK".
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
30
+
31
+ ## Contributors
32
+
33
+ * [James Cox](https://github.com/imajes)
34
+ * [Steve Mitchell](http://github.com/theSteveMitchell)
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new(:test) do |t|
6
+ t.libs << 'test'
7
+ t.test_files = FileList['test/**/test*.rb']
8
+ t.verbose = true
9
+ end
10
+
11
+ Rake::TestTask.new(:jenkins) do |t|
12
+ t.libs << 'test'
13
+ t.test_files = FileList['test/**/test*.rb']
14
+ t.options = '--junit'
15
+ t.verbose = true
16
+ end
data/config.ru ADDED
@@ -0,0 +1,3 @@
1
+ require 'conjur-rack-heartbeat'
2
+
3
+ run Rack::Heartbeat.new(proc{ raise "Method not handled"})
data/jenkins.sh ADDED
@@ -0,0 +1,5 @@
1
+ #!/bin/bash -e
2
+
3
+ gem install -N bundler
4
+ bundle
5
+ bundle exec rake jenkins
@@ -0,0 +1,2 @@
1
+ require 'rack/heartbeat'
2
+ require 'rack/heartbeat/railtie' if defined?(Rails)
@@ -0,0 +1,28 @@
1
+ module Rack
2
+ # A heartbeat mechanism for the server. This will add a _/_ endpoint
3
+ # that responds to OPTIONS, returning status 200 when executed.
4
+
5
+ class Heartbeat
6
+ DEFAULT_ALLOW = %w(HEAD GET PUT DELETE OPTIONS)
7
+
8
+ attr_accessor :allow
9
+
10
+ def initialize(app, allow = nil)
11
+ @app = app
12
+ @allow = allow || DEFAULT_ALLOW
13
+ end
14
+
15
+ def call(env)
16
+ if env['PATH_INFO'] == "/" && (env['REQUEST_METHOD']||'').upcase == 'OPTIONS'
17
+ NewRelic::Agent.ignore_transaction if defined? NewRelic
18
+ [200, {"Content-Type" => "text/plain", "Allow" => @allow.join(',')}, ["OK"]]
19
+ else
20
+ @app.call(env)
21
+ end
22
+ end
23
+
24
+ def self.setup
25
+ yield self
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,9 @@
1
+ module Rack
2
+
3
+ class Heartbeat::Railtie < Rails::Railtie
4
+ initializer "rack.heartbeat.initializer" do |app|
5
+ app.middleware.insert 0, 'Rack::Heartbeat'
6
+ end
7
+ end
8
+
9
+ end
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.authors = ["James Cox", "Kevin Gilpin"]
5
+ gem.email = ["james@imaj.es", "kgilpin@gmail.com"]
6
+ gem.summary = %q{Provides OPTIONS / as a heartbeat URL}
7
+ gem.homepage = "https://github.com/conjurinc/rack-heartbeat"
8
+
9
+ gem.files = `git ls-files`.split($\)
10
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
11
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
12
+ gem.name = "conjur-rack-heartbeat"
13
+ gem.require_paths = ["lib"]
14
+ gem.version = '2.0.0'
15
+
16
+ gem.add_development_dependency('minitest')
17
+ gem.add_development_dependency('rack-test')
18
+ gem.add_development_dependency('minitest-junit')
19
+ gem.add_runtime_dependency('rack')
20
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,6 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+ SimpleCov.formatter = SimpleCov::Formatter::HTMLFormatter
4
+ require 'minitest/autorun'
5
+ require 'minitest/pride'
6
+ require 'conjur-rack-heartbeat'
@@ -0,0 +1,53 @@
1
+ require 'helper'
2
+
3
+ class Rack::TestHeartbeat < Minitest::Test
4
+ def setup
5
+ @app = Minitest::Mock.new
6
+ @heartbeat = Rack::Heartbeat.new(@app)
7
+ end
8
+
9
+ def test_call_when_env_empty_sends_app_call
10
+ env = {}
11
+
12
+ @app.expect :call, nil, [env]
13
+ @heartbeat.call(env)
14
+ @app.verify
15
+ end
16
+
17
+ def test_call_when_path_info_is_nil_sends_app_call
18
+ env = {'PATH_INFO' => nil}
19
+
20
+ @app.expect :call, nil, [env]
21
+ @heartbeat.call(env)
22
+ @app.verify
23
+ end
24
+
25
+ def test_call_when_path_info_does_not_match_heartbeat_sends_app_call
26
+ env = {'PATH_INFO' => 'some-path'}
27
+
28
+ @app.expect :call, nil, [env]
29
+ @heartbeat.call(env)
30
+ @app.verify
31
+ end
32
+
33
+ def test_call_when_request_method_does_not_match_heartbeat_sends_app_call
34
+ env = {'PATH_INFO' => '/', 'REQUEST_METHOD' => 'GET'}
35
+
36
+ @app.expect :call, nil, [env]
37
+ @heartbeat.call(env)
38
+ @app.verify
39
+ end
40
+
41
+ def test_call_when_path_info_matches_heartbeat_path_returns_200_response
42
+ env = {'PATH_INFO' => '/', 'REQUEST_METHOD' => 'OPTIONS'}
43
+
44
+ assert_equal [200, {'Content-Type' => 'text/plain', 'Allow' => 'HEAD,GET,PUT,DELETE,OPTIONS'}, ['OK']], @heartbeat.call(env)
45
+ end
46
+
47
+ def test_call_with_custom_allow_when_path_info_matches_heartbeat_path_returns_200_response
48
+ env = {'PATH_INFO' => '/', 'REQUEST_METHOD' => 'OPTIONS'}
49
+
50
+ @heartbeat.allow = %w(GET)
51
+ assert_equal [200, {'Content-Type' => 'text/plain', 'Allow' => 'GET'}, ['OK']], @heartbeat.call(env)
52
+ end
53
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: conjur-rack-heartbeat
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.0
5
+ platform: ruby
6
+ authors:
7
+ - James Cox
8
+ - Kevin Gilpin
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2016-01-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: minitest
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - '>='
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - '>='
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rack-test
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: minitest-junit
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rack
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ description:
71
+ email:
72
+ - james@imaj.es
73
+ - kgilpin@gmail.com
74
+ executables: []
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - .gitignore
79
+ - .project
80
+ - Gemfile
81
+ - LICENSE
82
+ - README.md
83
+ - Rakefile
84
+ - config.ru
85
+ - jenkins.sh
86
+ - lib/conjur-rack-heartbeat.rb
87
+ - lib/rack/heartbeat.rb
88
+ - lib/rack/heartbeat/railtie.rb
89
+ - rack-heartbeat.gemspec
90
+ - test/helper.rb
91
+ - test/rack/test_heartbeat.rb
92
+ homepage: https://github.com/conjurinc/rack-heartbeat
93
+ licenses: []
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.4.3
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: Provides OPTIONS / as a heartbeat URL
115
+ test_files:
116
+ - test/helper.rb
117
+ - test/rack/test_heartbeat.rb