checkpoint 0.2.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +7 -0
  2. data/.envrc +1 -0
  3. data/.gitignore +18 -9
  4. data/.rspec +2 -0
  5. data/.rubocop.yml +30 -0
  6. data/.travis.yml +5 -0
  7. data/.yardopts +1 -0
  8. data/Gemfile +5 -1
  9. data/LICENSE.md +27 -0
  10. data/README.md +23 -0
  11. data/Rakefile +14 -0
  12. data/bin/console +18 -0
  13. data/bin/rake +21 -0
  14. data/bin/rspec +21 -0
  15. data/bin/sequel +21 -0
  16. data/bin/setup +8 -0
  17. data/bin/yard +21 -0
  18. data/bin/yardoc +21 -0
  19. data/checkpoint.gemspec +37 -19
  20. data/db/migrations/1_create_permits.rb +19 -0
  21. data/docs/Makefile +24 -0
  22. data/docs/_static/.gitkeep +0 -0
  23. data/docs/_templates/.gitkeep +0 -0
  24. data/docs/authentication.rst +18 -0
  25. data/docs/conf.py +46 -0
  26. data/docs/index.rst +28 -0
  27. data/docs/policies.rst +211 -0
  28. data/docs/requirements.txt +4 -0
  29. data/lib/checkpoint.rb +16 -2
  30. data/lib/checkpoint/agent.rb +93 -0
  31. data/lib/checkpoint/agent/resolver.rb +33 -0
  32. data/lib/checkpoint/agent/token.rb +52 -0
  33. data/lib/checkpoint/authority.rb +67 -0
  34. data/lib/checkpoint/credential.rb +82 -0
  35. data/lib/checkpoint/credential/permission.rb +27 -0
  36. data/lib/checkpoint/credential/resolver.rb +87 -0
  37. data/lib/checkpoint/credential/role.rb +26 -0
  38. data/lib/checkpoint/credential/token.rb +51 -0
  39. data/lib/checkpoint/db.rb +161 -0
  40. data/lib/checkpoint/db/permit.rb +24 -0
  41. data/lib/checkpoint/permission_mapper.rb +29 -0
  42. data/lib/checkpoint/permits.rb +133 -0
  43. data/lib/checkpoint/query.rb +42 -0
  44. data/lib/checkpoint/query/action_permitted.rb +40 -0
  45. data/lib/checkpoint/query/role_granted.rb +55 -0
  46. data/lib/checkpoint/railtie.rb +92 -71
  47. data/lib/checkpoint/resource.rb +138 -0
  48. data/lib/checkpoint/resource/all_of_any_type.rb +34 -0
  49. data/lib/checkpoint/resource/all_of_type.rb +50 -0
  50. data/lib/checkpoint/resource/any_entity.rb +25 -0
  51. data/lib/checkpoint/resource/any_entity_of_type.rb +29 -0
  52. data/lib/checkpoint/resource/resolver.rb +21 -0
  53. data/lib/checkpoint/resource/token.rb +65 -0
  54. data/lib/checkpoint/version.rb +3 -1
  55. data/lib/tasks/migrate.rake +75 -0
  56. metadata +260 -19
  57. data/Readme.markdown +0 -103
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6a1c461fe8389571e1850b62a87c9d0db9ade53e
4
+ data.tar.gz: 2854266ee72cf25d1e789aed12eb63e27e7436a5
5
+ SHA512:
6
+ metadata.gz: cea376e3ab91a65d63e86b64b7eddd54ea4edbf5a403763e099a334ca1546454b3e4d86a666cafa56e4b1db7c663a8d89ed4f52a890b358975e3f8f071851ae2
7
+ data.tar.gz: ae1c1b1bdb8bfe5705ede2d5d4478a8888884200307008206e80680b49f75785ed8d02d02a13856c9a137b559a204807fc46910a27a2b7dde054c61e97d0e4a3
data/.envrc ADDED
@@ -0,0 +1 @@
1
+ PATH_add bin
data/.gitignore CHANGED
@@ -1,10 +1,19 @@
1
- *.gem
2
- .bundle
1
+ /.bundle/
2
+ /coverage/
3
+ /doc/
4
+ /pkg/
5
+ /spec/reports/
6
+ /tmp/
7
+
8
+ /db/checkpoint.log
9
+ /db/checkpoint.yml
10
+ /db/*.sqlite3
3
11
  Gemfile.lock
4
- pkg/*
5
- *.swp
6
- *.swo
7
- *.swn
8
- *.~
9
- *swp
10
- *~
12
+
13
+ # rspec failure tracking
14
+ .rspec_status
15
+
16
+ # Docs generated by YARD and Sphinx
17
+ /.yardoc/
18
+ /docs/_build/
19
+ /docs/_yard/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
@@ -0,0 +1,30 @@
1
+ Rails:
2
+ Enabled: true
3
+
4
+ Rails/Delegate:
5
+ Enabled: false
6
+
7
+ # inherit_gem:
8
+ # rubocop-rails:
9
+ # - config/rails.yml
10
+
11
+ AllCops:
12
+ DisplayCopNames: true
13
+ TargetRubyVersion: 2.4
14
+ Exclude:
15
+ - 'bin/**/*'
16
+ - 'vendor/**/*'
17
+
18
+ Layout/MultilineMethodDefinitionBraceLayout:
19
+ EnforcedStyle: same_line
20
+
21
+ Metrics/LineLength:
22
+ Max: 110
23
+
24
+ Metrics/BlockLength:
25
+ Exclude:
26
+ - '*.gemspec'
27
+ ExcludedMethods: ['describe', 'context', 'xdescribe', 'xcontext']
28
+
29
+ Style/StringLiterals:
30
+ Enabled: false
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.2
5
+ before_install: gem install bundler -v 1.16.0
@@ -0,0 +1 @@
1
+ --output-dir ./docs/_yard
data/Gemfile CHANGED
@@ -1,4 +1,8 @@
1
- source "http://rubygems.org"
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
2
6
 
