ostiary 0.11.0 → 0.11.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4fb578931e7699371535e5d759d387d36587e922d71e9f4c748cf115ec687af4
4
- data.tar.gz: 6134612b7f338b2a2511ca501e8aa3d6cf0100e6df6f7716fbfccc5cdaf5ddb5
3
+ metadata.gz: 5816e2a27296da2fc83da9d64bb2d5328692bab4b76d0a3e34b30e33e72babe5
4
+ data.tar.gz: 8058838062c1d85b4002aa3c1a9769447252808070ead4e24124d5a538487c16
5
5
  SHA512:
6
- metadata.gz: 52d562092fdd9555ddb5b8e52073c2c6a939aba1b664e9027f97829a45b3ef363d097811ffea88d7351f026f7ccd73c141a4a67c3ea39615083372b5ee9471e2
7
- data.tar.gz: a5f3d43534641beaa6923129a71e8d05da2d707c42ef3ebe9ff7b58527ec681894adf3063f0320dfb7ea2a8e95cb718cbd339c64e1437c27db42ff2f7623c9f2
6
+ metadata.gz: fa26b3d04b56f3a06720a6f97f2c0ca46bcbf9db9c591cdff7c72f4b218c16e69b6774b569bb03079cb9481d632d2e249f4b547944369bab24d09031e07e9f62
7
+ data.tar.gz: 38553e22331617a97097f9cba9704758e18986ff8399846a13758ccfee0b7fa5305290c721cf2277e4f9001b0f4d31d39c58125d114226deaa43b9c9771a322a
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ostiary
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.11.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jacques Hakvoort
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-11 00:00:00.000000000 Z
11
+ date: 2021-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.13'
19
+ version: 2.2.10
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.13'
26
+ version: 2.2.10
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: 12.3.3
34
34
  type: :development
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: '10.0'
40
+ version: 12.3.3
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -80,29 +80,12 @@ email:
80
80
  executables: []
81
81
  extensions: []
82
82
  extra_rdoc_files: []
83
- files:
84
- - ".circleci/config.yml"
85
- - ".gitignore"
86
- - ".rspec"
87
- - ".ruby-gemset"
88
- - ".ruby-version"
89
- - Gemfile
90
- - LICENSE.txt
91
- - README.md
92
- - Rakefile
93
- - lib/ostiary.rb
94
- - lib/ostiary/controller_helper.rb
95
- - lib/ostiary/ostiary.rb
96
- - lib/ostiary/policy.rb
97
- - lib/ostiary/policy_exempted.rb
98
- - lib/ostiary/policy_limited.rb
99
- - lib/ostiary/version.rb
100
- - ostiary.gemspec
83
+ files: []
101
84
  homepage: https://github.com/nedap/ostiary
102
85
  licenses:
103
86
  - MIT
104
87
  metadata: {}
105
- post_install_message:
88
+ post_install_message:
106
89
  rdoc_options: []
107
90
  require_paths:
108
91
  - lib
@@ -117,8 +100,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
100
  - !ruby/object:Gem::Version
118
101
  version: '0'
119
102
  requirements: []
120
- rubygems_version: 3.0.3
121
- signing_key:
103
+ rubygems_version: 3.0.3.1
104
+ signing_key:
122
105
  specification_version: 4
123
106
  summary: Limit access to (rails) controllers/actions with policies
124
107
  test_files: []
