hubrise_initializer 0.2.9 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+ source "https://rubygems.org"
3
+
4
+ gem "rails", "~> 6.0"
5
+ gem "rspec"
6
+ gem "rspec-rails", "~> 5.0"
7
+ gem "hubrise_initializer", path: "."
8
+
9
+ gem "rubocop", "0.81.0"
10
+ gem "webmock"
data/Gemfile.lock ADDED
@@ -0,0 +1,219 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ hubrise_initializer (1.0.1)
5
+ act-fluent-logger-rails (~> 0.6)
6
+ lograge (~> 0.11)
7
+ lograge-sql
8
+ logstash-event (~> 1.2)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ act-fluent-logger-rails (0.6.4)
14
+ activesupport (>= 4)
15
+ fluent-logger
16
+ railties (>= 4)
17
+ actioncable (6.1.6.1)
18
+ actionpack (= 6.1.6.1)
19
+ activesupport (= 6.1.6.1)
20
+ nio4r (~> 2.0)
21
+ websocket-driver (>= 0.6.1)
22
+ actionmailbox (6.1.6.1)
23
+ actionpack (= 6.1.6.1)
24
+ activejob (= 6.1.6.1)
25
+ activerecord (= 6.1.6.1)
26
+ activestorage (= 6.1.6.1)
27
+ activesupport (= 6.1.6.1)
28
+ mail (>= 2.7.1)
29
+ actionmailer (6.1.6.1)
30
+ actionpack (= 6.1.6.1)
31
+ actionview (= 6.1.6.1)
32
+ activejob (= 6.1.6.1)
33
+ activesupport (= 6.1.6.1)
34
+ mail (~> 2.5, >= 2.5.4)
35
+ rails-dom-testing (~> 2.0)
36
+ actionpack (6.1.6.1)
37
+ actionview (= 6.1.6.1)
38
+ activesupport (= 6.1.6.1)
39
+ rack (~> 2.0, >= 2.0.9)
40
+ rack-test (>= 0.6.3)
41
+ rails-dom-testing (~> 2.0)
42
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
43
+ actiontext (6.1.6.1)
44
+ actionpack (= 6.1.6.1)
45
+ activerecord (= 6.1.6.1)
46
+ activestorage (= 6.1.6.1)
47
+ activesupport (= 6.1.6.1)
48
+ nokogiri (>= 1.8.5)
49
+ actionview (6.1.6.1)
50
+ activesupport (= 6.1.6.1)
51
+ builder (~> 3.1)
52
+ erubi (~> 1.4)
53
+ rails-dom-testing (~> 2.0)
54
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
55
+ activejob (6.1.6.1)
56
+ activesupport (= 6.1.6.1)
57
+ globalid (>= 0.3.6)
58
+ activemodel (6.1.6.1)
59
+ activesupport (= 6.1.6.1)
60
+ activerecord (6.1.6.1)
61
+ activemodel (= 6.1.6.1)
62
+ activesupport (= 6.1.6.1)
63
+ activestorage (6.1.6.1)
64
+ actionpack (= 6.1.6.1)
65
+ activejob (= 6.1.6.1)
66
+ activerecord (= 6.1.6.1)
67
+ activesupport (= 6.1.6.1)
68
+ marcel (~> 1.0)
69
+ mini_mime (>= 1.1.0)
70
+ activesupport (6.1.6.1)
71
+ concurrent-ruby (~> 1.0, >= 1.0.2)
72
+ i18n (>= 1.6, < 2)
73
+ minitest (>= 5.1)
74
+ tzinfo (~> 2.0)
75
+ zeitwerk (~> 2.3)
76
+ addressable (2.8.0)
77
+ public_suffix (>= 2.0.2, < 5.0)
78
+ ast (2.4.2)
79
+ builder (3.2.4)
80
+ concurrent-ruby (1.1.10)
81
+ crack (0.4.5)
82
+ rexml
83
+ crass (1.0.6)
84
+ diff-lcs (1.5.0)
85
+ erubi (1.10.0)
86
+ fluent-logger (0.9.0)
87
+ msgpack (>= 1.0.0, < 2)
88
+ globalid (1.0.0)
89
+ activesupport (>= 5.0)
90
+ hashdiff (1.0.1)
91
+ i18n (1.12.0)
92
+ concurrent-ruby (~> 1.0)
93
+ jaro_winkler (1.5.4)
94
+ lograge (0.12.0)
95
+ actionpack (>= 4)
96
+ activesupport (>= 4)
97
+ railties (>= 4)
98
+ request_store (~> 1.0)
99
+ lograge-sql (2.0.0)
100
+ activerecord (>= 5, < 7.1)
101
+ lograge (~> 0.11)
102
+ logstash-event (1.2.02)
103
+ loofah (2.18.0)
104
+ crass (~> 1.0.2)
105
+ nokogiri (>= 1.5.9)
106
+ mail (2.7.1)
107
+ mini_mime (>= 0.1.1)
108
+ marcel (1.0.2)
109
+ method_source (1.0.0)
110
+ mini_mime (1.1.2)
111
+ mini_portile2 (2.8.0)
112
+ minitest (5.16.2)
113
+ msgpack (1.5.3)
114
+ nio4r (2.5.8)
115
+ nokogiri (1.13.7)
116
+ mini_portile2 (~> 2.8.0)
117
+ racc (~> 1.4)
118
+ parallel (1.22.1)
119
+ parser (3.1.2.0)
120
+ ast (~> 2.4.1)
121
+ public_suffix (4.0.7)
122
+ racc (1.6.0)
123
+ rack (2.2.4)
124
+ rack-test (2.0.2)
125
+ rack (>= 1.3)
126
+ rails (6.1.6.1)
127
+ actioncable (= 6.1.6.1)
128
+ actionmailbox (= 6.1.6.1)
129
+ actionmailer (= 6.1.6.1)
130
+ actionpack (= 6.1.6.1)
131
+ actiontext (= 6.1.6.1)
132
+ actionview (= 6.1.6.1)
133
+ activejob (= 6.1.6.1)
134
+ activemodel (= 6.1.6.1)
135
+ activerecord (= 6.1.6.1)
136
+ activestorage (= 6.1.6.1)
137
+ activesupport (= 6.1.6.1)
138
+ bundler (>= 1.15.0)
139
+ railties (= 6.1.6.1)
140
+ sprockets-rails (>= 2.0.0)
141
+ rails-dom-testing (2.0.3)
142
+ activesupport (>= 4.2.0)
143
+ nokogiri (>= 1.6)
144
+ rails-html-sanitizer (1.4.3)
145
+ loofah (~> 2.3)
146
+ railties (6.1.6.1)
147
+ actionpack (= 6.1.6.1)
148
+ activesupport (= 6.1.6.1)
149
+ method_source
150
+ rake (>= 12.2)
151
+ thor (~> 1.0)
152
+ rainbow (3.1.1)
153
+ rake (13.0.6)
154
+ request_store (1.5.1)
155
+ rack (>= 1.4)
156
+ rexml (3.2.5)
157
+ rspec (3.11.0)
158
+ rspec-core (~> 3.11.0)
159
+ rspec-expectations (~> 3.11.0)
160
+ rspec-mocks (~> 3.11.0)
161
+ rspec-core (3.11.0)
162
+ rspec-support (~> 3.11.0)
163
+ rspec-expectations (3.11.0)
164
+ diff-lcs (>= 1.2.0, < 2.0)
165
+ rspec-support (~> 3.11.0)
166
+ rspec-mocks (3.11.1)
167
+ diff-lcs (>= 1.2.0, < 2.0)
168
+ rspec-support (~> 3.11.0)
169
+ rspec-rails (5.1.2)
170
+ actionpack (>= 5.2)
171
+ activesupport (>= 5.2)
172
+ railties (>= 5.2)
173
+ rspec-core (~> 3.10)
174
+ rspec-expectations (~> 3.10)
175
+ rspec-mocks (~> 3.10)
176
+ rspec-support (~> 3.10)
177
+ rspec-support (3.11.0)
178
+ rubocop (0.81.0)
179
+ jaro_winkler (~> 1.5.1)
180
+ parallel (~> 1.10)
181
+ parser (>= 2.7.0.1)
182
+ rainbow (>= 2.2.2, < 4.0)
183
+ rexml
184
+ ruby-progressbar (~> 1.7)
185
+ unicode-display_width (>= 1.4.0, < 2.0)
186
+ ruby-progressbar (1.11.0)
187
+ sprockets (4.1.1)
188
+ concurrent-ruby (~> 1.0)
189
+ rack (> 1, < 3)
190
+ sprockets-rails (3.4.2)
191
+ actionpack (>= 5.2)
192
+ activesupport (>= 5.2)
193
+ sprockets (>= 3.0.0)
194
+ thor (1.2.1)
195
+ tzinfo (2.0.4)
196
+ concurrent-ruby (~> 1.0)
197
+ unicode-display_width (1.8.0)
198
+ webmock (3.14.0)
199
+ addressable (>= 2.8.0)
200
+ crack (>= 0.3.2)
201
+ hashdiff (>= 0.4.0, < 2.0.0)
202
+ websocket-driver (0.7.5)
203
+ websocket-extensions (>= 0.1.0)
204
+ websocket-extensions (0.1.5)
205
+ zeitwerk (2.6.0)
206
+
207
+ PLATFORMS
208
+ ruby
209
+
210
+ DEPENDENCIES
211
+ hubrise_initializer!
212
+ rails (~> 6.0)
213
+ rspec
214
+ rspec-rails (~> 5.0)
215
+ rubocop (= 0.81.0)
216
+ webmock
217
+
218
+ BUNDLED WITH
219
+ 2.1.2
data/README.md CHANGED
@@ -40,9 +40,21 @@ The following environment variables can be used only when`ENV['RAILS_LOGGER'] ==
40
40
 
41
41
  To upload the latest version to RubyGems.org:
42
42
 
43
+ 0. Make sure all local changes are committed.
44
+
43
45
  1. Increase version in `lib/hubrise_initializer/version.rb`
44
46
 
45
- 2. Build & publish - `cd` to the repository main folder then:
47
+ 2. Tag the repository:
48
+ ```bash
49
+ VERSION=1.0.2
50
+ git add lib/hubrise_initializer/version.rb
51
+ git commit -m "Version $VERSION"
52
+ git tag v$VERSION
53
+ git push --tags
54
+ git push
55
+ ```
56
+
57
+ 3. Build & publish - `cd` to the repository main folder then:
46
58
 
47
59
  ```bash
