require "panda_pal/engine" require 'panda_pal/plugins' require 'panda_pal/helpers' module PandaPal class LtiNavigationInUse < StandardError;end class NotMounted < StandardError;end @@lti_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 def self.lti_options @@lti_options.deep_dup end def self.lti_properties= lti_properties @@lti_properties = lti_properties end def self.lti_properties @@lti_properties.deep_dup end def self.lti_environments=(lti_environments) @@lti_environments = lti_environments end def self.lti_environments @@lti_environments.deep_dup end def self.lti_custom_params=(custom_params) @@lti_custom_params = custom_params end def self.lti_custom_params @@lti_custom_params.deep_dup end def self.stage_navigation(navigation, options) @@lti_navigation[navigation] ||= {} @@lti_navigation[navigation].merge!(options) end def self.lti_paths @@lti_navigation.deep_dup 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.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