hubrise_initializer 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+ source "https://rubygems.org"
3
+
4
+ gem "rails", "~> 6.0"
5
+ gem "rspec-rails", "~> 5.0"
6
+ gem "hubrise_initializer", path: "."
7
+
8
+ gem "rubocop", "0.81.0"
9
+ 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
+ rspec
10
+
11
+ GEM
12
+ remote: https://rubygems.org/
13
+ specs:
14
+ act-fluent-logger-rails (0.6.4)
15
+ activesupport (>= 4)
16
+ fluent-logger
17
+ railties (>= 4)
18
+ actioncable (6.1.6.1)
19
+ actionpack (= 6.1.6.1)
20
+ activesupport (= 6.1.6.1)
21
+ nio4r (~> 2.0)
22
+ websocket-driver (>= 0.6.1)
23
+ actionmailbox (6.1.6.1)
24
+ actionpack (= 6.1.6.1)
25
+ activejob (= 6.1.6.1)
26
+ activerecord (= 6.1.6.1)
27
+ activestorage (= 6.1.6.1)
28
+ activesupport (= 6.1.6.1)
29
+ mail (>= 2.7.1)
30
+ actionmailer (6.1.6.1)
31
+ actionpack (= 6.1.6.1)
32
+ actionview (= 6.1.6.1)
33
+ activejob (= 6.1.6.1)
34
+ activesupport (= 6.1.6.1)
35
+ mail (~> 2.5, >= 2.5.4)
36
+ rails-dom-testing (~> 2.0)
37
+ actionpack (6.1.6.1)
38
+ actionview (= 6.1.6.1)
39
+ activesupport (= 6.1.6.1)
40
+ rack (~> 2.0, >= 2.0.9)
41
+ rack-test (>= 0.6.3)
42
+ rails-dom-testing (~> 2.0)
43
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
44
+ actiontext (6.1.6.1)
45
+ actionpack (= 6.1.6.1)
46
+ activerecord (= 6.1.6.1)
47
+ activestorage (= 6.1.6.1)
48
+ activesupport (= 6.1.6.1)
49
+ nokogiri (>= 1.8.5)
50
+ actionview (6.1.6.1)
51
+ activesupport (= 6.1.6.1)
52
+ builder (~> 3.1)
53
+ erubi (~> 1.4)
54
+ rails-dom-testing (~> 2.0)
55
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
56
+ activejob (6.1.6.1)
57
+ activesupport (= 6.1.6.1)
58
+ globalid (>= 0.3.6)
59
+ activemodel (6.1.6.1)
60
+ activesupport (= 6.1.6.1)
61
+ activerecord (6.1.6.1)
62
+ activemodel (= 6.1.6.1)
63
+ activesupport (= 6.1.6.1)
64
+ activestorage (6.1.6.1)
65
+ actionpack (= 6.1.6.1)
66
+ activejob (= 6.1.6.1)
67
+ activerecord (= 6.1.6.1)
68
+ activesupport (= 6.1.6.1)
69
+ marcel (~> 1.0)
70
+ mini_mime (>= 1.1.0)
71
+ activesupport (6.1.6.1)
72
+ concurrent-ruby (~> 1.0, >= 1.0.2)
73
+ i18n (>= 1.6, < 2)
74
+ minitest (>= 5.1)
75
+ tzinfo (~> 2.0)
76
+ zeitwerk (~> 2.3)
77
+ addressable (2.8.0)
78
+ public_suffix (>= 2.0.2, < 5.0)
79
+ ast (2.4.2)
80
+ builder (3.2.4)
81
+ concurrent-ruby (1.1.10)
82
+ crack (0.4.5)
83
+ rexml
84
+ crass (1.0.6)
85
+ diff-lcs (1.5.0)
86
+ erubi (1.10.0)
87
+ fluent-logger (0.9.0)
88
+ msgpack (>= 1.0.0, < 2)
89
+ globalid (1.0.0)
90
+ activesupport (>= 5.0)
91
+ hashdiff (1.0.1)
92
+ i18n (1.12.0)
93
+ concurrent-ruby (~> 1.0)
94
+ jaro_winkler (1.5.4)
95
+ lograge (0.12.0)
96
+ actionpack (>= 4)
97
+ activesupport (>= 4)
98
+ railties (>= 4)
99
+ request_store (~> 1.0)
100
+ lograge-sql (2.0.0)
101
+ activerecord (>= 5, < 7.1)
102
+ lograge (~> 0.11)
103
+ logstash-event (1.2.02)
104
+ loofah (2.18.0)
105
+ crass (~> 1.0.2)
106
+ nokogiri (>= 1.5.9)
107
+ mail (2.7.1)
108
+ mini_mime (>= 0.1.1)
109
+ marcel (1.0.2)
110
+ method_source (1.0.0)
111
+ mini_mime (1.1.2)
112
+ mini_portile2 (2.8.0)
113
+ minitest (5.16.2)
114
+ msgpack (1.5.3)
115
+ nio4r (2.5.8)
116
+ nokogiri (1.13.7)
117
+ mini_portile2 (~> 2.8.0)
118
+ racc (~> 1.4)
119
+ parallel (1.22.1)
120
+ parser (3.1.2.0)
121
+ ast (~> 2.4.1)
122
+ public_suffix (4.0.7)
123
+ racc (1.6.0)
124
+ rack (2.2.4)
125
+ rack-test (2.0.2)
126
+ rack (>= 1.3)
127
+ rails (6.1.6.1)
128
+ actioncable (= 6.1.6.1)
129
+ actionmailbox (= 6.1.6.1)
130
+ actionmailer (= 6.1.6.1)
131
+ actionpack (= 6.1.6.1)
132
+ actiontext (= 6.1.6.1)
133
+ actionview (= 6.1.6.1)
134
+ activejob (= 6.1.6.1)
135
+ activemodel (= 6.1.6.1)
136
+ activerecord (= 6.1.6.1)
137
+ activestorage (= 6.1.6.1)
138
+ activesupport (= 6.1.6.1)
139
+ bundler (>= 1.15.0)
140
+ railties (= 6.1.6.1)
141
+ sprockets-rails (>= 2.0.0)
142
+ rails-dom-testing (2.0.3)
143
+ activesupport (>= 4.2.0)
144
+ nokogiri (>= 1.6)
145
+ rails-html-sanitizer (1.4.3)
146
+ loofah (~> 2.3)
147
+ railties (6.1.6.1)
148
+ actionpack (= 6.1.6.1)
149
+ activesupport (= 6.1.6.1)
150
+ method_source
151
+ rake (>= 12.2)
152
+ thor (~> 1.0)
153
+ rainbow (3.1.1)
154
+ rake (13.0.6)
155
+ request_store (1.5.1)
156
+ rack (>= 1.4)
157
+ rexml (3.2.5)
158
+ rspec (3.11.0)
159
+ rspec-core (~> 3.11.0)
160
+ rspec-expectations (~> 3.11.0)
161
+ rspec-mocks (~> 3.11.0)
162
+ rspec-core (3.11.0)
163
+ rspec-support (~> 3.11.0)
164
+ rspec-expectations (3.11.0)
165
+ diff-lcs (>= 1.2.0, < 2.0)
166
+ rspec-support (~> 3.11.0)
167
+ rspec-mocks (3.11.1)
168
+ diff-lcs (>= 1.2.0, < 2.0)
169
+ rspec-support (~> 3.11.0)
170
+ rspec-rails (5.1.2)
171
+ actionpack (>= 5.2)
172
+ activesupport (>= 5.2)
173
+ railties (>= 5.2)
174
+ rspec-core (~> 3.10)
175
+ rspec-expectations (~> 3.10)
176
+ rspec-mocks (~> 3.10)
177
+ rspec-support (~> 3.10)
178
+ rspec-support (3.11.0)
179
+ rubocop (0.81.0)
180
+ jaro_winkler (~> 1.5.1)
181
+ parallel (~> 1.10)
182
+ parser (>= 2.7.0.1)
183
+ rainbow (>= 2.2.2, < 4.0)
184
+ rexml
185
+ ruby-progressbar (~> 1.7)
186
+ unicode-display_width (>= 1.4.0, < 2.0)
187
+ ruby-progressbar (1.11.0)
188
+ sprockets (4.1.1)
189
+ concurrent-ruby (~> 1.0)
190
+ rack (> 1, < 3)
191
+ sprockets-rails (3.4.2)
192
+ actionpack (>= 5.2)
193
+ activesupport (>= 5.2)
194
+ sprockets (>= 3.0.0)
195
+ thor (1.2.1)
196
+ tzinfo (2.0.4)
197
+ concurrent-ruby (~> 1.0)
198
+ unicode-display_width (1.8.0)
199
+ webmock (3.14.0)
200
+ addressable (>= 2.8.0)
201
+ crack (>= 0.3.2)
202
+ hashdiff (>= 0.4.0, < 2.0.0)
203
+ websocket-driver (0.7.5)
204
+ websocket-extensions (>= 0.1.0)
205
+ websocket-extensions (0.1.5)
206
+ zeitwerk (2.6.0)
207
+
208
+ PLATFORMS
209
+ ruby
210
+
211
+ DEPENDENCIES
212
+ hubrise_initializer!
213
+ rails (~> 6.0)
214
+ rspec-rails (~> 5.0)
215
+ rubocop (= 0.81.0)
216
+ webmock
217
+
218
+ BUNDLED WITH
219
+ 2.1.2
data/README.md CHANGED
@@ -46,7 +46,7 @@ To upload the latest version to RubyGems.org:
46
46
 
47
47
  2. Tag the repository:
48
48
  ```bash
49
- VERSION=1.0.0
49
+ VERSION=1.0.1
50
50
  git add lib/hubrise_initializer/version.rb
51
51
  git commit -m "Version $VERSION"
52
52
  git tag v$VERSION
@@ -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,9 @@ 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'
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")
24
+ spec.add_runtime_dependency("rspec")
23
25
  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 = "1.0.0".freeze
3
+ VERSION = "1.0.1"
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: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Antoine Monnier
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-06 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
@@ -66,13 +66,32 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  description:
70
84
  email:
71
85
  executables: []
72
86
  extensions: []
73
87
  extra_rdoc_files: []
74
88
  files:
89
+ - ".github/workflows/rubocop.yml"
90
+ - ".github/workflows/spec.yml"
75
91
  - ".gitignore"
92
+ - ".rubocop.yml"
93
+ - Gemfile
94
+ - Gemfile.lock
76
95
  - README.md
77
96
  - hubrise_initializer.gemspec
78
97
  - lib/hubrise_initializer.rb