48
60
  rm -f hubrise_initializer-*.gem
@@ -1,14 +1,15 @@
1
- $LOAD_PATH.push File.expand_path("lib", __dir__)
1
+ # frozen_string_literal: true
2
+ $LOAD_PATH.push(File.expand_path("lib", __dir__))
2
3
 
3
4
  require "hubrise_initializer/version"
4
5
 
5
6
  Gem::Specification.new do |spec|
6
- spec.name = 'hubrise_initializer'
7
+ spec.name = "hubrise_initializer"
7
8
  spec.version = HubriseInitializer::VERSION
8
9
 
9
- spec.require_paths = ['lib']
10
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
11
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
10
+ spec.require_paths = ["lib"]
11
+ spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
12
+ %x(git ls-files -z).split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
12
13
  end
13
14
 
14
15
  spec.authors = ["Antoine Monnier"]
@@ -16,8 +17,8 @@ Gem::Specification.new do |spec|
16
17
  spec.homepage = "https://github.com/hubrise/rails-initializer.git"
17
18
  spec.license = "MIT"
18
19
 
19
- spec.add_runtime_dependency 'lograge', '~> 0.11'
20
- spec.add_runtime_dependency 'lograge-sql', '~>1.1'
21
- spec.add_runtime_dependency 'act-fluent-logger-rails', '~> 0.6'
22
- spec.add_runtime_dependency 'logstash-event', '~> 1.2'
20
+ spec.add_runtime_dependency("lograge", "~> 0.11")
21
+ spec.add_runtime_dependency("lograge-sql")
22
+ spec.add_runtime_dependency("act-fluent-logger-rails", "~> 0.6")
23
+ spec.add_runtime_dependency("logstash-event", "~> 1.2")
23
24
  end
