deimos 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +64 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/deimos.gemspec +31 -0
- data/lib/deimos/logger.rb +32 -0
- data/lib/deimos/manager.rb +17 -0
- data/lib/deimos/status.rb +27 -0
- data/lib/deimos/version.rb +3 -0
- data/lib/deimos.rb +44 -0
- metadata +157 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: eb1166f1af8b6589e45dc0a2ab20fec615b691db7348e91199b368714a43e3a1
|
4
|
+
data.tar.gz: 562fd8af67609e08de2f1063053a6f8cd6f84671a844e4d44b5bf61543a14800
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 980ee84529e282e676faa1191f8053ee6ff451d466f13888a5ecbf0448e450ef9e5c27cb04392847bedb2511c8fb473f38cd2ceeea7320132b5463df619c204b
|
7
|
+
data.tar.gz: 20afcdeea07eab350938a88580898c0a6e5a11a7b695394c94eac68eeb5ea37e44bc80722f3b70fe5d50f82ccfa397fc0508f8bdd53d1cc61505224a2678b7f3
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
deimos (0.1.0)
|
5
|
+
huyegger
|
6
|
+
sinatra
|
7
|
+
sinatra-contrib
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
backports (3.12.0)
|
13
|
+
coderay (1.1.2)
|
14
|
+
diff-lcs (1.3)
|
15
|
+
huyegger (0.4.4)
|
16
|
+
method_source (0.9.2)
|
17
|
+
multi_json (1.13.1)
|
18
|
+
mustermann (1.0.3)
|
19
|
+
pry (0.12.2)
|
20
|
+
coderay (~> 1.1.0)
|
21
|
+
method_source (~> 0.9.0)
|
22
|
+
rack (2.0.6)
|
23
|
+
rack-protection (2.0.5)
|
24
|
+
rack
|
25
|
+
rake (10.5.0)
|
26
|
+
rspec (3.8.0)
|
27
|
+
rspec-core (~> 3.8.0)
|
28
|
+
rspec-expectations (~> 3.8.0)
|
29
|
+
rspec-mocks (~> 3.8.0)
|
30
|
+
rspec-core (3.8.0)
|
31
|
+
rspec-support (~> 3.8.0)
|
32
|
+
rspec-expectations (3.8.2)
|
33
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
34
|
+
rspec-support (~> 3.8.0)
|
35
|
+
rspec-mocks (3.8.0)
|
36
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
37
|
+
rspec-support (~> 3.8.0)
|
38
|
+
rspec-support (3.8.0)
|
39
|
+
sinatra (2.0.5)
|
40
|
+
mustermann (~> 1.0)
|
41
|
+
rack (~> 2.0)
|
42
|
+
rack-protection (= 2.0.5)
|
43
|
+
tilt (~> 2.0)
|
44
|
+
sinatra-contrib (2.0.5)
|
45
|
+
backports (>= 2.8.2)
|
46
|
+
multi_json
|
47
|
+
mustermann (~> 1.0)
|
48
|
+
rack-protection (= 2.0.5)
|
49
|
+
sinatra (= 2.0.5)
|
50
|
+
tilt (>= 1.3, < 3)
|
51
|
+
tilt (2.0.9)
|
52
|
+
|
53
|
+
PLATFORMS
|
54
|
+
ruby
|
55
|
+
|
56
|
+
DEPENDENCIES
|
57
|
+
bundler (~> 1.16)
|
58
|
+
deimos!
|
59
|
+
pry
|
60
|
+
rake (~> 10.0)
|
61
|
+
rspec (~> 3.0)
|
62
|
+
|
63
|
+
BUNDLED WITH
|
64
|
+
1.17.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Adam Carlile
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# Deimos
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/deimos`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'deimos'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install deimos
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/deimos.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "deimos"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/deimos.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "deimos/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "deimos"
|
8
|
+
spec.version = Deimos::VERSION
|
9
|
+
spec.authors = ["Adam Carlile"]
|
10
|
+
spec.email = ["hello@adamcarlile.com"]
|
11
|
+
|
12
|
+
spec.summary = "An oppinionated status gem to run alongside Phobos applications"
|
13
|
+
spec.homepage = "https://github.com/adamcarlile/deimos"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_dependency "sinatra"
|
24
|
+
spec.add_dependency "sinatra-contrib"
|
25
|
+
spec.add_dependency "huyegger"
|
26
|
+
|
27
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
28
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
29
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
30
|
+
spec.add_development_dependency "pry"
|
31
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rack/body_proxy'
|
4
|
+
|
5
|
+
module Deimos
|
6
|
+
class Logger
|
7
|
+
|
8
|
+
def initialize(app, logger = Deimos.logger)
|
9
|
+
@app = app
|
10
|
+
@logger = logger
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(env)
|
14
|
+
began_at = Rack::Utils.clock_time
|
15
|
+
status, header, body = @app.call(env)
|
16
|
+
header = Rack::Utils::HeaderHash.new(header)
|
17
|
+
body = Rack::BodyProxy.new(body) { log(env, status, header, began_at) }
|
18
|
+
[status, header, body]
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def log(env, status, header, began_at)
|
24
|
+
@logger.info({
|
25
|
+
message: [env[Rack::REQUEST_METHOD], env[Rack::PATH_INFO]].join(' '),
|
26
|
+
remote_ip: env['HTTP_X_FORWARDED_FOR'] || env["REMOTE_ADDR"],
|
27
|
+
status: status.to_s[0..3],
|
28
|
+
duration: (Rack::Utils.clock_time - began_at).round(4)
|
29
|
+
})
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "sinatra/base"
|
2
|
+
require "sinatra/json"
|
3
|
+
require 'webrick'
|
4
|
+
|
5
|
+
# Sinatra Applicaiton to present basic health check endpoint
|
6
|
+
module Deimos
|
7
|
+
class Status < Sinatra::Application
|
8
|
+
|
9
|
+
set :bind, Deimos.config.bind
|
10
|
+
set :port, Deimos.config.port
|
11
|
+
disable :show_exceptions, :traps, :logging
|
12
|
+
|
13
|
+
use Deimos::Logger
|
14
|
+
|
15
|
+
set :quiet, true
|
16
|
+
set :logger, Deimos.logger
|
17
|
+
set :server, :webrick
|
18
|
+
set :server_settings,
|
19
|
+
Logger: Deimos.logger,
|
20
|
+
AccessLog: []
|
21
|
+
|
22
|
+
get "/status" do
|
23
|
+
content_type :json
|
24
|
+
Deimos.manager.call
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/deimos.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'huyegger'
|
2
|
+
require 'sinatra'
|
3
|
+
require 'sinatra/contrib'
|
4
|
+
require 'webrick'
|
5
|
+
require 'logger'
|
6
|
+
|
7
|
+
require "deimos/version"
|
8
|
+
|
9
|
+
require 'deimos/logger'
|
10
|
+
require 'deimos/manager'
|
11
|
+
|
12
|
+
module Deimos
|
13
|
+
module_function
|
14
|
+
|
15
|
+
def boot!
|
16
|
+
require 'deimos/status'
|
17
|
+
Thread.new { Deimos::Status.run! }
|
18
|
+
end
|
19
|
+
|
20
|
+
def config
|
21
|
+
@config ||= OpenStruct.new.tap do |x|
|
22
|
+
x.log_level = ENV.fetch("LOG_LEVEL", ::Logger::INFO)
|
23
|
+
x.port = ENV.fetch("PORT", 5000)
|
24
|
+
x.bind = ENV.fetch("BIND_IP", "0.0.0.0")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def configure
|
29
|
+
yield(config)
|
30
|
+
end
|
31
|
+
|
32
|
+
def manager
|
33
|
+
@manager ||= Deimos::Manager.new
|
34
|
+
end
|
35
|
+
|
36
|
+
def add(*args, &block)
|
37
|
+
manager.add(*args, &block)
|
38
|
+
end
|
39
|
+
|
40
|
+
def logger
|
41
|
+
@logger ||= Huyegger::Logger.new(::Logger.new(STDOUT).tap {|x| x.level = config.log_level})
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
metadata
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: deimos
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Adam Carlile
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-03-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: sinatra
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sinatra-contrib
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: huyegger
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.16'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.16'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description:
|
112
|
+
email:
|
113
|
+
- hello@adamcarlile.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- ".rspec"
|
120
|
+
- ".travis.yml"
|
121
|
+
- Gemfile
|
122
|
+
- Gemfile.lock
|
123
|
+
- LICENSE.txt
|
124
|
+
- README.md
|
125
|
+
- Rakefile
|
126
|
+
- bin/console
|
127
|
+
- bin/setup
|
128
|
+
- deimos.gemspec
|
129
|
+
- lib/deimos.rb
|
130
|
+
- lib/deimos/logger.rb
|
131
|
+
- lib/deimos/manager.rb
|
132
|
+
- lib/deimos/status.rb
|
133
|
+
- lib/deimos/version.rb
|
134
|
+
homepage: https://github.com/adamcarlile/deimos
|
135
|
+
licenses:
|
136
|
+
- MIT
|
137
|
+
metadata: {}
|
138
|
+
post_install_message:
|
139
|
+
rdoc_options: []
|
140
|
+
require_paths:
|
141
|
+
- lib
|
142
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
requirements: []
|
153
|
+
rubygems_version: 3.0.1
|
154
|
+
signing_key:
|
155
|
+
specification_version: 4
|
156
|
+
summary: An oppinionated status gem to run alongside Phobos applications
|
157
|
+
test_files: []
|