lib/panda_pal.rb in panda_pal-5.1.0 vs lib/panda_pal.rb in panda_pal-5.2.0

- old
+ new

@@ -5,15 +5,15 @@ module PandaPal class LtiNavigationInUse < StandardError;end class NotMounted < StandardError;end @@lti_navigation = {} - @@staged_navigation = {} @@lti_options = {} @@lti_properties = {} @@lti_environments = {} @@lti_custom_params = {} + @@lti_private_key = nil def self.lti_options= lti_options @@lti_options = lti_options end @@ -43,33 +43,46 @@ def self.lti_custom_params @@lti_custom_params.deep_dup end - def self.register_navigation(navigation) + def self.stage_navigation(navigation, options) @@lti_navigation[navigation] ||= {} + @@lti_navigation[navigation].merge!(options) end - def self.stage_navigation(navigation, options) - @@staged_navigation[navigation] = {} unless @@staged_navigation.has_key?(navigation) - @@staged_navigation[navigation].merge!(options) - end - def self.lti_paths @@lti_navigation.deep_dup end - def self.propagate_lti_navigation - @@staged_navigation.each do |k,v| - lti_navigation(k,v) - @@staged_navigation.delete(k) - end + def self.lti_private_key + key = @@lti_private_key.presence + key ||= ENV['LTI_PRIVATE_KEY'].presence + key ||= File.read(File.join( File.dirname(__FILE__), "../config/dev_lti_key.key")) if Rails.env.development? + return nil unless key.present? + + key = OpenSSL::PKey::RSA.new(key) if key.is_a?(String) + key end + def self.lti_private_key=(v) + @@lti_private_key = k + end + private - def self.lti_navigation(navigation, options) - raise "lti navigation '#{navigation}' has not been registered!" unless @@lti_navigation.has_key?(navigation) - @@lti_navigation[navigation].merge!(options) + def self.validate_pandapal_config! + errors = [] + validate_lti_navigation(errors) + if errors.present? + lines = errors.map { |e| " - #{e}" } + raise "PandaPal was not configured correctly:\n#{lines.join("\n")}" + end end + def self.validate_lti_navigation(errors = []) + @@lti_navigation.each do |k, v| + errors << "lti navigation '#{k}' does not have a Route!" unless (LaunchUrlHelpers.launch_url(k) rescue nil) + end + errors + end end