micro_common 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/.rubocop.yml +10 -0
- data/.travis.yml +7 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +1 -0
- data/Rakefile +6 -0
- data/lib/micro_common.rb +33 -0
- data/lib/micro_common/meta_middleware.rb +49 -0
- data/lib/micro_common/store_request_id.rb +12 -0
- data/lib/micro_common/version.rb +3 -0
- data/micro_common.gemspec +33 -0
- metadata +155 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3a057f7feca71df1af402ee3ade5e03fa4dd6ee13461809684bb52de765df0b0
|
4
|
+
data.tar.gz: cf5ede4234377b19b553764ff1a10bbfc4ef8b44d5faffced9e1e6434244e0e4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 62f407bbb7debe5d82b815df9ab353343459c265eb9e71a7b03e47ab1aede693a857ef38a1cfc4dc4ffab3517e70229e81c5c02fc8bbe7b2e11612db9c62c56f
|
7
|
+
data.tar.gz: 95c9bf3e58efa893afb11f2503e739ad463ab59173154fb24294e7435b53f63557d9246184fd4d1aaae0225deec4a5cd0185ce56cda6769caf62602ff2acce44
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Francesco Boffa
|
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 @@
|
|
1
|
+
# MicroCommon
|
data/Rakefile
ADDED
data/lib/micro_common.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'ougai'
|
2
|
+
require 'lograge'
|
3
|
+
|
4
|
+
require 'micro_common/meta_middleware'
|
5
|
+
require 'micro_common/store_request_id'
|
6
|
+
|
7
|
+
require 'micro_common/version'
|
8
|
+
|
9
|
+
module MicroCommon
|
10
|
+
class Railtie < Rails::Railtie
|
11
|
+
initializer 'add_middlewares' do |app|
|
12
|
+
app.middleware.insert_after Rails::Rack::Logger, MicroCommon::MetaMiddleware
|
13
|
+
app.middleware.insert_before ActionDispatch::RemoteIp, MicroCommon::StoreRequestId
|
14
|
+
end
|
15
|
+
|
16
|
+
config.logger = Ougai::Logger.new(STDOUT)
|
17
|
+
config.logger.formatter = Ougai::Formatters::Readable.new if ENV['SIMPLE_LOGS']
|
18
|
+
config.logger.before_log = lambda do |data|
|
19
|
+
data[:request_id] = RequestStore.store[:request_id]
|
20
|
+
end
|
21
|
+
|
22
|
+
config.lograge.enabled = true
|
23
|
+
config.lograge.base_controller_class = 'ActionController::API'
|
24
|
+
config.lograge.formatter = Class.new do |fmt|
|
25
|
+
def fmt.call(data)
|
26
|
+
data
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
Rails.logger = config.logger
|
31
|
+
ActiveRecord::Base.logger = config.logger
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module MicroCommon
|
2
|
+
class MetaMiddleware
|
3
|
+
def initialize(app)
|
4
|
+
@app = app
|
5
|
+
end
|
6
|
+
|
7
|
+
def call(env)
|
8
|
+
uri = env['PATH_INFO']
|
9
|
+
|
10
|
+
if uri == '/meta/about'
|
11
|
+
about
|
12
|
+
elsif uri == '/meta/ping'
|
13
|
+
ping
|
14
|
+
elsif uri == '/meta/status'
|
15
|
+
status
|
16
|
+
else
|
17
|
+
@app.call(env)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def about
|
22
|
+
response = JSON.pretty_generate(YAML.safe_load(File.read(Rails.root.join('config', 'about.yaml'))))
|
23
|
+
[200, { 'Content-Type' => 'application/json' }, [response]]
|
24
|
+
end
|
25
|
+
|
26
|
+
def ping
|
27
|
+
[200, {}, ['PONG']]
|
28
|
+
end
|
29
|
+
|
30
|
+
def status
|
31
|
+
checks = run_checks
|
32
|
+
status = checks.all? { |_, v| v } ? 200 : 503
|
33
|
+
[status, { 'Content-Type' => 'application/json' }, [checks.to_json]]
|
34
|
+
end
|
35
|
+
|
36
|
+
def run_checks
|
37
|
+
{
|
38
|
+
database: check_database
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
def check_database
|
43
|
+
ActiveRecord::Base.connection.execute('SELECT 1')
|
44
|
+
true
|
45
|
+
rescue PG::Error, PG::ConnectionBad, ActiveRecord::NoDatabaseError
|
46
|
+
false
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'micro_common/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'micro_common'
|
7
|
+
spec.version = MicroCommon::VERSION
|
8
|
+
spec.authors = ['Francesco Boffa']
|
9
|
+
spec.email = ['fra.boffa@gmail.com']
|
10
|
+
|
11
|
+
spec.summary = 'Microservice common utilities'
|
12
|
+
spec.description = 'Microservice common utilities'
|
13
|
+
spec.homepage = 'https://github.com'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
# Specify which files should be added to the gem when it is released.
|
17
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
18
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
19
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
|
+
end
|
21
|
+
spec.bindir = 'exe'
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ['lib']
|
24
|
+
|
25
|
+
spec.add_dependency 'awesome_print'
|
26
|
+
spec.add_dependency 'ougai'
|
27
|
+
spec.add_dependency 'lograge'
|
28
|
+
spec.add_dependency 'request_store'
|
29
|
+
|
30
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
31
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
32
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: micro_common
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Francesco Boffa
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-05-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: awesome_print
|
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: ougai
|
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: lograge
|
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: request_store
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.16'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.16'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '10.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '10.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '3.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '3.0'
|
111
|
+
description: Microservice common utilities
|
112
|
+
email:
|
113
|
+
- fra.boffa@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- ".rspec"
|
120
|
+
- ".rubocop.yml"
|
121
|
+
- ".travis.yml"
|
122
|
+
- Gemfile
|
123
|
+
- LICENSE.txt
|
124
|
+
- README.md
|
125
|
+
- Rakefile
|
126
|
+
- lib/micro_common.rb
|
127
|
+
- lib/micro_common/meta_middleware.rb
|
128
|
+
- lib/micro_common/store_request_id.rb
|
129
|
+
- lib/micro_common/version.rb
|
130
|
+
- micro_common.gemspec
|
131
|
+
homepage: https://github.com
|
132
|
+
licenses:
|
133
|
+
- MIT
|
134
|
+
metadata: {}
|
135
|
+
post_install_message:
|
136
|
+
rdoc_options: []
|
137
|
+
require_paths:
|
138
|
+
- lib
|
139
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
|
+
requirements:
|
146
|
+
- - ">="
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: '0'
|
149
|
+
requirements: []
|
150
|
+
rubyforge_project:
|
151
|
+
rubygems_version: 2.7.8
|
152
|
+
signing_key:
|
153
|
+
specification_version: 4
|
154
|
+
summary: Microservice common utilities
|
155
|
+
test_files: []
|