roo_on_rails 1.6.0 → 1.7.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.
@@ -5,6 +5,7 @@ source "https://rubygems.org"
5
5
  gem "guard"
6
6
  gem "guard-rspec"
7
7
  gem "appraisal"
8
+ gem "webmock"
8
9
  gem "pg"
9
10
  gem "sqlite3"
10
11
  gem "rails", "~> 5.0.0"
@@ -1,13 +1,16 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- roo_on_rails (1.6.0)
4
+ roo_on_rails (1.7.0)
5
5
  dogstatsd-ruby
6
6
  dotenv-rails (~> 2.1)
7
+ faraday
8
+ faraday_middleware
7
9
  hashie (~> 3.4)
8
10
  hirefire-resource
9
11
  newrelic_rpm
10
12
  octokit
13
+ omniauth-google-oauth2
11
14
  platform-api (~> 2.0)
12
15
  rack-ssl-enforcer
13
16
  rack-timeout
@@ -70,6 +73,8 @@ GEM
70
73
  coderay (1.1.1)
71
74
  concurrent-ruby (1.0.5)
72
75
  connection_pool (2.2.1)
76
+ crack (0.4.3)
77
+ safe_yaml (~> 1.0.0)
73
78
  diff-lcs (1.3)
74
79
  docile (1.1.5)
75
80
  dogstatsd-ruby (3.0.0)
@@ -81,6 +86,8 @@ GEM
81
86
  excon (0.57.1)
82
87
  faraday (0.12.1)
83
88
  multipart-post (>= 1.2, < 3)
89
+ faraday_middleware (0.11.0.1)
90
+ faraday (>= 0.7.4, < 1.0)
84
91
  ffi (1.9.18)
85
92
  formatador (0.2.5)
86
93
  globalid (0.4.0)
@@ -99,7 +106,8 @@ GEM
99
106
  guard (~> 2.1)
100
107
  guard-compat (~> 1.1)
101
108
  rspec (>= 2.99.0, < 4.0)
102
- hashie (3.5.5)
109
+ hashdiff (0.3.4)
110
+ hashie (3.5.6)
103
111
  heroics (0.0.23)
104
112
  erubis (~> 2.0)
105
113
  excon
@@ -107,6 +115,7 @@ GEM
107
115
  hirefire-resource (0.4.2)
108
116
  i18n (0.8.4)
109
117
  json (2.1.0)
118
+ jwt (1.5.6)
110
119
  listen (3.1.5)
111
120
  rb-fsevent (~> 0.9, >= 0.9.4)
112
121
  rb-inotify (~> 0.9, >= 0.9.7)
@@ -125,6 +134,7 @@ GEM
125
134
  minitest (5.10.2)
126
135
  moneta (0.8.1)
127
136
  multi_json (1.12.1)
137
+ multi_xml (0.6.0)
128
138
  multipart-post (2.0.0)
129
139
  nenv (0.3.0)
130
140
  newrelic_rpm (4.2.0.334)
@@ -134,8 +144,25 @@ GEM
134
144
  notiffany (0.1.1)
135
145
  nenv (~> 0.1)
136
146
  shellany (~> 0.0)
147
+ oauth2 (1.4.0)
148
+ faraday (>= 0.8, < 0.13)
149
+ jwt (~> 1.0)
150
+ multi_json (~> 1.3)
151
+ multi_xml (~> 0.5)
152
+ rack (>= 1.2, < 3)
137
153
  octokit (4.7.0)
138
154
  sawyer (~> 0.8.0, >= 0.5.3)
155
+ omniauth (1.6.1)
156
+ hashie (>= 3.4.6, < 3.6.0)
157
+ rack (>= 1.6.2, < 3)
158
+ omniauth-google-oauth2 (0.5.0)
159
+ jwt (~> 1.5)
160
+ multi_json (~> 1.3)
161
+ omniauth (>= 1.1.1)
162
+ omniauth-oauth2 (>= 1.3.1)
163
+ omniauth-oauth2 (1.4.0)
164
+ oauth2 (~> 1.0)
165
+ omniauth (~> 1.2)
139
166
  pg (0.21.0)
140
167
  platform-api (2.1.0)
141
168
  heroics (~> 0.0.23)
@@ -197,6 +224,7 @@ GEM
197
224
  rspec-support (~> 3.6.0)
198
225
  rspec-support (3.6.0)
199
226
  ruby_dep (1.5.0)
227
+ safe_yaml (1.0.4)
200
228
  sawyer (0.8.1)
201
229
  addressable (>= 2.3.5, < 2.6)
202
230
  faraday (~> 0.8, < 1.0)
@@ -225,6 +253,10 @@ GEM
225
253
  tzinfo (1.2.3)
