Module: Masks

Defined in:
lib/masks.rb,
lib/masks/engine.rb,
lib/masks/version.rb,
lib/masks/middleware.rb,
app/models/masks/mask.rb,
app/models/masks/check.rb,
app/models/masks/error.rb,
app/models/masks/event.rb,
app/models/masks/device.rb,
lib/masks/configuration.rb,
app/models/masks/session.rb,
app/models/masks/rails/key.rb,
app/models/masks/credential.rb,
app/models/masks/rails/role.rb,
app/models/masks/rails/actor.rb,
app/models/masks/rails/email.rb,
app/models/masks/rails/scope.rb,
app/models/masks/openid/token.rb,
app/models/masks/rails/device.rb,
app/jobs/masks/application_job.rb,
app/mailers/masks/actor_mailer.rb,
app/models/concerns/masks/role.rb,
app/models/masks/actors/system.rb,
app/models/concerns/masks/actor.rb,
app/models/masks/rails/recovery.rb,
app/jobs/masks/expire_actors_job.rb,
app/models/concerns/masks/access.rb,
app/models/concerns/masks/scoped.rb,
app/models/masks/credentials/key.rb,
app/models/masks/sessions/access.rb,
app/models/masks/sessions/inline.rb,
app/models/concerns/masks/adapter.rb,
app/models/masks/actors/anonymous.rb,
app/models/masks/rails/actor_role.rb,
app/models/masks/sessions/request.rb,
app/models/masks/application_model.rb,
app/models/masks/credentials/email.rb,
app/resources/masks/actor_resource.rb,
app/models/masks/application_record.rb,
app/models/masks/credentials/device.rb,
app/helpers/masks/application_helper.rb,
app/jobs/masks/expire_recoveries_job.rb,
app/mailers/masks/application_mailer.rb,
app/models/masks/access/actor_scopes.rb,
app/models/masks/access/actor_signup.rb,
app/models/masks/credentials/factor2.rb,
app/models/masks/credentials/session.rb,
app/models/masks/rails/openid/client.rb,
app/resources/masks/session_resource.rb,
app/controllers/masks/keys_controller.rb,
app/models/masks/credentials/nickname.rb,
app/models/masks/credentials/password.rb,
app/models/masks/credentials/recovery.rb,
app/models/masks/openid/authorization.rb,
app/controllers/masks/debug_controller.rb,
app/controllers/masks/error_controller.rb,
app/models/masks/access/actor_password.rb,
app/models/masks/credentials/return_to.rb,
app/models/masks/rails/openid/id_token.rb,
app/controllers/masks/actors_controller.rb,
app/controllers/masks/emails_controller.rb,
app/models/masks/adapters/active_record.rb,
app/models/masks/credentials/last_login.rb,
app/models/masks/credentials/masquerade.rb,
app/controllers/masks/devices_controller.rb,
app/models/masks/credentials/backup_code.rb,
app/controllers/concerns/masks/controller.rb,
app/controllers/masks/sessions_controller.rb,
app/models/masks/credentials/access_token.rb,
app/controllers/masks/passwords_controller.rb,
app/models/masks/credentials/one_time_code.rb,
app/models/masks/rails/openid/access_token.rb,
app/controllers/masks/recoveries_controller.rb,
app/models/masks/rails/openid/authorization.rb,
app/controllers/masks/application_controller.rb,
app/controllers/masks/manage/base_controller.rb,
app/controllers/masks/backup_codes_controller.rb,
app/controllers/masks/manage/actors_controller.rb,
app/controllers/masks/one_time_code_controller.rb,
app/controllers/masks/openid/tokens_controller.rb,
lib/generators/masks/install/install_generator.rb,
app/controllers/masks/manage/clients_controller.rb,
app/controllers/masks/manage/devices_controller.rb,
app/controllers/masks/openid/userinfo_controller.rb,
app/controllers/masks/manage/dashboard_controller.rb,
app/controllers/masks/openid/discoveries_controller.rb,
app/controllers/masks/openid/authorizations_controller.rb

Overview

Top-level module for masks.

Includes helper methods for managing configuration and building sessions, access, etc.

Defined Under Namespace

Modules: Access, Actor, Actors, Adapter, Adapters, Controller, Credentials, Error, OpenID, Rails, Role, Scoped, Sessions Classes: ActorResource, ApplicationModel, ApplicationRecord, Check, Configuration, Credential, DebugController, Device, Engine, Event, ExpireActorsJob, ExpireRecoveriesJob, InstallGenerator, Mask, Middleware, Session, SessionResource

Constant Summary collapse

VERSION =
Gem::Version.new("0.4.0")

Class Method Summary collapse

Class Method Details

.access(name, session, **_opts) ⇒ Masks::Access

Returns an access instance based on the type & session passed.

Parameters:

Returns:

Raises:

  • (Masks::Error::Unauthorized)

    if access cannot be granted to the session passed

  • (Masks::UnknownAccess)

    if the access type cannot be found



33
34
35
# File 'lib/masks.rb', line 33

def access(name, session, **_opts)
  configuration.access(name).fetch(:cls).build(session)
end

.configurationMasks::Configuration

Returns the global configuration object for masks.



74
75
76
# File 'lib/masks.rb', line 74

def configuration
  @configuration ||= Masks::Configuration.new(data: config.dup)
end

.configure {|Masks::Configuration| ... } ⇒ Masks::Configuration

Yields the global masks configuration object.



68
69
70
# File 'lib/masks.rb', line 68

def configure
  yield configuration
end

.gem_path(gem_name) ⇒ Object



171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/masks.rb', line 171

def gem_path(gem_name)
  begin
    # Try to require the gem
    require gem_name
  rescue LoadError
    return nil
  end

  # Get the gem specification
  spec = Gem::Specification.find_by_name(gem_name)
  Pathname.new(spec.gem_dir) if spec
end

.load_config(dir) ⇒ Object



167
168
169
# File 'lib/masks.rb', line 167

def load_config(dir)
  JSON.parse(File.read(dir.join("masks.json")), symbolize_names: true)
end

.mask(name, params: {}, **data) {|Masks::Sessions::Inline| ... } ⇒ Masks::Sessions::Inline

Returns a masked session based on the params and data passed.

This method is useful for creating masks directly, outside of a specific context like a web request.

Parameters:

  • params (Hash) (defaults to: {})
  • data (Hash)

Yields:

Returns:



57
58
59
60
61
62
63
# File 'lib/masks.rb', line 57

def mask(name, params: {}, **data)
  model = configuration.model(:inline)
  session = model.new(name:, config: configuration, params:, data:)
  session.mask!
  yield session if session.passed? && block_given?
  session
end

.request(request) ⇒ Masks::Sessions::Request

Returns a masked session based on the request passed.

Parameters:

  • request (ActionDispatch::Request)

Returns:



41
42
43
44
45
46
# File 'lib/masks.rb', line 41

def request(request)
  model = configuration.model(:request)
  session = model.new(config: configuration, request:)
  session.mask!
  session
end