class ApplicationController
Base class for all rOCCI-server's controllers. Implements parsing and authentication callbacks, exposes user information, declares supported media formats and handles raised errors.
Constants
- INDEX_LINK_FORMATS
List of format targets for rendering into links only
Public Instance Methods
Performs authentication with Warden. Warden will raise an exception and redirect to UnauthorizedController.
# File app/controllers/application_controller.rb, line 84 def authenticate! warden.authenticate! end
Provides access to a structure containing authentication data intended for delegation to the backend.
@return [Hashie::Mash] a hash containing authentication data
# File app/controllers/application_controller.rb, line 66 def current_user if Rails.env.test? # turn off caching for tests @current_user = warden.user else @current_user ||= warden.user end end
Provides access to a request collection prepared by the RequestParser.
@param expected_entity_type [Object] parameter passed as 'entity_type' to Occi::Parser.parse @return [Occi::Collection] collection containig parsed OCCI request
# File app/controllers/application_controller.rb, line 93 def request_occi_collection(expected_entity_type = nil) if Rails.env.test? # turn off caching for tests @request_collection = parse_request(expected_entity_type) else @request_collection ||= parse_request(expected_entity_type) end end
Provides access to a lazy authN object from Warden.
@return [Warden::Manager]
# File app/controllers/application_controller.rb, line 78 def warden request.env['warden'] end
Protected Instance Methods
Provides access to and caching for the active backend instance.
@return [Backend] instance of the backend
# File app/controllers/application_controller.rb, line 107 def backend_instance if Rails.env.test? # turn off caching for tests @backend_instance = Backend.new(current_user) else @backend_instance ||= Backend.new(current_user) end end
Runs basic checks matching ActionInstance content with action name declared in the 'query_string'
# File app/controllers/application_controller.rb, line 141 def check_ai!(ai, query_string) action_param = action_from_query_string(query_string) fail ::Errors::ArgumentError, 'Provided action does not have a term!' unless ai && ai.action && ai.action.term fail ::Errors::ArgumentTypeMismatchError, "Action terms in params and body do not " "match! #{action_param.inspect} vs. #{ai.action.term.inspect}" unless ai.action.term == action_param end
Provides access to a lazy parser object
@param expected_entity_type [Object] parameter passed as 'entity_type' to Occi::Parser.parse @return [Occi::Collection] collection of parsed OCCI objects
# File app/controllers/application_controller.rb, line 120 def parse_request(expected_entity_type = nil) request_collection = request.env['rocci_server.request.parser'].parse_occi_messages(expected_entity_type) request_collection ||= Occi::Collection.new request_collection.model = OcciModel.get(backend_instance) request_collection.check(check_categories = true, set_default_attrs = true) request_collection end
Provides access to user-configured server URL
@return [String] FQDN of the server, including the port number
# File app/controllers/application_controller.rb, line 133 def server_url "#{ROCCI_SERVER_CONFIG.common.protocol || 'http'}://" "#{ROCCI_SERVER_CONFIG.common.hostname || 'localhost'}:" "#{ROCCI_SERVER_CONFIG.common.port.to_s || '3000'}" end
Updates resource mixins in the given collection by looking them up in the model and replacing empty titles and wrong locations.
@param collection [Occi::Collection] an OCCI collection @return [Occi::Collection] an updated OCCI collection (== input collection)
# File app/controllers/application_controller.rb, line 153 def update_mixins_in_coll(collection) return collection if collection.blank? return collection if collection.resources.blank? && collection.links.blank? model = OcciModel.get(backend_instance) collection.resources.to_a.each do |resource| next if resource.mixins.blank? && resource.links.blank? resource.mixins.to_a.each { |mxn| update_mixin_from_model(mxn, model) } resource.links.to_a.each do |link| next if link.mixins.blank? link.mixins.to_a.each { |lnk_mxn| update_mixin_from_model(lnk_mxn, model) } end end collection.links.to_a.each do |link| next if link.mixins.blank? link.mixins.to_a.each { |lnk_mxn| update_mixin_from_model(lnk_mxn, model) } end collection end