Class: ApplicationController

Inherits:
ActionController::Base
  • Object
show all
Includes:
ActionController::ImplicitRender, ActionController::MimeResponds, Mixins::ErrorHandling
Defined in:
app/controllers/application_controller.rb

Overview

Base class for all rOCCI-server's controllers. Implements parsing and authentication callbacks, exposes user information, declares supported media formats and handles raised errors.

Constant Summary collapse

['text/plain', 'text/occi', 'text/uri-list'].freeze

Instance Method Summary collapse

Methods included from Mixins::ErrorHandling

#handle_auth_err, #handle_authz_err, #handle_backend_unavailable_err, #handle_internal_backend_err, #handle_invalid_resource_err, #handle_not_impl_err, #handle_parser_input_err, #handle_parser_type_err, #handle_resource_not_found_err, #handle_wrong_args_err

Instance Method Details

#authenticate!Object

Performs authentication with Warden. Warden will raise an exception and redirect to UnauthorizedController.


84
85
86
# File 'app/controllers/application_controller.rb', line 84

def authenticate!
  warden.authenticate!
end

#current_userHashie::Mash

Provides access to a structure containing authentication data intended for delegation to the backend.

Returns:

  • (Hashie::Mash)

    a hash containing authentication data


66
67
68
69
70
71
72
73
# 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

#request_occi_collection(expected_entity_type = nil) ⇒ Occi::Collection

Provides access to a request collection prepared by the RequestParser.

Parameters:

  • expected_entity_type (Object) (defaults to: nil)

    parameter passed as 'entity_type' to Occi::Parser.parse

Returns:

  • (Occi::Collection)

    collection containig parsed OCCI request


93
94
95
96
97
98
99
100
# 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

#wardenWarden::Manager

Provides access to a lazy authN object from Warden.

Returns:

  • (Warden::Manager)

78
79
80
# File 'app/controllers/application_controller.rb', line 78

def warden
  request.env['warden']
end