226
254
  thread_safe (~> 0.1)
227
255
  url (0.3.2)
256
+ webmock (3.0.1)
257
+ addressable (>= 2.3.6)
258
+ crack (>= 0.3.2)
259
+ hashdiff
228
260
  websocket-driver (0.6.5)
229
261
  websocket-extensions (>= 0.1.0)
230
262
  websocket-extensions (0.1.2)
@@ -241,6 +273,7 @@ DEPENDENCIES
241
273
  memfs
242
274
  pg
243
275
  pry-byebug
276
+ rack-test
244
277
  rails (~> 5.0.0)
245
278
  rake (~> 10.0)
246
279
  roo_on_rails!
@@ -248,6 +281,7 @@ DEPENDENCIES
248
281
  simplecov
249
282
  sqlite3
250
283
  thor (~> 0.19)
284
+ webmock
251
285
 
252
286
  BUNDLED WITH
253
287
  1.14.6
@@ -5,6 +5,7 @@ source "https://rubygems.org"
5
5
  gem "guard"
6
6
  gem "guard-rspec"
7
7
  gem "appraisal"
8
+ gem "webmock"
8
9
  gem "pg"
9
10
  gem "sqlite3"
10
11
  gem "rails", "~> 5.1"
@@ -1,13 +1,16 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- roo_on_rails (1.6.0)
4
+ roo_on_rails (1.7.0)
5
5
  dogstatsd-ruby
6
6
  dotenv-rails (~> 2.1)
7
+ faraday
8
+ faraday_middleware
7
9
  hashie (~> 3.4)
8
10
  hirefire-resource
9
11
  newrelic_rpm
10
12
  octokit
13
+ omniauth-google-oauth2
11
14
  platform-api (~> 2.0)
12
15
  rack-ssl-enforcer
13
16
  rack-timeout
@@ -70,6 +73,8 @@ GEM
70
73
  coderay (1.1.1)
71
74
  concurrent-ruby (1.0.5)
72
75
  connection_pool (2.2.1)
76
+ crack (0.4.3)
77
+ safe_yaml (~> 1.0.0)
73
78
  diff-lcs (1.3)
74
79
  docile (1.1.5)
75
80
  dogstatsd-ruby (3.0.0)
@@ -82,6 +87,8 @@ GEM
82
87
  excon (0.57.1)
83
88
  faraday (0.12.1)
84
89
  multipart-post (>= 1.2, < 3)
90
+ faraday_middleware (0.11.0.1)
91
+ faraday (>= 0.7.4, < 1.0)
85
92
  ffi (1.9.18)
86
93
  formatador (0.2.5)
87
94
  globalid (0.4.0)
@@ -100,7 +107,8 @@ GEM
100
107
  guard (~> 2.1)
101
108
  guard-compat (~> 1.1)
102
109
  rspec (>= 2.99.0, < 4.0)
103
- hashie (3.5.5)
110
+ hashdiff (0.3.4)
111
+ hashie (3.5.6)
104
112
  heroics (0.0.23)
105
113
  erubis (~> 2.0)
106
114
  excon
@@ -108,6 +116,7 @@ GEM
108
116
  hirefire-resource (0.4.2)
109
117
  i18n (0.8.4)
110
118
  json (2.1.0)
119
+ jwt (1.5.6)
111
120
  listen (3.1.5)
112
121
  rb-fsevent (~> 0.9, >= 0.9.4)
113
122
  rb-inotify (~> 0.9, >= 0.9.7)
@@ -126,6 +135,7 @@ GEM
126
135
  minitest (5.10.2)
127
136
  moneta (0.8.1)
128
137
  multi_json (1.12.1)
138
+ multi_xml (0.6.0)
129
139
  multipart-post (2.0.0)
130
140
  nenv (0.3.0)
131
141
  newrelic_rpm (4.2.0.334)
@@ -135,8 +145,25 @@ GEM
135
145
  notiffany (0.1.1)
136
146
  nenv (~> 0.1)
137
147
  shellany (~> 0.0)
148
+ oauth2 (1.4.0)
149
+ faraday (>= 0.8, < 0.13)
150
+ jwt (~> 1.0)
151
+ multi_json (~> 1.3)
152
+ multi_xml (~> 0.5)
153
+ rack (>= 1.2, < 3)
138
154
  octokit (4.7.0)
139
155
  sawyer (~> 0.8.0, >= 0.5.3)
