factory_bot_instrumentation 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ed82ce916f1e735296247aa088af8dc8f737824129ca9c45eabd9bd691f073be
4
- data.tar.gz: dca8a2b9ca82e6bdc2ac9af520fd61f4b31f7a8d59bb03224b0aac966960ba0f
3
+ metadata.gz: 98a7a69daca8d49bb11b7145e050b3625c5f5638cc961fc3e91377300890c1db
4
+ data.tar.gz: ed9d4f5a254eb60cb0241fffbc32a43cfcd6ff2a44ddd476fc299286a37b488b
5
5
  SHA512:
6
- metadata.gz: 12651f784af98ac806f5a266d921d788f4b45b33ce159592f0ec4b6a0ad6cb850c8341b50236ae6d25348fdb070dcc3f415f311d07e54dd7cdf2c7a92b96c48b
7
- data.tar.gz: a5357b66bf2cef3ecf4cd39d47272cfeabfedeea56fd72659ae8ca084895cdd9c0576521979d91ae1fd800cbce5e1bbbcd15cc0785d16ec3a938054c7838bbab
6
+ metadata.gz: 6df53693fc478ac1ef3895d086efb6b86c7654b16a392fc6c7daa828e36918e1a67706bbc7c00a2f219394b092d9fa8f99bd608c57894e16d81274bb5e5e8bbc
7
+ data.tar.gz: d12ec3b074a2b0c1f7a33ea9725d13d28a4095d01e36d68727b057869d9904a3ea9052ad7247221197f2c1d5087e27be29509a71443b34d7edd8da0c7d254267
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ### 0.5.0
2
+
3
+ * Added support for custom before action logics (#7)
4
+
1
5
  ### 0.4.0
2
6
 
3
7
  * Added support for configurable rendering (#6)
data/Makefile CHANGED
@@ -93,4 +93,4 @@ shell-irb: install
93
93
 
94
94
  release:
95
95
  # Release a new gem version
96
- @$(RAKE) release
96
+ @$(BUNDLE) exec $(RAKE) release
data/README.md CHANGED
@@ -271,8 +271,8 @@ ease the integration. But as you can imagine the Instrumentation engine opens
271
271
  up some risky possibilities to your application. This is fine for a canary or
272
272
  development environment, but not for a production environment.
273
273
 
274
- There is currently only one way to secure the Instrumentation engine. You can
275
- completly disable it on your production environment by reconfiguring your
274
+ There are currently multiple ways to secure the Instrumentation engine. You can
275
+ completely disable it on your production environment by reconfiguring your
276
276
  routes like this:
277
277
 
278
278
  ```ruby
@@ -283,8 +283,17 @@ Rails.application.routes.draw do
283
283
  end
284
284
  ```
285
285
 
286
- Another option would be an HTTP basic authentication on this routes, but this
287
- is not yet implemented.
286
+ Another option would be an HTTP basic authentication. Just configure the gem
287
+ like this on the initializer:
288
+
289
+ ```ruby
290
+ FactoryBot::Instrumentation.configure do |conf|
291
+ conf.before_action = proc do |controller|
292
+ basic_auth(username: ENV.fetch('INSTRUMENTATION_USERNAME'),
293
+ password: ENV.fetch('INSTRUMENTATION_PASSWORD'))
294
+ end
295
+ end
296
+ ```
288
297
 
289
298
  #### Global settings
290
299
 
@@ -307,6 +316,12 @@ FactoryBot::Instrumentation.configure do |conf|
307
316
  controller.render plain: entity.to_json,
308
317
  content_type: 'application/json'
309
318
  end
319
+ # By default we do not perform any custom +before_action+ filters on the
320
+ # instrumentation controllers, with this option you can implement your
321
+ # custom logic like authentication
322
+ conf.before_action = proc do |controller|
323
+ # do your custom logic here
324
+ end
310
325
  end
311
326
  ```
312
327
 
@@ -3,5 +3,33 @@
3
3
  module FactoryBot::Instrumentation
4
4
  # A base engine application controller.
5
5
  class ApplicationController < ActionController::API
6
+ # Extend our core functionality to support easy authentication logics
7
+ include ActionController::HttpAuthentication::Basic::ControllerMethods
8
+ include ActionController::HttpAuthentication::Digest::ControllerMethods
9
+ include ActionController::HttpAuthentication::Token::ControllerMethods
10
+
11
+ # Allow the users to implement additional instrumentation-wide before
12
+ # action logic, like authentication
13
+ before_action do |controller|
14
+ if FactoryBot::Instrumentation.configuration.before_action
15
+ instance_eval &FactoryBot::Instrumentation.configuration.before_action
16
+ end
17
+ end
18
+
19
+ protected
20
+
21
+ # A simple shortcut for Basic Auth on Rails 4.2+. Just configure the
22
+ # username and password and you're ready to check the current request.
23
+ #
24
+ # @param username [String] the required user name
25
+ # @param password [String] the required password of the user
26
+ # @param realm [String] the authentication realm
27
+ def basic_auth(username:, password:, realm: 'Instrumentation')
28
+ authenticate_or_request_with_http_basic(realm) \
29
+ do |given_name, given_password|
30
+ ActiveSupport::SecurityUtils.secure_compare(given_name, username) &
31
+ ActiveSupport::SecurityUtils.secure_compare(given_password, password)
32
+ end
33
+ end
6
34
  end
7
35
  end
@@ -24,6 +24,11 @@ module FactoryBot
24
24
  content_type: 'application/json'
25
25
  end
26
26
  end
27
+
28
+ # By default we do not perform any custom +before_action+ filters on the
29
+ # instrumentation controllers, with this option you can implement your
30
+ # custom logic like authentication
31
+ config_accessor(:before_action) { nil }
27
32
  end
28
33
  end
29
34
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module FactoryBot
4
4
  module Instrumentation
5
- VERSION = '0.4.0'.freeze
5
+ VERSION = '0.5.0'.freeze
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: factory_bot_instrumentation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hermann Mayer
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-12-09 00:00:00.000000000 Z
11
+ date: 2020-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -203,7 +203,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
203
203
  - !ruby/object:Gem::Version
204
204
  version: '0'
205
205
  requirements: []
206
- rubygems_version: 3.0.6
206
+ rubygems_version: 3.1.2
207
207
  signing_key:
208
208
  specification_version: 4
209
209
  summary: Allow your testers to generate test data on demand