pundit_logger 0.1.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.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +53 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/generators/pundit_logger/install_generator.rb +17 -0
- data/lib/pundit_extensions/loggers.rb +30 -0
- data/lib/pundit_logger.rb +30 -0
- data/lib/pundit_logger/configuration.rb +110 -0
- data/lib/pundit_logger/controller_extensions.rb +14 -0
- data/lib/pundit_logger/log_controller_policy_summary.rb +46 -0
- data/lib/pundit_logger/log_unauthorized_policies.rb +31 -0
- data/lib/pundit_logger/logging.rb +31 -0
- data/lib/pundit_logger/version.rb +3 -0
- data/lib/templates/default_initializer.rb +43 -0
- data/pundit_logger.gemspec +36 -0
- metadata +186 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 994d1a23819e4dbb8db86ca87bb03d1f3dbf78ac
|
4
|
+
data.tar.gz: 8d8e3bb2ed0c4bded11efc1f1f2040c07f2cd5f2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4219e48f5702c95a06cb528db084f27baf2593aa7bcae63bbc739867112b546a28277e3c258ea686d9b00a80235b2005265a260ff44e2fb5aa79212d9ed846a0
|
7
|
+
data.tar.gz: 7b9679a5fd3c27f3c85ede0c31eb98d4c671b1ecc6127c1fbd8c2bcd277d51412562728cf79296765ffc1d47817c2243644842a01f4383cd9f9b8475eaa23e38
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at shodges317@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Steve Hodges
|
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,53 @@
|
|
1
|
+
# PunditLogger
|
2
|
+
|
3
|
+
`pundit_logger` adds logging during key [Pundit](https://github.com/varvet/pundit) events to your application logs.
|
4
|
+
|
5
|
+
Use `pundit_logger` in production environments, most likely to log details about 401 Unauthorized occurances in your application.
|
6
|
+
|
7
|
+
`pundit_logger` can also speed with development and debugging with identification of the policies and scopes involved in controller requests.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'pundit_logger'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install pundit_logger
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
By including `pundit_logger` in a Rails application's `Gemfile`, logging will happen automatically. Just watch your logs for lines tagged with `[PUNDIT]` (assuming your log level is at least `debug` - you change that in gem configuration)
|
28
|
+
|
29
|
+
## Configuration
|
30
|
+
|
31
|
+
To configure `pundit_logger`, add a Rails initializer. You can generate a default initalizer:
|
32
|
+
|
33
|
+
$ rails generate pundit_logger:install
|
34
|
+
|
35
|
+
Configuration options are documented in that generated file, or [lib/pundit_logger/configuration.rb](lib/pundit_logger/configuration.rb). See specs for examples.
|
36
|
+
|
37
|
+
## Development
|
38
|
+
|
39
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
40
|
+
|
41
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
42
|
+
|
43
|
+
## Contributing
|
44
|
+
|
45
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/pundit_logger. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
46
|
+
|
47
|
+
## License
|
48
|
+
|
49
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
50
|
+
|
51
|
+
## Code of Conduct
|
52
|
+
|
53
|
+
Everyone interacting in the PunditLogger project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/pundit_logger/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "pundit_logger"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
module PunditLogger
|
3
|
+
module Generators
|
4
|
+
class InstallGenerator < Rails::Generators::Base
|
5
|
+
source_root File.expand_path("../../../templates", __FILE__)
|
6
|
+
desc 'Creates Pundit::Logger initializer for your application'
|
7
|
+
|
8
|
+
def copy_initializer
|
9
|
+
template 'default_initializer.rb',
|
10
|
+
'config/initializers/pundit_logger.rb'
|
11
|
+
|
12
|
+
puts "View the created file for configuration options.\n" \
|
13
|
+
"Now you know what Pundit\'s up to!"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'pundit'
|
2
|
+
require 'set'
|
3
|
+
|
4
|
+
module ::Pundit
|
5
|
+
class PolicyFinder
|
6
|
+
alias_method :original_scope, :scope
|
7
|
+
def scope
|
8
|
+
policy_scope_class = original_scope
|
9
|
+
policy_scope_class_invoked policy_scope_class
|
10
|
+
policy_scope_class
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def policy_scope_class_invoked(policy_scope_class)
|
16
|
+
return unless policy_scope_class
|
17
|
+
Pundit.invoked_policy_scope_names << policy_scope_class.name
|
18
|
+
|
19
|
+
return unless Pundit::Logger.log_scope_instantiation?
|
20
|
+
Pundit::Logger.log "Invoking #{policy_scope_class.name}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class << self
|
25
|
+
def invoked_policy_scope_names
|
26
|
+
@invoked_policy_scope_names ||= Set.new
|
27
|
+
@invoked_policy_scope_names
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'rails/all'
|
2
|
+
require 'pundit_logger/version'
|
3
|
+
require 'pundit_logger/configuration'
|
4
|
+
require 'pundit_logger/controller_extensions'
|
5
|
+
require 'pundit_logger/logging'
|
6
|
+
require 'pundit_extensions/loggers'
|
7
|
+
|
8
|
+
module Pundit
|
9
|
+
module Logger
|
10
|
+
extend ControllerExtensions
|
11
|
+
extend Logging
|
12
|
+
extend Configuration
|
13
|
+
|
14
|
+
# @return name of ActiveSupport hook to use when injecting
|
15
|
+
# controller loggers
|
16
|
+
def self.pundit_controller_hook_name
|
17
|
+
if Rails::VERSION::MAJOR > 5 ||
|
18
|
+
(Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR > 0)
|
19
|
+
:action_controller_base
|
20
|
+
else
|
21
|
+
:action_controller
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
ActiveSupport.on_load(Pundit::Logger.pundit_controller_hook_name) do
|
28
|
+
Pundit::Logger.add_controller_unauthorized_logger
|
29
|
+
Pundit::Logger.add_controller_policy_summary
|
30
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
module Pundit
|
2
|
+
module Logger
|
3
|
+
module Configuration
|
4
|
+
# Used to configure Pundit:Logger in your application.
|
5
|
+
#
|
6
|
+
# @example
|
7
|
+
# # config/initializers/pundit_logger.rb
|
8
|
+
#
|
9
|
+
# Pundit::Logger.configure do |config|
|
10
|
+
# config.log_level = :warn
|
11
|
+
# end
|
12
|
+
def configure
|
13
|
+
yield self if block_given?
|
14
|
+
end
|
15
|
+
|
16
|
+
# @param [String] ('ActionController::Base')
|
17
|
+
# Name of the controller to add logging to.
|
18
|
+
attr_writer :base_controller
|
19
|
+
def base_controller
|
20
|
+
(
|
21
|
+
@base_controller || 'ActionController::Base'
|
22
|
+
).constantize
|
23
|
+
end
|
24
|
+
|
25
|
+
# @param [Symbol] (:debug) The method to call on the defined
|
26
|
+
# logger, or the standard Rails logger methods
|
27
|
+
# If using the Rails.logger, options include
|
28
|
+
# :debug, :warn: :info, :error
|
29
|
+
attr_writer :log_level
|
30
|
+
def log_level
|
31
|
+
@log_level ||= :debug
|
32
|
+
end
|
33
|
+
|
34
|
+
# @param [#deug] (Rails.logger) The logger which the
|
35
|
+
# gem will write to. Must respond to whatever the
|
36
|
+
# configuration for #log_level is. (:debug by default)
|
37
|
+
#
|
38
|
+
# If the logger responds to #tagged, tagged logging
|
39
|
+
# will be utilized. You can disable tagged logging
|
40
|
+
# with #logger_tag:
|
41
|
+
# config.logger_tag = false
|
42
|
+
attr_writer :logger
|
43
|
+
def logger
|
44
|
+
@logger ||= Rails.logger
|
45
|
+
end
|
46
|
+
|
47
|
+
# @param [String, false, nil] ('PUNDIT') The tag to use for
|
48
|
+
# tagged_logging. This prefixes any output to your logs
|
49
|
+
# from this gem.
|
50
|
+
# If nil or false, tagged logging will not be used.
|
51
|
+
attr_writer :logger_tag
|
52
|
+
def logger_tag
|
53
|
+
if instance_variable_defined?(:@logger_tag)
|
54
|
+
@logger_tag
|
55
|
+
else
|
56
|
+
'PUNDIT'
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# Enable logging when a Scope is instantiated. This can help
|
61
|
+
# identify the source of SQL queries following in the logs.
|
62
|
+
#
|
63
|
+
# @param [String, false, nil] (true) logging enabled when,
|
64
|
+
# truthy, disabled when falsey
|
65
|
+
attr_writer :log_scope_instantiation
|
66
|
+
def log_scope_instantiation?
|
67
|
+
if instance_variable_defined?(:@log_scope_instantiation)
|
68
|
+
@log_scope_instantiation
|
69
|
+
else
|
70
|
+
true
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# Enable logging when a policy returns unauthorized
|
75
|
+
# (a Pundit::NotAuthorizedError), and that error is
|
76
|
+
# unhandled, bubbling up to the controller).
|
77
|
+
#
|
78
|
+
# This logging includes the policy and the arguments,
|
79
|
+
# to help debug why the action was unauthorized.
|
80
|
+
#
|
81
|
+
# @param [Boolean] (true) logging enabled when truthy,
|
82
|
+
# disabled when falsey
|
83
|
+
attr_writer :log_unauthorized_policies
|
84
|
+
def log_unauthorized_policies?
|
85
|
+
if instance_variable_defined?(:@log_unauthorized_policies)
|
86
|
+
@log_unauthorized_policies
|
87
|
+
else
|
88
|
+
true
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
# Enable logging a summary of all policies and scopes used
|
93
|
+
# in a controller request, after the action completes.
|
94
|
+
#
|
95
|
+
# Note that policies invoked by serializers are not
|
96
|
+
# logged at this time.
|
97
|
+
#
|
98
|
+
# @param [Boolean] (true) logging enabled when truthy,
|
99
|
+
# disabled when falsey
|
100
|
+
attr_writer :log_controller_policy_summary
|
101
|
+
def log_controller_policy_summary?
|
102
|
+
if instance_variable_defined?(:@log_controller_policy_summary)
|
103
|
+
@log_controller_policy_summary
|
104
|
+
else
|
105
|
+
true
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require_relative 'log_unauthorized_policies'
|
2
|
+
require_relative 'log_controller_policy_summary'
|
3
|
+
|
4
|
+
module Pundit::Logger
|
5
|
+
module ControllerExtensions
|
6
|
+
def add_controller_unauthorized_logger
|
7
|
+
base_controller.include LogUnauthorizedPolicies
|
8
|
+
end
|
9
|
+
|
10
|
+
def add_controller_policy_summary
|
11
|
+
base_controller.include LogControllerPolicySummary
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Pundit
|
2
|
+
module Logger
|
3
|
+
# Once a controller action completes, the names of the
|
4
|
+
# Pundit policies invoked are logged to the configured logger.
|
5
|
+
#
|
6
|
+
# Intended for mixing into Rails controllers
|
7
|
+
#
|
8
|
+
# Functionality controlled by
|
9
|
+
# Pundit::Logger.log_controller_policy_summary; disable by setting
|
10
|
+
# that to false.
|
11
|
+
module LogControllerPolicySummary
|
12
|
+
|
13
|
+
extend ActiveSupport::Concern
|
14
|
+
|
15
|
+
included do
|
16
|
+
after_action :log_policies_invoked,
|
17
|
+
if: -> { Pundit::Logger.log_controller_policy_summary? }
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def log_policies_invoked
|
23
|
+
policy_names = invoked_policy_names +
|
24
|
+
invoked_policy_scope_names
|
25
|
+
message = if policy_names.empty?
|
26
|
+
'None'
|
27
|
+
else
|
28
|
+
policy_names.uniq.sort.join(', ')
|
29
|
+
end
|
30
|
+
Pundit::Logger.log 'Controller Action Policies ' \
|
31
|
+
"Invoked: #{message}"
|
32
|
+
end
|
33
|
+
|
34
|
+
def invoked_policy_names
|
35
|
+
return [] unless respond_to?(:policies)
|
36
|
+
policies.map do |_, policy_obj|
|
37
|
+
policy_obj.class.name
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def invoked_policy_scope_names
|
42
|
+
Pundit.invoked_policy_scope_names.to_a
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Pundit
|
2
|
+
module Logger
|
3
|
+
# If Pundit authorization fails, the policy name and associated
|
4
|
+
# information is logged to the configured logger.
|
5
|
+
#
|
6
|
+
# Intended for mixing into Rails controllers
|
7
|
+
#
|
8
|
+
# Functionality controlled by
|
9
|
+
# Pundit::Logger.log_unauthorized_policies; disable by setting
|
10
|
+
# that to false.
|
11
|
+
module LogUnauthorizedPolicies
|
12
|
+
|
13
|
+
extend ActiveSupport::Concern
|
14
|
+
|
15
|
+
included do
|
16
|
+
around_action :log_unauthorized_policies,
|
17
|
+
if: -> { Pundit::Logger.log_unauthorized_policies? }
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def log_unauthorized_policies
|
23
|
+
yield
|
24
|
+
rescue Pundit::NotAuthorizedError => e
|
25
|
+
Pundit::Logger.log "Authorization Failed for "\
|
26
|
+
"#{e.policy.class.name}: #{e.message}"
|
27
|
+
raise e
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Pundit
|
2
|
+
module Logger
|
3
|
+
module Logging
|
4
|
+
# Logs a message to the logger configured in
|
5
|
+
# Pundit::Logger.logger.
|
6
|
+
#
|
7
|
+
# Uses tagged logging, if configured using
|
8
|
+
# Pundit::Logger.logger_tag
|
9
|
+
#
|
10
|
+
# @param [String] Message to write to the logger
|
11
|
+
def log(message)
|
12
|
+
if logger.respond_to?(:tagged) && logger_tag
|
13
|
+
logger.tagged(logger_tag) do
|
14
|
+
write_message message
|
15
|
+
end
|
16
|
+
else
|
17
|
+
write_message message
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def write_message(message)
|
24
|
+
logger.public_send(
|
25
|
+
log_level.to_sym,
|
26
|
+
message
|
27
|
+
)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'pundit'
|
2
|
+
require 'pundit_logger'
|
3
|
+
|
4
|
+
Pundit::Logger.configure do |config|
|
5
|
+
|
6
|
+
# CONTROLLER CONFIGURATION
|
7
|
+
#
|
8
|
+
# Name of the controller to add logging to.
|
9
|
+
# For a standard Rails app, the default configuration
|
10
|
+
# will add logging to all controllers.
|
11
|
+
#
|
12
|
+
# config.base_controller = 'ActionController::Base'
|
13
|
+
|
14
|
+
# LOGGER CONFIGURATION
|
15
|
+
#
|
16
|
+
# Modify the log_level, for instance to :info or :debug
|
17
|
+
# config.log_level = :debug
|
18
|
+
#
|
19
|
+
# Specify a different logger. The logger may or may not
|
20
|
+
# implement tagged logging, but must implement :debug,
|
21
|
+
# or whatever you set log_level to.
|
22
|
+
# config.logger = Rails.logger
|
23
|
+
#
|
24
|
+
# For tagged logging, the tag to use for logs generated
|
25
|
+
# by Pundit::Logger
|
26
|
+
# config.logger_tag = 'PUNDIT'
|
27
|
+
|
28
|
+
# OUTPUT CONFIGURATION
|
29
|
+
#
|
30
|
+
# Logs whenever a Pundit Scope is instantiated. This
|
31
|
+
# can be helpful when observing which SQL is logged
|
32
|
+
# immediately afterwards.
|
33
|
+
# config.log_scope_instantiation = true
|
34
|
+
#
|
35
|
+
# Logs details about the policy, current_user, and other
|
36
|
+
# arguments whenever an pundit `authorized` method in
|
37
|
+
# a controller is not authorized.
|
38
|
+
# config.log_unauthorized_policies = true
|
39
|
+
#
|
40
|
+
# Logs a summary of all policies used for scopes and
|
41
|
+
# authorization in a controller action.
|
42
|
+
# config.log_controller_policy_summary = true
|
43
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "pundit_logger/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'pundit_logger'
|
8
|
+
spec.version = PunditLogger::VERSION
|
9
|
+
spec.authors = ['Steve Hodges']
|
10
|
+
spec.email = ['shodges317@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = %q{Log policy usage in Rails apps which use Pundit}
|
13
|
+
spec.description = 'Pundit is a lightweight authorization gem. But, in ' \
|
14
|
+
'complex Rails apps, it can be difficult to determine ' \
|
15
|
+
'why authorization failed, or which policies are ' \
|
16
|
+
'involved in a request. pundit_logger adds logging ' \
|
17
|
+
'during many Pundit events to your Rails application logs.'
|
18
|
+
spec.homepage = 'https://github.com/stevehodges/pundit_logger'
|
19
|
+
spec.license = 'MIT'
|
20
|
+
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
24
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
end
|
26
|
+
spec.require_paths = ['lib']
|
27
|
+
spec.add_dependency "pundit", "~> 1.0"
|
28
|
+
spec.add_dependency "rails", "~> 5.0"
|
29
|
+
|
30
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
31
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
32
|
+
spec.add_development_dependency "rspec-rails", "~> 3.0"
|
33
|
+
spec.add_development_dependency "rails", "~> 5.0"
|
34
|
+
spec.add_development_dependency "sqlite3", '~> 1.3', '< 1.4'
|
35
|
+
spec.add_development_dependency "pry"
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,186 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pundit_logger
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Steve Hodges
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-07-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: pundit
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec-rails
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rails
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '5.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '5.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: sqlite3
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '1.3'
|
104
|
+
- - "<"
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '1.4'
|
107
|
+
type: :development
|
108
|
+
prerelease: false
|
109
|
+
version_requirements: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - "~>"
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '1.3'
|
114
|
+
- - "<"
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '1.4'
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: pry
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
type: :development
|
125
|
+
prerelease: false
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
description: Pundit is a lightweight authorization gem. But, in complex Rails apps,
|
132
|
+
it can be difficult to determine why authorization failed, or which policies are
|
133
|
+
involved in a request. pundit_logger adds logging during many Pundit events to your
|
134
|
+
Rails application logs.
|
135
|
+
email:
|
136
|
+
- shodges317@gmail.com
|
137
|
+
executables: []
|
138
|
+
extensions: []
|
139
|
+
extra_rdoc_files: []
|
140
|
+
files:
|
141
|
+
- ".gitignore"
|
142
|
+
- ".rspec"
|
143
|
+
- ".travis.yml"
|
144
|
+
- CODE_OF_CONDUCT.md
|
145
|
+
- Gemfile
|
146
|
+
- LICENSE.txt
|
147
|
+
- README.md
|
148
|
+
- Rakefile
|
149
|
+
- bin/console
|
150
|
+
- bin/setup
|
151
|
+
- lib/generators/pundit_logger/install_generator.rb
|
152
|
+
- lib/pundit_extensions/loggers.rb
|
153
|
+
- lib/pundit_logger.rb
|
154
|
+
- lib/pundit_logger/configuration.rb
|
155
|
+
- lib/pundit_logger/controller_extensions.rb
|
156
|
+
- lib/pundit_logger/log_controller_policy_summary.rb
|
157
|
+
- lib/pundit_logger/log_unauthorized_policies.rb
|
158
|
+
- lib/pundit_logger/logging.rb
|
159
|
+
- lib/pundit_logger/version.rb
|
160
|
+
- lib/templates/default_initializer.rb
|
161
|
+
- pundit_logger.gemspec
|
162
|
+
homepage: https://github.com/stevehodges/pundit_logger
|
163
|
+
licenses:
|
164
|
+
- MIT
|
165
|
+
metadata: {}
|
166
|
+
post_install_message:
|
167
|
+
rdoc_options: []
|
168
|
+
require_paths:
|
169
|
+
- lib
|
170
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
171
|
+
requirements:
|
172
|
+
- - ">="
|
173
|
+
- !ruby/object:Gem::Version
|
174
|
+
version: '0'
|
175
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
176
|
+
requirements:
|
177
|
+
- - ">="
|
178
|
+
- !ruby/object:Gem::Version
|
179
|
+
version: '0'
|
180
|
+
requirements: []
|
181
|
+
rubyforge_project:
|
182
|
+
rubygems_version: 2.6.14
|
183
|
+
signing_key:
|
184
|
+
specification_version: 4
|
185
|
+
summary: Log policy usage in Rails apps which use Pundit
|
186
|
+
test_files: []
|