Module: Kankri

Defined in:
lib/kankri.rb,
lib/kankri/version.rb,
lib/kankri/exceptions.rb,
lib/kankri/privilege_set.rb,
lib/kankri/password_check.rb,
lib/kankri/privilege_check.rb,
lib/kankri/privilege_subject.rb,
lib/kankri/simple_authenticator.rb

Overview

Exceptions for Kankri.

Defined Under Namespace

Modules: PrivilegeSubject Classes: PasswordCheck, PrivilegeChecker, PrivilegeSet, SimpleAuthenticator

Constant Summary collapse

VERSION =
'0.1.2'
AuthenticationFailure =

Exception generated when authentication fails.

Class.new(RuntimeError)
InsufficientPrivilegeError =

Exception generated when required privileges are missing.

Class.new(RuntimeError)

Class Method Summary collapse

Class Method Details

.authenticator_from_hash(hash) ⇒ Object

Creates an authenticator object from a hash

The hash should map username strings to hashes with the following Symbol keys:

  • password: The plain-text password for the user.

  • privileges: A hash mapping String or Symbol ‘privilege keys’ to either

    the String 'all' or Symbol :all, meaning the user has all privileges
    for that key, or a list of String or Symbol privileges the user has for
    that key.
    

Examples:

Create an authenticator from a hash of users.

Kankri.authenticator_from_hash(
  admin: {
    password: 'hunter2',
    privileges: {
      foo: 'all',
      bar: ['abc', 'def', 'ghi'],
      baz: []
    }
  }
)

Returns:

  • (Object)

    An authenticator for the given hash.



42
43
44
# File 'lib/kankri.rb', line 42

def self.authenticator_from_hash(hash)
  SimpleAuthenticator.new(hash)
end