156
+ omniauth (1.6.1)
157
+ hashie (>= 3.4.6, < 3.6.0)
158
+ rack (>= 1.6.2, < 3)
159
+ omniauth-google-oauth2 (0.5.0)
160
+ jwt (~> 1.5)
161
+ multi_json (~> 1.3)
162
+ omniauth (>= 1.1.1)
163
+ omniauth-oauth2 (>= 1.3.1)
164
+ omniauth-oauth2 (1.4.0)
165
+ oauth2 (~> 1.0)
166
+ omniauth (~> 1.2)
140
167
  pg (0.21.0)
141
168
  platform-api (2.1.0)
142
169
  heroics (~> 0.0.23)
@@ -198,6 +225,7 @@ GEM
198
225
  rspec-support (~> 3.6.0)
199
226
  rspec-support (3.6.0)
200
227
  ruby_dep (1.5.0)
228
+ safe_yaml (1.0.4)
201
229
  sawyer (0.8.1)
202
230
  addressable (>= 2.3.5, < 2.6)
203
231
  faraday (~> 0.8, < 1.0)
@@ -226,6 +254,10 @@ GEM
226
254
  tzinfo (1.2.3)
227
255
  thread_safe (~> 0.1)
228
256
  url (0.3.2)
257
+ webmock (3.0.1)
258
+ addressable (>= 2.3.6)
259
+ crack (>= 0.3.2)
260
+ hashdiff
229
261
  websocket-driver (0.6.5)
230
262
  websocket-extensions (>= 0.1.0)
231
263
  websocket-extensions (0.1.2)
@@ -242,6 +274,7 @@ DEPENDENCIES
242
274
  memfs
243
275
  pg
244
276
  pry-byebug
277
+ rack-test
245
278
  rails (~> 5.1)
246
279
  rake (~> 10.0)
247
280
  roo_on_rails!
@@ -249,6 +282,7 @@ DEPENDENCIES
249
282
  simplecov
250
283
  sqlite3
251
284
  thor (~> 0.19)
285
+ webmock
252
286
 
253
287
  BUNDLED WITH
254
288
  1.14.6
@@ -11,4 +11,5 @@ if defined?(Rails)
11
11
  require 'roo_on_rails/railties/http'
12
12
  require 'roo_on_rails/railties/sidekiq'
13
13
  require 'roo_on_rails/railties/rake_tasks'
14
+ require 'roo_on_rails/railties/google_auth'
14
15
  end
@@ -6,6 +6,8 @@ require 'roo_on_rails/checks/heroku/app_exists'
6
6
  require 'roo_on_rails/checks/sidekiq/settings'
7
7
  require 'roo_on_rails/checks/heroku/drains_metrics'
8
8
  require 'roo_on_rails/checks/documentation/playbook'
9
+ require 'roo_on_rails/checks/google_oauth/initializer'
10
+ require 'roo_on_rails/checks/papertrail/all'
9
11
 
10
12
  module RooOnRails
11
13
  module Checks
@@ -15,6 +17,8 @@ module RooOnRails
15
17
  requires Heroku::PrebootEnabled
16
18
  requires Sidekiq::Settings
17
19
  requires Documentation::Playbook
20
+ requires GoogleOauth::Initializer
21
+ requires Papertrail::All
18
22
 
19
23
  def call
20
24
  # nothing to do