3
7
  # Specify your gem's dependencies in checkpoint.gemspec
4
8
  gemspec
@@ -0,0 +1,27 @@
1
+ Copyright (c) 2018, The Regents of the University of Michigan.
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are
6
+ met:
7
+
8
+ * Redistributions of source code must retain the above copyright
9
+ notice, this list of conditions and the following disclaimer.
10
+ * Redistributions in binary form must reproduce the above copyright
11
+ notice, this list of conditions and the following disclaimer in the
12
+ documentation and/or other materials provided with the distribution.
13
+ * Neither the name of the The University of Michigan nor the
14
+ names of its contributors may be used to endorse or promote products
15
+ derived from this software without specific prior written permission.
16
+
17
+ THIS SOFTWARE IS PROVIDED BY THE REGENTS OF THE UNIVERSITY OF MICHIGAN AND
18
+ CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
19
+ NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OF THE
21
+ UNIVERSITY OF MICHIGAN BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
23
+ TO,PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
27
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,23 @@
1
+ [![Build Status](https://travis-ci.org/mlibrary/checkpoint.svg?branch=master)](https://travis-ci.org/mlibrary/checkpoint?branch=master)
2
+ [![Coverage Status](https://coveralls.io/repos/github/mlibrary/checkpoint/badge.svg?branch=master)](https://coveralls.io/github/mlibrary/checkpoint?branch=master)
3
+
4
+ # Checkpoint
5
+
6
+ Checkpoint provides a model and infrastructure for policy-based authorization,
7
+ especially in Rails applications.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'checkpoint'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ ## License
22
+
23
+ Checkpoint is licensed under the BSD-3-Clause license. See [LICENSE.md](LICENSE.md).
data/Rakefile CHANGED
@@ -1 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ load 'lib/tasks/migrate.rake'
9
+
10
+ task default: :spec
11
+
12
+ task :docs do
13
+ sh %( bin/yard )
14
+ sh %( cd docs && make html )
15
+ end
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "checkpoint"
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
+ def init!
10
+ Checkpoint::DB.initialize!
11
+ Object.const_set(:DB, Checkpoint::DB.db)
12
+ end
13
+
14
+ require "pry"
15
+ Pry.start
16
+
17
+ # require "irb"
18
+ # IRB.start(__FILE__)
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rake' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
12
+ load(bundle_binstub) if File.file?(bundle_binstub)
13
+
14
+ require "pathname"
15
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
16
+ Pathname.new(__FILE__).realpath)
17
+
18
+ require "rubygems"
19
+ require "bundler/setup"
20
+
21
+ load Gem.bin_path("rake", "rake")
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rspec' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
12
+ load(bundle_binstub) if File.file?(bundle_binstub)
13
+
14
+ require "pathname"
15
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
16
+ Pathname.new(__FILE__).realpath)
17
+
18
+ require "rubygems"
19
+ require "bundler/setup"
20
+
21
+ load Gem.bin_path("rspec-core", "rspec")
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'sequel' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
12
+ load(bundle_binstub) if File.file?(bundle_binstub)
13
+
14
+ require "pathname"
15
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
16
+ Pathname.new(__FILE__).realpath)
17
+
18
+ require "rubygems"
19
+ require "bundler/setup"
20
+
21
+ load Gem.bin_path("sequel", "sequel")
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'yard' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
12
+ load(bundle_binstub) if File.file?(bundle_binstub)
13
+
14
+ require "pathname"
15
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
16
+ Pathname.new(__FILE__).realpath)
17
+
18
+ require "rubygems"
19
+ require "bundler/setup"
20
+
21
+ load Gem.bin_path("yard", "yard")
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'yardoc' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
12
+ load(bundle_binstub) if File.file?(bundle_binstub)
13
+
14
+ require "pathname"
15
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
16
+ Pathname.new(__FILE__).realpath)
17
+
18
+ require "rubygems"
19
+ require "bundler/setup"
20
+
21
+ load Gem.bin_path("yard", "yardoc")
@@ -1,25 +1,43 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path("../lib", __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
5
  require "checkpoint/version"
4
6
 
5
- Gem::Specification.new do |s|
6
- s.name = "checkpoint"
7
- s.version = Checkpoint::VERSION
8
- s.authors = ["Leanbid LTD"]
9
- s.email = ["it@leanbid.com"]
10
- s.homepage = "https://github.com/digitalfrost/checkpoint"
11
- s.summary = "Simple rails authorisation"
12
- #s.description = %q{TODO: Write a gem description}
13
- s.license = "MIT"
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "checkpoint"
9
+ spec.version = Checkpoint::VERSION
10
+ spec.authors = ["Noah Botimer"]
11
+ spec.email = ["botimer@umich.edu"]
12
+ spec.license = "BSD-3-Clause"
13
+
14
+ spec.summary = <<~SUMMARY
15
+ Checkpoint provides a model and infrastructure for policy-based authorization,
16
+ especially in Rails applications.
17
+ SUMMARY
18
+
19
+ spec.homepage = "https://github.com/mlibrary/checkpoint"
14
20
 
15
- s.rubyforge_project = "checkpoint"
21
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
22
+ f.match(%r{^(test|spec|features)/})
23
+ end
24
+ spec.bindir = "exe"
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ["lib"]
16
27
 
17
- s.files = `git ls-files`.split("\n")
18
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
- s.require_paths = ["lib"]
28
+ spec.add_dependency "ettin", "~> 1.1"
29
+ spec.add_dependency "mysql2", "~> 0.4.10"
30
+ spec.add_dependency "sequel", "~> 5.6"
21
31
 
22
- # specify any dependencies here; for example:
23
- # s.add_development_dependency "rspec"
24
- # s.add_runtime_dependency "rest-client"
32
+ spec.add_development_dependency "bundler", "~> 1.16"
33
+ spec.add_development_dependency "coveralls", "~> 0.8"
34
+ spec.add_development_dependency "pry"
35
+ spec.add_development_dependency "pry-byebug"
36
+ spec.add_development_dependency "rake", "~> 10.0"
37
+ spec.add_development_dependency "rspec", "~> 3.0"
38
+ spec.add_development_dependency "rubocop", "~> 0.52"
39
+ spec.add_development_dependency "rubocop-rails", "~> 1.1"
40
+ spec.add_development_dependency "rubocop-rspec", "~> 1.16"
41
+ spec.add_development_dependency "sqlite3", "~> 1.3"
42
+ spec.add_development_dependency "yard", "~> 0.9"
25
43
  end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ Sequel.migration do
4
+ change do
5
+ create_table :permits do
6
+ primary_key :id
7
+ column :agent_type, String, size: 100, null: false
8
+ column :agent_id, String, size: 100, null: false
9
+ column :agent_token, String, size: 201, null: false
10
+ column :credential_type, String, size: 100, null: false
11
+ column :credential_id, String, size: 100, null: false
12
+ column :credential_token, String, size: 201, null: false
13
+ column :resource_type, String, size: 100, null: false
14
+ column :resource_id, String, size: 100, null: false
15
+ column :resource_token, String, size: 201, null: false
16
+ column :zone_id, String, size: 100, null: false
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,24 @@
1
+ # Minimal makefile for Sphinx documentation
2
+ #
3
+
4
+ # You can set these variables from the command line.
5
+ SPHINXOPTS =
6
+ SPHINXBUILD = sphinx-build
7
+ SPHINXPROJ = Checkpoint
8
+ AUTOBUILD = sphinx-autobuild
9
+ SOURCEDIR = .
10
+ BUILDDIR = _build
11
+
12
+ # Put it first so that "make" without argument is like "make help".
13
+ help:
14
+ @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
15
+
16
+ auto:
17
+ @$(AUTOBUILD) ${@:2} "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
18
+
19
+ .PHONY: auto help Makefile
20
+
21
+ # Catch-all target: route all unknown targets to Sphinx using the new
22
+ # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
23
+ %: Makefile
24
+ @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
File without changes
File without changes
@@ -0,0 +1,18 @@
1
+ Identity and Authentication
2
+ ===========================
3
+
4
+ Users can be identified in any number of ways and carry with them various
5
+ attributes that determine the entirety of "who they are". Our typical needs
6
+ include identifying a person by username or email address, and building a
7
+ profile of attributes such as geographical region (as determined by IP address),
8
+ or University status (student, staff, etc.). The identifiers and attributes are
9
+ intrinsic to the user and do not, by themselves, grant any permissions within
10
+ an application. Likewise, these attributes cannot be granted within an
11
+ application, only inspected.
12
+
13
+ A&E will continue to provide the identity and attributes of users. The
14
+ specifics of whether this will be implemented with environment variables,
15
+ HTTP headers, SAML, or other means is to be determined. An application is
16
+ not expected to implement its own login process except to the degree that
17
+ it can recognize the required authentication information provided to it.
18
+
@@ -0,0 +1,46 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ import guzzle_sphinx_theme
4
+ from recommonmark.parser import CommonMarkParser
5
+
6
+ # -- General configuration ------------------------------------------------
7
+ project = u'Checkpoint'
8
+ copyright = u'2017, Regents of the University of Michigan'
9
+ author = u'Noah Botimer'
10
+ version = u'0.1.0'
11
+ release = u'0.1.0'
12
+
13
+
14
+ extensions = ['guzzle_sphinx_theme']
15
+ templates_path = ['_templates']
16
+ master_doc = 'index'
17
+
18
+ source_parsers = {
19
+ '.md': CommonMarkParser,
20
+ }
21
+ source_suffix = ['.rst', '.md']
22
+
23
+ language = None
24
+ exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
25
+ pygments_style = 'sphinx'
26
+ todo_include_todos = False
27
+
28
+
29
+ # -- Options for HTML output ----------------------------------------------
30
+ html_theme_path = guzzle_sphinx_theme.html_theme_path()
31
+ html_theme = 'guzzle_sphinx_theme'
32
+ html_static_path = ['_static']
33
+
34
+ # Guzzle theme options (see theme.conf for more information)
35
+ html_theme_options = {
36
+ "project_nav_name": "Checkpoint",
37
+ }
38
+
39
+ html_sidebars = {
40
+ '**': [
41
+ 'logo-text.html',
42
+ 'globaltoc.html',
43
+ 'searchbox.html',
44
+ ]
45
+ }
46
+