@@ -1,30 +1,35 @@
1
+ # frozen_string_literal: true
1
2
  class HubriseInitializer
2
3
  class Lograge
3
4
  class << self
4
- def custom_options(event)
5
+ def custom_options(_event)
5
6
  {}
6
7
  end
7
8
 
8
9
  def custom_payload(controller)
9
- request, response = controller.request, controller.response
10
+ request = controller.request
11
+ request_headers = process_request_headers(request)
12
+ response = controller.response
13
+
10
14
  {
11
- release: ENV['RELEASE'],
12
- host: request.host,
13
- ip: request.ip,
14
- user_agent: request.user_agent,
15
- params: request.query_string.presence
16
- }.merge(
17
- if ENV['RAILS_LOGRAGE_QUERY'] == 'true'
15
+ release: ENV["RELEASE"],
16
+ host: request.host,
17
+ ip: request.ip,
18
+ access_token: request_headers["X-Access-Token"], # For the API
19
+ params: request.query_string.presence,
20
+ }.compact
21
+ .merge(
22
+ if ENV["RAILS_LOGRAGE_QUERY"] == "true"
18
23
  {
19
- request_headers: process_request_headers(request).to_s,
20
- request_body: truncate_body(switch_to_utf8(request.raw_post)),
21
- response_headers: response.headers.to_h.to_s,
22
- response_body: truncate_body(switch_to_utf8(response.body))
24
+ request_headers: request_headers.to_s,
25
+ request_body: truncate_body(switch_to_utf8(request.raw_post)),
26
+ response_headers: response.headers.to_h.to_s,
27
+ response_body: truncate_body(switch_to_utf8(response.body)),
23
28
  }
24
29
  else
25
30
  {}
26
31
  end
27
- )
32
+ )
28
33
  end