data/.circleci/config.yml DELETED
@@ -1,42 +0,0 @@
1
- version: 2
2
- jobs:
3
- build:
4
- docker:
5
- - image: circleci/ruby:2.6.5
6
-
7
- working_directory: ~/repo
8
-
9
- steps:
10
- - checkout
11
-
12
- - restore_cache:
13
- keys:
14
- - v1-dependencies-{{ checksum "Gemfile.lock" }}
15
- - v1-dependencies-
16
-
17
- - run:
18
- name: install dependencies
19
- command: |
20
- bundle install --jobs=4 --retry=3 --path vendor/bundle
21
-
22
- - save_cache:
23
- paths:
24
- - ./vendor/bundle
25
- key: v1-dependencies-{{ checksum "Gemfile.lock" }}
26
-
27
- - run:
28
- name: run tests
29
- command: |
30
- mkdir /tmp/test-results
31
- TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | \
32
- circleci tests split --split-by=timings)"
33
-
34
- bundle exec rspec \
35
- --format progress \
36
- --format RspecJunitFormatter \
37
- --out /tmp/test-results/rspec.xml \
38
- --format progress \
39
- $TEST_FILES
40
-
41
- - store_test_results:
42
- path: /tmp/test-results
data/.gitignore DELETED
@@ -1,53 +0,0 @@
1
- *.gem
2
- *.rbc
3
- .rspec_status
4
- /.config
5
- /coverage/
6
- /InstalledFiles
7
- /pkg/
8
- /spec/reports/
9
- /spec/examples.txt
10
- /test/tmp/
11
- /test/version_tmp/
12
- /tmp/
13
-
14
- # Used by dotenv library to load environment variables.
15
- # .env
16
-
17
- ## Specific to RubyMotion:
18
- .dat*
19
- .repl_history
20
- build/
21
- *.bridgesupport
22
- build-iPhoneOS/
23
- build-iPhoneSimulator/
24
-
25
- ## Specific to RubyMotion (use of CocoaPods):
26
- #
27
- # We recommend against adding the Pods directory to your .gitignore. However
28
- # you should judge for yourself, the pros and cons are mentioned at:
29
- # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
30
- #
31
- # vendor/Pods/
32
-
33
- ## Documentation cache and generated files:
34
- /.yardoc/
35
- /_yardoc/
36
- /doc/
37
- /rdoc/
38
-
39
- ## Environment normalization:
40
- /.bundle/
41
- /vendor/bundle
42
- /lib/bundler/man/
43
-
44
- # for a library or gem, you might want to ignore these files since the code is
45
- # intended to run in multiple environments; otherwise, check them in:
46
- Gemfile.lock
47
- # .ruby-version
48
- # .ruby-gemset
49
-
50
- # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
51
- .rvmrc
52
-
53
- .DS_Store
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --color
2
- --format documentation
3
- --profile
data/.ruby-gemset DELETED
@@ -1 +0,0 @@
1
- ostiary
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- ruby-2.3.5
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in ostiary.gemspec
4
- gemspec
data/LICENSE.txt DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2017 Nedap
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 all
13
- 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 THE
21
- SOFTWARE.
data/README.md DELETED
@@ -1,94 +0,0 @@
1
- # Ostiary
2
-
3
- An ostiarius, a Latin word sometimes anglicized as ostiary but often literally translated as porter or doorman, originally was a servant or guard posted at the entrance of a building. See also gatekeeper.
4
-
5
- ## Functionality
6
-
7
- [![CircleCI Status](https://circleci.com/gh/nedap/ostiary.svg?style=svg)](https://circleci.com/gh/nedap/ostiary)
8
-
9
- This gem will help you enforce 'policies' when viewing controllers/actions.
10
- This is done by requiring certain roles for controllers, where you can
11
- optionally include or exclude certain actions.
12
-
13
- ## Installation
14
-
15
- Add this line to your application's Gemfile:
16
-
17
- ```ruby
18
- gem 'ostiary'
19
- ```
20
-
21
- And then execute:
22
-
23
- $ bundle
24
-
25
- Or install it yourself as:
26
-
27
- $ gem install ostiary
28
-
29
- ## Usage
30
-
31
- ### Primary setup
32
-
33
- In your base Controller class do the following for Rails:
34
-
35
- ```ruby
36
- # This class creates a class accessor called :ostiary on each (inherited) controller.
37
- # With each controller created, it will stack the policies you add
38
- include Ostiary::ControllerHelper
39
-
40
- before_filter :ensure_authorized!
41
-
42
- # Because each ostiary is unique for a controller, you only have to supply the current action.
43
- # With this, it can check if there are certain policies that will be broken.
44
- def ensure_authorized!
45
- self.class.ostiary.authorize!(action) do |name|
46
- # Your authorization method using name.
47
- # e.g. `current_user.has_right?(name)`
48
- end
49
- rescue Ostiary::PolicyBroken => error
50
- # We re-raise the Error as a RoutingError in Rails
51
- # You can also do `return head :forbidden` if that's more in line with your needs.
52
- raise ActionController::RoutingError.new(error.message)
53
- end
54
- ```
55
-
56
- ### Securing controllers
57
-
58
- In each controller you wish to secure, you can call `ostiary_policy`, just like `before_filter` & `after_filter` of Rails.
59
-
60
- ```ruby
61
- # Require the :list role on the entire controller
62
- ostiary_policy :list
63
-
64
- # Require the :view role only on the index & show actions
65
- ostiary_policy :view, only: [:index, :show]
66
-
67
- # Require the :edit role except on the index & show actions
68
- ostiary_policy :edit, except: [:index, :show]
69
- ```
70
-
71
- These policies will be added to the ostiary instance created for each Controller Class. It will also include each policy inherited from parent classes.
72
-
73
- ### Checking for a right
74
-
75
- You can also ask if a user is authorized to access to a certain path (url).
76
-
77
- in your Controller:
78
-
79
- ```ruby
80
- def authorized?(path)
81
- # recognize_path is a Rails Routing helper that will return a hash with the controller
82
- # and action of the path you supplied. We'll have to transform that String of the
83
- # controller into an actual Class.
84
- return false unless route = Rails.application.routes.recognize_path(path)
85
- requested_controller = "#{route[:controller]}_controller".camelize.constantize
86
- requested_controller.ostiary.authorized?(route[:action]) do |role|
87
- # Your authorization method using name.
88
- end
89
- end
90
- ```
91
-
92
- ## License
93
-
94
- ostiary is Copyright 2017 nedap and released under the MIT license which you should find included in the [LICENSE.txt](LICENSE.txt) file.
data/Rakefile DELETED
@@ -1,6 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
-
4
- RSpec::Core::RakeTask.new(:spec)
5
-
6
- task :default => :spec
data/lib/ostiary.rb DELETED
@@ -1,10 +0,0 @@
1
- require "ostiary/version"
2
- require "ostiary/ostiary"
3
- require "ostiary/policy"
4
- require "ostiary/policy_limited"
5
- require "ostiary/policy_exempted"
6
- require "ostiary/controller_helper"
7
-
8
- module Ostiary
9
- class PolicyBroken < StandardError; end
10
- end
@@ -1,52 +0,0 @@
1
- module Ostiary
2
- module ControllerHelper
3
-
4
- def self.included(base)
5
- base.extend(ClassMethods)
6
- end
7
-
8
- module ClassMethods
9
-
10
- def inherited(subclass)
11
- subclass.ostiary.policies += self.ostiary.policies
12
- super
13
- end
14
-
15
- def ostiary
16
- @ostiary ||= Ostiary.new
17
- end
18
-
19
- def required_application_role(role, actions = {})
20
- warn "[DEPRECATION] `required_application_role` is deprecated. Please use `ostiary_policy` instead."
21
- ostiary_policy(role, actions)
22
- end
23
-
24
- # We want to give the option of setting a policy for one action, based on ::Role
25
- # So we'll copy the way the filters in controllers work.
26
- # Only apply the role to certain action(s)
27
- # only: [*actions]
28
- # Exclude action(s) from requiring a role
29
- # except: [*actions]
30
- # By default a given role will be required for every action
31
- # Override role checking by passing a symbol as method;
32
- # ostiary_policy method: :master?, only: :show
33
- # One line creates one policy, which are immediately created with the proper class
34
- def ostiary_policy(role = nil, only: nil, except: nil, method: nil)
35
- raise ArgumentError, "Use at least role or method" unless method || role
36
- raise ArgumentError, "Use either role or method" if method && role
37
- raise ArgumentError, "Use either only or except" if except && only
38
- raise ArgumentError, "Use a symbol for method:" if method && !(method.is_a? Symbol)
39
-
40
- if actions.empty?
41
- ostiary.policies << Policy.new(role, method: method&.to_proc)
42
- elsif only
43
- ostiary.policies << PolicyLimited.new(role, only, method: method&.to_proc)
44
- elsif except
45
- ostiary.policies << PolicyExempted.new(role, except, method: method&.to_proc)
46
- end
47
- end
48
-
49
- end
50
-
51
- end
52
- end
@@ -1,23 +0,0 @@
1
- module Ostiary
2
- class Ostiary
3
- attr_accessor :policies
4
-
5
- def initialize
6
- @policies = []
7
- end
8
-
9
- def authorize!(action, &block)
10
- policies.each do |policy|
11
- next if policy.met?(action, block)
12
- raise PolicyBroken, policy.error_message(action)
13
- end
14
- end
15
-
16
- def authorized?(action, &block)
17
- policies.all? do |policy|
18
- policy.met?(action, block)
19
- end
20
- end
21
-
22
- end
23
- end
@@ -1,25 +0,0 @@
1
- module Ostiary
2
- class Policy
3
- attr_reader :name, :method, :actions
4
-
5
- def initialize(name, actions = [], method: nil)
6
- @name = name
7
- @method = method
8
- @actions = actions
9
- end
10
-
11
- def inspect
12
- "#{name}"
13
- end
14
-
15
- def met?(_action)
16
- return yield name unless method
17
- method.call
18
- end
19
-
20
- def error_message(action)
21
- "#{action} requires #{name}"
22
- end
23
-
24
- end
25
- end
@@ -1,18 +0,0 @@
1
- module Ostiary
2
- class PolicyExempted < Policy
3
-
4
- def inspect
5
- "#{name} except for #{actions.to_sentence}"
6
- end
7
-
8
- def met?(action)
9
- return true if actions.include?(action)
10
- super
11
- end
12
-
13
- def error_message(action)
14
- "#{action} not exempted for #{name}"
15
- end
16
-
17
- end
18
- end
@@ -1,18 +0,0 @@
1
- module Ostiary
2
- class PolicyLimited < Policy
3
-
4
- def inspect
5
- "#{name} only for #{actions.to_sentence}"
6
- end
7
-
8
- def met?(action)
9
- return true unless actions.include?(action)
10
- super
11
- end
12
-
13
- def error_message(action)
14
- "#{action} limited by #{name}"
15
- end
16
-
17
- end
18
- end
@@ -1,3 +0,0 @@
1
- module Ostiary
2
- VERSION = "0.11.0"
3
- end
data/ostiary.gemspec DELETED
@@ -1,36 +0,0 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'ostiary/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "ostiary"
8
- spec.version = Ostiary::VERSION
9
- spec.author = "Jacques Hakvoort"
10
- spec.authors = ["Jacques Hakvoort"]
11
- spec.email = ["jacques.hakvoort@nedap.com"]
12
-
13
- spec.homepage = "https://github.com/nedap/ostiary"
14
- spec.summary = "Limit access to (rails) controllers/actions with policies"
15
- spec.description = <<-TXT;
16
- Ostiary is a security gem for your (rails) controllers & actions.
17
- It employs a before_filter-like call to set policies per controller/action.
18
- You can pass your own security call in block and handle the PolicyBroken
19
- yourself.
20
- Policies are also inherited from parent classes.
21
- From wikipedia: "An ostiarius, a Latin word sometimes anglicized as ostiary
22
- but often literally translated as porter or doorman, originally was a
23
- servant or guard posted at the entrance of a building. See also gatekeeper."
24
- TXT
25
- spec.license = 'MIT'
26
-
27
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
28
- f.match(%r{^(test|spec|features)/})
29
- end
30
- spec.require_paths = ["lib"]
31
-
32
- spec.add_development_dependency "bundler", "~> 1.13"
33
- spec.add_development_dependency "rake", "~> 10.0"
34
- spec.add_development_dependency "rspec", "~> 3.0"
35
- spec.add_development_dependency 'rspec_junit_formatter'
36
- end