@@ -0,0 +1,49 @@
1
+ # Google Oauth initializer, generated by RooOnRails
2
+
3
+ require 'roo_on_rails/rack/google_oauth'
4
+
5
+ Rails.application.config.middleware.use RooOnRails::Rack::GoogleOauth do |env|
6
+ # This is your auth strategy.
7
+ # Here you're supposed to do something with the OAuth payload and
8
+ # return a valid Rack response.
9
+
10
+ # A simple and insecure example:
11
+ #
12
+ require 'digest/md5'
13
+ auth_data = env['omniauth.auth']
14
+ naive_token = Digest::MD5.hexdigest(auth_data.info.email.downcase)
15
+ expires_in = Time.current + 60 * 60 * 24
16
+ headers = { 'Location' => '/' }
17
+ Rack::Utils.set_cookie_header!(headers, 'naive_auth_cookie', {
18
+ value: naive_token, expires: expires_in, path: '/'
19
+ })
20
+ [302, headers, ['You are being redirecred to /']]
21
+
22
+ # You can also hand it over to a Rails controller action, where the
23
+ # OAuth payload will be available in `request.env['omniauth.auth']`.
24
+ # If you do this, the controller will take care of returning a valid
25
+ # response for Rack.
26
+ #
27
+ # This is the recommenced approach as it makes it easier to use
28
+ # Rails encrypted cookies and other security features.
29
+ #
30
+ # For example:
31
+ # MyAuthController.action(:login).call(env)
32
+ end
33
+
34
+ # What to do in case of failure.
35
+ # Must be a 302 redirect.
36
+ # It can invoke a Rails controller action
37
+ #
38
+ OmniAuth.config.on_failure = proc do |env|
39
+ error = env['omniauth.error'] # e.g. #<OmniAuth::Strategies::OAuth2::CallbackError: OmniAuth::Strategies::OAuth2::CallbackError>
40
+ details = error.message # e.g. "invalid_hd | Invalid Hosted Domain"
41
+ error_type = env['omniauth.error.type'] # e.g. :invalid_credentials
42
+
43
+ Rails.logger.info("[RooOnRails] Login failed (#{error_type}): #{details}")
44
+
45
+ # To use a rails controller;
46
+ # MyAuthController.action(:login_failed).call(env)
47
+
48
+ [302, { 'Location' => '/' }, ['']]
49
+ end
@@ -0,0 +1,43 @@
1
+ require 'roo_on_rails/config'
2
+ require 'roo_on_rails/checks/base'
3
+ require 'fileutils'
4
+
5
+ module RooOnRails
6
+ module Checks
7
+ module GoogleOauth
8
+ class Initializer < Base
9
+ LOCATION = 'config/initializers/google_oauth.rb'.freeze
10
+
11
+ def intro
12
+ 'Google Oauth protection'
13
+ end
14
+
15
+ def call
16
+ if RooOnRails::Config.google_auth_enabled?
17
+ check_initializer
18
+ else
19
+ pass 'Google Oauth is not enabled. Doing nothing'
20
+ end
21
+ end
22
+
23
+ def fix
24
+ FileUtils.cp(template, LOCATION)
25
+ end
26
+
27
+ private
28
+
29
+ def check_initializer
30
+ if File.exist? LOCATION
31
+ pass 'Google Oauth initializer is present. Doing nothing.'
32
+ else
33
+ fail! 'Google Oauth is enabled but the initializer is missing.'
34
+ end
35
+ end
36
+
37
+ def template
38
+ File.join(__dir__, '_template.rb')
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,21 @@
1
+ require 'roo_on_rails/checks/env_specific'
2
+ require 'roo_on_rails/checks/papertrail/system_named'
3
+
4
+ module RooOnRails
5
+ module Checks
6
+ module Papertrail
7
+ # Wrapper for Papertrail setup checks.
8
+ class All < EnvSpecific
9
+ requires SystemNamed
10
+
11
+ def intro
12
+ "Checking for Papertrail setup in #{bold env}..."
13
+ end
14
+
15
+ def call
16
+ pass 'all Papertrail checks passed'
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,64 @@
1
+ require 'roo_on_rails/checks/env_specific'
2
+ require 'roo_on_rails/checks/heroku/token'
3
+ require 'roo_on_rails/checks/heroku/app_exists'
4
+ require 'roo_on_rails/checks/papertrail/log_destination_exists'
5
+
6
+ module RooOnRails
7
+ module Checks
8
+ module Papertrail
9
+ # Check if a Heroku app is setup to a log drain to Papertrail
10
+ #
11
+ # Input context
12
+ # - heroku.api_client: a connected PlatformAPI client
13
+ # - heroku.app.{env}: an app name.
14
+ # - papertrail.dest.host, .port
15
+ #
16
+ # Output context:
17
+ # - papertrail.system_name.{env}: the drain token for this app, aka.
18
+ # "system name" in Papertrail. Looks like "d.{uuid}".
19
+ class DrainExists < EnvSpecific
20
+ requires Heroku::Token
21
+ requires Heroku::AppExists
22
+ requires LogDestinationExists
23
+
24
+ def intro
25
+ "Checking for Papertrail drain on #{bold app_name}..."
26
+ end
27
+
28
+ def call
29
+ # find the PT drain
30
+ data = client.log_drain.list(app_name).
31
+ select { |h| h['url'] =~ /papertrailapp/ }
32
+ fail! 'no Papertrail drain found' if data.empty?
33
+ fail! 'multiple Papertrail drains found' if data.length > 1
34
+
35
+ data = data.first
36
+ fail! "app is draining to #{data['url']} instead of #{papertrail_url}" if data['url'] != papertrail_url
37
+
38
+ pass "found drain setup with token #{data['token']}"
39
+ context.papertrail.system_name![env] = data['token']
40
+ end
41
+
42
+ def fix
43
+ client.log_drain.create(app_name, url: papertrail_url)
44
+ end
45
+
46
+ private
47
+
48
+ def app_name
49
+ context.heroku.app[env]
50
+ end
51
+
52
+ def client
53
+ context.heroku.api_client
54
+ end
55
+
56
+ def papertrail_url
57
+ format 'syslog+tls://%s:%s',
58
+ context.papertrail.dest.host,
59
+ context.papertrail.dest.port
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end