29
34
 
30
35
  private
@@ -33,7 +38,7 @@ class HubriseInitializer
33
38
 
34
39
  # Attempt to switch string encoding to utf-8. Return fallback if not a valid utf-8 sequence.
35
40
  def switch_to_utf8(s)
36
- return if !s
41
+ return unless s
37
42
 
38
43
  return s if s.encoding == Encoding::UTF_8
39
44
 
@@ -41,23 +46,22 @@ class HubriseInitializer
41
46
  return s_utf_8 if s_utf_8.valid_encoding?
42
47
 
43
48
  # Fallback for binary data
44
- return "Binary (#{s.size} bytes)"
49
+ "Binary (#{s.size} bytes)"
45
50
  end
46
51
 
47
52
  def truncate_body(s)
48
- s.present? ? s.squish.truncate(TRUNCATED_BODY_MAX_LENGTH, omission: '...') : nil
53
+ s.present? ? s.squish.truncate(TRUNCATED_BODY_MAX_LENGTH, omission: "...") : nil
49
54
  end
50
55
 
51
56
  def process_request_headers(request)
52
- http_prefix = 'HTTP_'
53
- request.headers.inject({}) do |hash, (key, value)|
54
- next hash if !key.start_with?(http_prefix)
57
+ http_prefix = "HTTP_"
58
+ request.headers.each_with_object({}) do |(key, value), hash|
59
+ next hash unless key.start_with?(http_prefix)
55
60
 
56
- header_name = key.gsub(http_prefix, '').split('_').map(&:capitalize).join('-')
61
+ header_name = key.gsub(http_prefix, "").split("_").map(&:capitalize).join("-")
57
62
  hash[header_name] = value
58
- hash
59
63
  end
60
64
  end
61
65
  end
62
66
  end
63
- end
67
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  class HubriseInitializer
2
- VERSION = '0.2.9'.freeze
3
+ VERSION = "1.0.2"
3
4
  end
@@ -1,8 +1,9 @@
1
- require 'lograge'
2
- require 'act-fluent-logger-rails'
1
+ # frozen_string_literal: true
2
+ require "lograge"
3
+ require "act-fluent-logger-rails"
3
4
 
4
- require 'hubrise_initializer/version'
5
- require 'hubrise_initializer/lograge'
5
+ require "hubrise_initializer/version"
6
+ require "hubrise_initializer/lograge"
6
7
 
7
8
  class HubriseInitializer
8
9
  class << self
@@ -25,16 +26,16 @@ class HubriseInitializer
25
26
  Rails.application.configure do
26
27
  config.lograge.base_controller_class = %w[ActionController::API ActionController::Base]
27
28
 
28
- if log_level = ENV['RAILS_LOG_LEVEL']
29
+ if (log_level = ENV["RAILS_LOG_LEVEL"])
29
30
  config.log_level = log_level
30
31
  end
