mini_check 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -13
- data/Gemfile +1 -1
- data/README.md +31 -0
- data/lib/mini_check/version.rb +1 -1
- data/lib/mini_check/version_rack_app.rb +88 -0
- data/lib/mini_check.rb +1 -0
- data/spec/mini_check/version_rack_app_spec.rb +98 -0
- data/spec/support/build.yml +0 -0
- metadata +17 -11
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
MGNjNDMwMmNmYTM2NWNhYWNhMDUxMmQ1NmM5ZGRiYWEwOTk2MzlhYg==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 20ef9ea5afbc7e220b1e81163a628c15267ae813
|
4
|
+
data.tar.gz: 5d4cdbf4c58aaa06595f0d3a7e239a3a8fee0de2
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
YTE1NDFmNGQ2MTRjZDgwOTVmYjkxOGRmMWFmMzk3YTc1YjI3MjQ1N2U0NjYx
|
11
|
-
NWVjZTA5MmRkYzA4ODFkOWU4N2NhMjE1ODg4YThjMmNjOTA5Njg=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
ODJmZmZlNWI3ODc0YjM1Y2E3NTE5NDg5MGU4NzNlMzlhOGNjZGMwYTg0NGU0
|
14
|
-
ZWRkNDAzYmZkNzAxMTk0ODZkNDVmMGRmNWY1YWMxN2M2YTllNTQ1NWIwZmQy
|
15
|
-
ODJlMTJlMTE3YTFjZjc4ODNiYmY1MTNlYWRlZjA5MDE2ODI3MDA=
|
6
|
+
metadata.gz: e5c6612eb00859f651ac8c40caeda10379651e323dd88ab6ebbca6e15223ab9dc72c45aeae31995990284ecc39951b964c60d370377ac10c623aa3c8148d5f59
|
7
|
+
data.tar.gz: 35521fa95e56d56b3ba71fd8dde9ac053a660369cba356c2909a6b7ab89fdd370b7215f68361f3e01d11f97bb2fd4f81a1f619f4965fa299f54165113b7c6a3d
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -67,6 +67,37 @@ The registered lambdas should do any of the following things:
|
|
67
67
|
|
68
68
|
The http status code will be 200 if all checks are healthy and 500 otherwise.
|
69
69
|
|
70
|
+
## Version
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
MyVersionCheck = MiniCheck::VersionRackApp.new(name: 'Cards', path: '/admin/version', build_file: './config/build.yml').tap do |app|
|
74
|
+
app.metadata["Whatever Here"] = "Bla Bla"
|
75
|
+
...
|
76
|
+
end
|
77
|
+
```
|
78
|
+
|
79
|
+
The build_file can be a YML or a plain text file. It needs to have pairs key-values.
|
80
|
+
|
81
|
+
If you now visit `http://localhost:XXXX/admin/version.json` you should get something like:
|
82
|
+
|
83
|
+
```json
|
84
|
+
{
|
85
|
+
"Application Name": "Cards",
|
86
|
+
"Whatever Here": "Bla Bla"
|
87
|
+
}
|
88
|
+
```
|
89
|
+
|
90
|
+
If you now visit `http://localhost:XXXX/admin/version` you should get something like:
|
91
|
+
|
92
|
+
```
|
93
|
+
Application Name=Cards
|
94
|
+
Whatever Here=Bla Bla
|
95
|
+
```
|
96
|
+
|
97
|
+
## Maintaining
|
98
|
+
|
99
|
+
Here is a good tutorial on this:
|
100
|
+
[Developing a RubyGem using Bundler](https://github.com/radar/guides/blob/master/gem-development.md).
|
70
101
|
|
71
102
|
## License
|
72
103
|
|
data/lib/mini_check/version.rb
CHANGED
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module MiniCheck
|
4
|
+
class VersionRackApp
|
5
|
+
attr_accessor :path, :build_file
|
6
|
+
|
7
|
+
def initialize args = {}
|
8
|
+
set_attributes args
|
9
|
+
end
|
10
|
+
|
11
|
+
def metadata
|
12
|
+
@metadata ||= Hash.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def call env
|
16
|
+
case "#{env['REQUEST_METHOD']} #{env['PATH_INFO']}"
|
17
|
+
when "GET #{path}.json"
|
18
|
+
JsonResponse.render(output_hash)
|
19
|
+
when "GET #{path}"
|
20
|
+
PlainTextResponse.render(output_hash)
|
21
|
+
else
|
22
|
+
host_app.call(env)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def new(app)
|
27
|
+
copy = self.dup
|
28
|
+
copy.host_app = app
|
29
|
+
copy
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def name= name
|
36
|
+
metadata["Application Name"] = name
|
37
|
+
end
|
38
|
+
|
39
|
+
def set_attributes args = {}
|
40
|
+
args.each do |k,v|
|
41
|
+
send("#{k}=", v)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def output_hash
|
46
|
+
metadata.merge(file_hash)
|
47
|
+
end
|
48
|
+
|
49
|
+
def file_hash
|
50
|
+
if (content = YAML.load_file(build_file)).instance_of?(Hash)
|
51
|
+
content
|
52
|
+
else
|
53
|
+
content = IO.read(build_file).split("\n")
|
54
|
+
Hash[content.map{ |pair| pair.split("=") }]
|
55
|
+
end
|
56
|
+
rescue => ex
|
57
|
+
{ error: ex.message }
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
protected
|
62
|
+
|
63
|
+
attr_accessor :host_app
|
64
|
+
|
65
|
+
def host_app
|
66
|
+
@host_app ||= lambda{|env| [404, {}, []]}
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
class JsonResponse
|
71
|
+
def self.render hash
|
72
|
+
[200, {'Content-Type' => 'application/json'}, [hash.to_json]]
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
class PlainTextResponse
|
77
|
+
def self.render hash
|
78
|
+
[200, {'Content-Type' => 'text/plain'}, [parse(hash)]]
|
79
|
+
end
|
80
|
+
|
81
|
+
private
|
82
|
+
|
83
|
+
def self.parse hash
|
84
|
+
hash.map{ |key,value| "#{key}=#{value}" }.join("\n")
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
data/lib/mini_check.rb
CHANGED
@@ -0,0 +1,98 @@
|
|
1
|
+
require_relative '../helper'
|
2
|
+
require 'rack/test'
|
3
|
+
|
4
|
+
describe MiniCheck::VersionRackApp do
|
5
|
+
include Rack::Test::Methods
|
6
|
+
|
7
|
+
subject{ MiniCheck::VersionRackApp.new path: '/version', build_file: './spec/support/build.yml', name: "Paquito"}
|
8
|
+
let(:version_hash) { {"Application Name" => "Paquito"} }
|
9
|
+
let(:version_text) { "Application Name=Paquito" }
|
10
|
+
let(:app){ subject }
|
11
|
+
|
12
|
+
def status
|
13
|
+
last_response.status
|
14
|
+
end
|
15
|
+
|
16
|
+
def headers
|
17
|
+
last_response.headers
|
18
|
+
end
|
19
|
+
|
20
|
+
def body
|
21
|
+
last_response.body
|
22
|
+
end
|
23
|
+
|
24
|
+
def body_json
|
25
|
+
JSON.parse(body)
|
26
|
+
end
|
27
|
+
|
28
|
+
describe :call do
|
29
|
+
it 'returns status, headers, body' do
|
30
|
+
get '/'
|
31
|
+
expect(status).to be_a(Fixnum)
|
32
|
+
expect(headers).to be_a(Hash)
|
33
|
+
expect(body).to be_a(String)
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'unknown path' do
|
37
|
+
it 'returns status 404 when no host app is given' do
|
38
|
+
get '/blahblah'
|
39
|
+
expect(status).to eq(404)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'delegates to the host app if given' do
|
43
|
+
app.send(:host_app=, lambda{|env| [999, {}, []] })
|
44
|
+
get '/blahblah'
|
45
|
+
expect(status).to eq(999)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'unknown verb' do
|
50
|
+
it 'returns status 404' do
|
51
|
+
post '/version'
|
52
|
+
expect(status).to eq(404)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'GET /version.json' do
|
57
|
+
def do_request
|
58
|
+
get '/version.json'
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'returns status 200' do
|
62
|
+
do_request
|
63
|
+
expect(status).to eq(200)
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'returns content type json' do
|
67
|
+
do_request
|
68
|
+
expect(headers['Content-Type']).to eq('application/json')
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'returns JSON body' do
|
72
|
+
do_request
|
73
|
+
expect(JSON.parse(body)).to eq(version_hash)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context 'GET /version' do
|
78
|
+
def do_request
|
79
|
+
get '/version'
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'returns status 200' do
|
83
|
+
do_request
|
84
|
+
expect(status).to eq(200)
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'returns content type plain text' do
|
88
|
+
do_request
|
89
|
+
expect(headers['Content-Type']).to eq('text/plain')
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'returns text body' do
|
93
|
+
do_request
|
94
|
+
expect(body).to eq(version_text)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
File without changes
|
metadata
CHANGED
@@ -1,41 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mini_check
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Manuel Morales
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-02-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.3'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.3'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: json
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
description: MiniCheck provides a simple Rack application for adding simple health
|
@@ -46,8 +46,8 @@ executables: []
|
|
46
46
|
extensions: []
|
47
47
|
extra_rdoc_files: []
|
48
48
|
files:
|
49
|
-
- .gitignore
|
50
|
-
- .travis.yml
|
49
|
+
- ".gitignore"
|
50
|
+
- ".travis.yml"
|
51
51
|
- CHANGELOG.md
|
52
52
|
- Gemfile
|
53
53
|
- LICENSE.md
|
@@ -58,12 +58,15 @@ files:
|
|
58
58
|
- lib/mini_check/checks_collection.rb
|
59
59
|
- lib/mini_check/rack_app.rb
|
60
60
|
- lib/mini_check/version.rb
|
61
|
+
- lib/mini_check/version_rack_app.rb
|
61
62
|
- mini_check.gemspec
|
62
63
|
- spec/helper.rb
|
63
64
|
- spec/mini_check/check_spec.rb
|
64
65
|
- spec/mini_check/checks_collection_spec.rb
|
65
66
|
- spec/mini_check/rack_app_spec.rb
|
67
|
+
- spec/mini_check/version_rack_app_spec.rb
|
66
68
|
- spec/mini_check_spec.rb
|
69
|
+
- spec/support/build.yml
|
67
70
|
homepage: https://github.com/workshare/mini-check
|
68
71
|
licenses:
|
69
72
|
- MIT
|
@@ -74,17 +77,17 @@ require_paths:
|
|
74
77
|
- lib
|
75
78
|
required_ruby_version: !ruby/object:Gem::Requirement
|
76
79
|
requirements:
|
77
|
-
- -
|
80
|
+
- - ">="
|
78
81
|
- !ruby/object:Gem::Version
|
79
82
|
version: '0'
|
80
83
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
84
|
requirements:
|
82
|
-
- -
|
85
|
+
- - ">="
|
83
86
|
- !ruby/object:Gem::Version
|
84
87
|
version: '0'
|
85
88
|
requirements: []
|
86
89
|
rubyforge_project:
|
87
|
-
rubygems_version: 2.
|
90
|
+
rubygems_version: 2.2.2
|
88
91
|
signing_key:
|
89
92
|
specification_version: 4
|
90
93
|
summary: MiniCheck provides a simple Rack application for adding simple health checks
|
@@ -94,4 +97,7 @@ test_files:
|
|
94
97
|
- spec/mini_check/check_spec.rb
|
95
98
|
- spec/mini_check/checks_collection_spec.rb
|
96
99
|
- spec/mini_check/rack_app_spec.rb
|
100
|
+
- spec/mini_check/version_rack_app_spec.rb
|
97
101
|
- spec/mini_check_spec.rb
|
102
|
+
- spec/support/build.yml
|
103
|
+
has_rdoc:
|