require "rails_connector/blob" module RailsConnector # @api public class Configuration # # Default path of a CA certification file in PEM format. # # @api public DEFAULT_CA_FILE = File.expand_path('../../../config/ca-bundle.crt', __FILE__) class << self # Determine if current visitor is permitted to edit content. attr_accessor :editing_auth_callback # Configure a callback to be invoked when the rails connector determines, # if current visitor is permitted to edit content. # Default is false. # # Example Usage: # RailsConnector::Configuation.editing_auth do |env| # request = Rack::Request.new(env) # # return truey if current visitor is permitted to edit content, falsy otherwise # end # @api public def editing_auth(&block) if block.respond_to?(:arity) && block.arity == 1 self.editing_auth_callback = block else raise ArgumentError, 'editing_auth should have only one attribute!' end end # TODO: Legacy compatiblity. Remove when DisplayHelper gets removed. def editor_interface_enabled? false end # The +RailsConnector+ makes heavy use of filesystem caching. # Use this method to configure the directory that should be used to store cached data. # By default, +RAILS_ROOT/tmp/infopark_cache+ will be used. # @param path [String] Path to directory that should be used to store cached data. # @example Configure +RailsConnector+ to store its cache under +/tmp/my_cache+. # RailsConnector::Configuration.cache_path = '/tmp/my_cache' # @api public def cache_path=(path) CmsCacheStorage.backend_cache = ActiveSupport::Cache::FileStore.new(path) end # Gets path of a CA certification file in PEM format. # @api public attr_reader :ca_file # Sets path of a CA certification file in PEM format. # The file can contain several CA certificates. # Certifications will be used for endpoint peer verification of various Infopark services # e.g. Content Read Service. # @api public def ca_file=(path) File.read(path) if path # Try to read the given file and fail if it doesn't exist or is not readable. @ca_file = path end # Configuration for Content Read Service API. # @api public def content_service_url content_service.url end # Set url configuration for Content Read Service API. # @api public def content_service_url=(value) content_service.url = value end # Configuration for Content Read Service API. # @api public def content_service_login content_service.login end # Set login configuration for Content Read Service API. # @api public def content_service_login=(value) content_service.login = value end # Configuration for Content Read Service API. # @api public def content_service_api_key content_service.api_key end # Set API key configuration for Content Read Service API. # @api public def content_service_api_key=(value) content_service.api_key = value end # Url configuration for CMS Rest API. # @api public def cms_url cms_api.url end # Set url configuration for CMS Rest API. # @api public def cms_url=(value) cms_api.url = value end # Login configuration for CMS Rest API. # @api public def cms_login cms_api.login end # Set login configuration for CMS Rest API. # @api public def cms_login=(value) cms_api.login = value end # API key configuration for CMS Rest API. # @api public def cms_api_key cms_api.api_key end # Set API key configuration for CMS Rest API. # @api public def cms_api_key=(value) cms_api.api_key = value end def to_prepare unless Rails.configuration.cache_classes NamedLink.reset_cache BasicObj.reset_type_computer! BasicWidget.reset_type_computer! ::ApplicationController.__send__(:helper, :cms) end end def configure_cms_database end attr_accessor :choose_homepage_callback # Configure a callback to be invoked when the rails connector delivers the homepage. # The given callback will receive the rack env # and must return an {BasicObj Obj} to be used as the homepage. # If no callback is configured, {BasicObj.homepage Obj.homepage} will be used as the default. # @api public def choose_homepage(&block) self.choose_homepage_callback = block end def cms_routes(*args) raise <<-EOS.gsub(/\s+/, ' ') Calling RailsConnector::Configuration.cms_routes is not needed anymore. Please remove it from config/routes.rb EOS end def use_x_sendfile=(value) raise 'Configuration.use_x_sendfile is now available as Rails configuration:'\ ' config.action_dispatch.x_sendfile_header = "X-Sendfile"' end private def content_service RailsConnector::ContentService.configuration end def cms_api RailsConnector::CmsRestApi.configuration end end # defaults self.ca_file = DEFAULT_CA_FILE self.editing_auth{ |env| false } end class ConfigurationError < StandardError end end