31
32
 
32
- case ENV['RAILS_LOGGER']
33
- when 'stdout'
33
+ case ENV["RAILS_LOGGER"]
34
+ when "stdout"
34
35
  # Log to STDOUT (docker-compose)
35
36
  config.logger = ActiveSupport::Logger.new(STDOUT)
36
37
 
37
- when 'fluentd'
38
+ when "fluentd"
38
39
  # Log to fluentd (kubernetes)
39
40
  # ENV['FLUENTD_URL'] is used internally by this logger
40
41
  config.logger = ActFluentLoggerRails::Logger.new
@@ -46,12 +47,12 @@ class HubriseInitializer
46
47
  config.lograge.custom_options = lambda { |event| HubriseInitializer::Lograge.custom_options(event) }
47
48
  config.lograge.custom_payload { |controller| HubriseInitializer::Lograge.custom_payload(controller) }
48
49
 
49
- if ENV['RAILS_LOGRAGE_SQL'] == 'true'
50
- require 'lograge/sql'
51
- require 'lograge/sql/extension'
50
+ if ENV["RAILS_LOGRAGE_SQL"] == "true"
51
+ require "lograge/sql"
52
+ require "lograge/sql/extension"
52
53
  end
53
54
 
54
- else
55
+ else # rubocop:disable Style/EmptyElse
55
56
  # Log to a file (Rails default)
56
57
  end
57
58
  end
@@ -59,19 +60,19 @@ class HubriseInitializer
59
60
 
60
61
  def configure_delayed_job_logger
61
62
  Rails.application.configure do
62
- case ENV['RAILS_LOGGER']
63
- when 'stdout'
63
+ Delayed::Worker.logger = case ENV["RAILS_LOGGER"]
64
+ when "stdout"
64
65
  # Log to STDOUT (docker-compose)
65
- Delayed::Worker.logger = ActiveSupport::Logger.new(STDOUT)
66
+ ActiveSupport::Logger.new(STDOUT)
66
67
 
67
- when 'fluentd'
68
+ when "fluentd"
68
69
  # Log to fluentd (kubernetes)
69
70
  # ENV['FLUENTD_URL'] is used internally by this logger
70
- Delayed::Worker.logger = ActFluentLoggerRails::Logger.new
71
+ ActFluentLoggerRails::Logger.new
71
72
 
72
73
  else
73
74
  # Log to a file
74
- Delayed::Worker.logger = ActiveSupport::Logger.new(File.join(Rails.root, 'log', 'delayed_job.log'))
75
+ ActiveSupport::Logger.new(File.join(Rails.root, "log", "delayed_job.log"))
75
76
  end
76
77
  end
77
78
  end
@@ -79,13 +80,13 @@ class HubriseInitializer
79
80
  def configure_web_console
80
81
  Rails.application.configure do
81
82
  # web_console is generally enabled on dev only
82
- return if !config.respond_to?(:web_console)
83
+ return unless config.respond_to?(:web_console)
83
84
 
84
85
  # - 172.0.0.0/8: host in docker-compose
85
86
  # - 192.168.0.0/16: inter containers network in docker-compose
86
87
  # - 10.244.0.0/16: pod networks in Kubernetes
87
- config.web_console.whitelisted_ips = ['172.0.0.0/8', '192.168.0.0/16', '10.0.0.0/8']
88
+ config.web_console.whitelisted_ips = ["172.0.0.0/8", "192.168.0.0/16", "10.0.0.0/8"]
88
89
  end
89
90
  end
90
91
  end
91
- end
92
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hubrise_initializer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.9
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Antoine Monnier
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-29 00:00:00.000000000 Z
11
+ date: 2022-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lograge
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: lograge-sql
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '1.1'
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
- version: '1.1'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: act-fluent-logger-rails
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -72,7 +72,12 @@ executables: []
72
72
  extensions: []
73
73
  extra_rdoc_files: []
74
74
  files:
75
+ - ".github/workflows/rubocop.yml"
76
+ - ".github/workflows/spec.yml"
75
77
  - ".gitignore"
78
+ - ".rubocop.yml"
79
+ - Gemfile
80
+ - Gemfile.lock
76
81
  - README.md
77
82
  - hubrise_initializer.gemspec
78
83
  - lib/hubrise_initializer.rb