Class: Masks::Configuration
- Inherits:
-
Object
- Object
- Masks::Configuration
- Includes:
- ActiveModel::Attributes, ActiveModel::Model, ActiveModel::Serializers::JSON, ActiveModel::Validations
- Defined in:
- lib/masks/configuration.rb
Overview
Container for masks configuration data.
Instance Method Summary collapse
-
#access(name) ⇒ Hash
Returns configuration data for the given access name.
-
#access_types ⇒ Hash
Returns configuration data for all access types.
-
#dat ⇒ Object
Returns all configuration data as
RecursiveOpenStruct
. -
#issuer ⇒ String
Returns a string to use as the “issuer” for various secrets—TOTP, JWT, etc.
-
#lifetimes ⇒ Hash
A hash of expiration times for various resources.
-
#mask(type) ⇒ Hash
Returns configuration data for a given mask type.
-
#masks ⇒ Array<Masks::Mask>
Returns all configured masks.
-
#model(name) ⇒ Class
Returns a model
Class
. -
#models ⇒ Hash{Symbol => String}
A hash of default models the app relies on.
-
#openid ⇒ String
Returns a string to use as the “issuer” for various secrets—TOTP, JWT, etc.
-
#signups=(value) ⇒ Object
Setter for whether or not sigups are allowed.
-
#signups? ⇒ Boolean
Whether or not sigups are allowed.
-
#site_links ⇒ Hash
A hash of links—urls to various places on the frontend.
-
#site_logo ⇒ String
Returns the site logo, used for visual identification of the site.
-
#site_name ⇒ String
Returns the site name, used for referring to the site (e.g. in the logo).
-
#site_title ⇒ String
Returns the site title, used primarily in meta tags.
-
#site_url ⇒ String
Returns the canonical url for the site.
-
#theme ⇒ String
Returns a site theme to use on the frontend.
-
#version ⇒ String
Returns the current global session key.
Instance Method Details
#access(name) ⇒ Hash
Returns configuration data for the given access name.
186 187 188 189 190 191 |
# File 'lib/masks/configuration.rb', line 186 def access(name) defaults = Masks::Access.defaults(name) raise Masks::Error::UnknownAccess, name unless defaults defaults.deep_merge(access_types&.fetch(name, {})) end |
#access_types ⇒ Hash
Returns configuration data for all access types.
This does not include defaults created with Masks::Access.access
.
198 199 200 201 202 203 204 |
# File 'lib/masks/configuration.rb', line 198 def access_types data .fetch(:access, {}) .to_h do |name, opts| [name, opts.merge(name:, cls: opts[:cls]&.constantize)] end end |
#dat ⇒ Object
Returns all configuration data as RecursiveOpenStruct
.
31 32 33 |
# File 'lib/masks/configuration.rb', line 31 def dat RecursiveOpenStruct.new(data) end |
#issuer ⇒ String
Returns a string to use as the “issuer” for various secrets—TOTP, JWT, etc.
37 38 39 |
# File 'lib/masks/configuration.rb', line 37 def issuer data.fetch(:name, "masks").parameterize end |
#lifetimes ⇒ Hash
A hash of expiration times for various resources.
These values are used to override expiration times for things like password reset emails and other time-based authentication methods.
116 117 118 119 120 |
# File 'lib/masks/configuration.rb', line 116 def lifetimes (super || dat.lifetimes&.to_h || {}).transform_values do |seconds| seconds.to_i.seconds end end |
#mask(type) ⇒ Hash
Returns configuration data for a given mask type.
159 160 161 162 163 |
# File 'lib/masks/configuration.rb', line 159 def mask(type) config = data.dig(:types, type.to_sym) raise Masks::Error::InvalidConfiguration, type unless config config end |
#masks ⇒ Array<Masks::Mask>
Returns all configured masks.
168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/masks/configuration.rb', line 168 def masks @masks ||= begin masks = super || data.fetch(:masks, []) masks.map do |opts| case opts when Masks::Mask opts when Hash Masks::Mask.new(opts.merge(config: self)) end end end end |
#model(name) ⇒ Class
Returns a model Class
.
151 152 153 |
# File 'lib/masks/configuration.rb', line 151 def model(name) models[name]&.constantize end |
#models ⇒ Hash{Symbol => String}
A hash of default models the app relies on.
This makes it easy to provide a substitute for key models while still relying on the base active record implementation.
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/masks/configuration.rb', line 128 def models { actor: "Masks::Rails::Actor", scope: "Masks::Rails::Scope", role: "Masks::Rails::Role", email: "Masks::Rails::Email", recovery: "Masks::Rails::Recovery", device: "Masks::Rails::Device", key: "Masks::Rails::Key", openid_client: "Masks::Rails::OpenID::Client", openid_access_token: "Masks::Rails::OpenID::AccessToken", openid_id_token: "Masks::Rails::OpenID::IdToken", openid_authorization: "Masks::Rails::OpenID::Authorization", session_json: "Masks::SessionResource", request: "Masks::Sessions::Request", inline: "Masks::Sessions::Inline", access: "Masks::Sessions::Access" }.merge(super || data.fetch(:models, {})) end |
#openid ⇒ String
Returns a string to use as the “issuer” for various secrets—TOTP, JWT, etc.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/masks/configuration.rb', line 73 def openid { scopes: %w[openid profile email address phone], subject_types: %w[nickname email pairwise], response_types: %w[code token id_token], grant_types: %w[ client_credentials authorization_code implicit refresh_token ], pairwise_salt: "masks" }.merge(super || data.fetch(:openid, {})) end |
#signups=(value) ⇒ Object
Setter for whether or not sigups are allowed.
209 210 211 |
# File 'lib/masks/configuration.rb', line 209 def signups=(value) data[:signups] = value end |
#signups? ⇒ Boolean
Whether or not sigups are allowed.
216 217 218 |
# File 'lib/masks/configuration.rb', line 216 def signups? data[:signups] end |
#site_links ⇒ Hash
A hash of links—urls to various places on the frontend.
These default to generated rails routes, but can be overridden where necessary.
94 95 96 97 98 99 100 101 102 |
# File 'lib/masks/configuration.rb', line 94 def site_links { root: rails_url.try(:root_path) || "/", recover: rails_url.recover_path, login: rails_url.session_path, after_login: rails_url.session_path, after_logout: rails_url.session_path }.merge(super || data.fetch(:links, {})) end |
#site_logo ⇒ String
Returns the site logo, used for visual identification of the site.
49 50 51 |
# File 'lib/masks/configuration.rb', line 49 def site_logo super || data.fetch(:logo, nil) end |
#site_name ⇒ String
Returns the site name, used for referring to the site (e.g. in the logo).
55 56 57 |
# File 'lib/masks/configuration.rb', line 55 def site_name super || data.fetch(:name, "masks") end |
#site_title ⇒ String
Returns the site title, used primarily in meta tags.
61 62 63 |
# File 'lib/masks/configuration.rb', line 61 def site_title super || data.fetch(:title, "") end |
#site_url ⇒ String
Returns the canonical url for the site.
67 68 69 |
# File 'lib/masks/configuration.rb', line 67 def site_url super || data.fetch(:url, nil) end |
#theme ⇒ String
Returns a site theme to use on the frontend.
43 44 45 |
# File 'lib/masks/configuration.rb', line 43 def theme super || data.fetch(:theme, "dark") end |
#version ⇒ String
Returns the current global session key.
106 107 108 |
# File 'lib/masks/configuration.rb', line 106 def version super || "v1" end |