Skip to content

Commit

Permalink
Compatibility with older and newer versions of psych gem
Browse files Browse the repository at this point in the history
  • Loading branch information
elohanlon committed Jan 10, 2024
1 parent e5651dd commit 38dabab
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 3 additions & 1 deletion app/models/concerns/cul/omniauth/abilities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ def config
@role_proxy_config ||= begin
root = (Rails.root.blank?) ? '.' : Rails.root
path = File.join(root,'config','roles.yml')
_opts = YAML.load_file(path)
# We'll use YAML loading logic similar to Rails 7, for older and newer psych gem compatibility
# https://github.com/rails/rails/blob/7-1-stable/activesupport/lib/active_support/encrypted_configuration.rb#L99
_opts = YAML.respond_to?(:unsafe_load) ? YAML.unsafe_load(path) : YAML.load(path)
all_config = _opts.fetch("_all_environments", {})
env_config = _opts.fetch(Rails.env, {})
symbolize_hash_keys(all_config.merge(env_config))
Expand Down
6 changes: 5 additions & 1 deletion lib/cul/omniauth/file_configurable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ module Cul::Omniauth::FileConfigurable
module ClassMethods
def cas_configuration_opts
@cas_opts ||= begin
_opts = YAML.load_file(File.join(Rails.root,'config','cas.yml'))[Rails.env] || {}
conf_path = File.join(Rails.root,'config','cas.yml')
# We'll use YAML loading logic similar to Rails 7, for older and newer psych gem compatibility
# https://github.com/rails/rails/blob/7-1-stable/activesupport/lib/active_support/encrypted_configuration.rb#L99
conf = YAML.respond_to?(:unsafe_load) ? YAML.unsafe_load(conf_path) : YAML.load(conf_path)
_opts = conf[Rails.env] || {}
_opts = _opts.symbolize_keys
_opts
end
Expand Down

0 comments on commit 38dabab

Please sign in to comment.