Class/Module Index [+]

Quicksearch

OpenShift::Controller::ApiBehavior

Attributes

requested_api_version[R]

Protected Instance Methods

authorize!(permission, resource, *resources) click to toggle source
# File lib/openshift/controller/api_behavior.rb, line 155
def authorize!(permission, resource, *resources)
  Ability.authorize!(current_user, current_user.scopes, permission, resource, *resources)
end
authorized?(permissions, resource, *resources) click to toggle source
# File lib/openshift/controller/api_behavior.rb, line 158
def authorized?(permissions, resource, *resources)
  Ability.authorized?(current_user, current_user.scopes, permissions, resource, *resources)
end
check_outage() click to toggle source
# File lib/openshift/controller/api_behavior.rb, line 41
def check_outage
  if Rails.configuration.maintenance[:enabled]
    message = Rails.cache.fetch("outage_msg", :expires_in => 5.minutes) do
      File.read(Rails.configuration.maintenance[:outage_msg_filepath]) rescue nil
    end
    reply = new_rest_reply(:service_unavailable)
    reply.messages.push(Message.new(:info, message)) if message
    respond_with reply
  end
end
check_version() click to toggle source
# File lib/openshift/controller/api_behavior.rb, line 16
def check_version
  version = catch(:version) do
    (request.accept || "").split(',').each do |mime_type|
      values = mime_type.split(';').map(&:strip)
      @nolinks = true if values.include? 'nolinks'
      values.map(&:strip).map(&:downcase).each do |value|
        throw :version, value.split("=")[1].to_f if value.starts_with? "version"
      end
    end
    nil
  end.presence
  if version.nil?
    version = API_VERSION
    #FIXME  this is a hack that should be removed by April
    version = 1.3 if request.headers['User-Agent'].present? and request.headers['User-Agent'].start_with? "rhc"
  end
  if SUPPORTED_API_VERSIONS.include? version
    @requested_api_version = version
    logger.debug "API version #{version}"
  else
    @requested_api_version = API_VERSION
    render_error(:not_acceptable, "Requested API version #{version} is not supported. Supported versions are #{SUPPORTED_API_VERSIONS.map{|v| v.to_s}.join(",")}")
  end
end
get_application() click to toggle source
# File lib/openshift/controller/api_behavior.rb, line 134
def get_application
  domain_id = params[:domain_id].presence || params[:domain_name].presence
  domain_id = domain_id.to_s.downcase if domain_id
  application_id = params[:application_id].presence || params[:id].presence || params[:application_name].presence || params[:name].presence
  application_id = application_id.to_s if application_id

  @application =
    if domain_id.nil?
      Application.accessible(current_user).find(application_id)
    else
      domain_id = Domain.check_name!(domain_id).downcase
      begin
        Application.accessible(current_user).find_by(domain_namespace: domain_id, canonical_name: Application.check_name!(application_id).downcase)
      rescue Mongoid::Errors::DocumentNotFound
        # ensure a domain not found exception is raised
        Domain.accessible(current_user).find_by(canonical_namespace: domain_id)
        raise
      end
    end
end
get_bool(param_value) click to toggle source
# File lib/openshift/controller/api_behavior.rb, line 68
def get_bool(param_value)
  return false unless param_value
  if param_value.is_a? TrueClass or param_value.is_a? FalseClass
    return param_value
  elsif param_value.is_a? String and param_value.upcase == "TRUE"
    return true
  elsif param_value.is_a? String and param_value.upcase == "FALSE"
    return false
  end
  raise OpenShift::UserException.new("Invalid value '#{param_value}'. Valid options: [true, false]", 167)
end
get_domain(id=nil) click to toggle source
# File lib/openshift/controller/api_behavior.rb, line 129
def get_domain(id=nil)
  id ||= params[:domain_id].presence
  @domain = Domain.accessible(current_user).find_by(canonical_namespace: Domain.check_name!(id.presence).downcase)
end
get_includes() click to toggle source
# File lib/openshift/controller/api_behavior.rb, line 80
def get_includes
  @includes ||=
    if params[:include].is_a? String
      params[:include].split(',')
    elsif params[:include].is_a? Array
      params[:include].map(&:to_s)
    else
      []
    end
end
get_log_tag_prepend() click to toggle source
# File lib/openshift/controller/api_behavior.rb, line 110
def get_log_tag_prepend
  tag = "UNKNOWN"
  case request.method
  when "GET"
    if params[:id]
      tag = "SHOW_"
    else
      tag = "LIST_"
    end
  when "POST"
    tag = "ADD_"
  when "PUT"
    tag = "UPDATE_"
  when "DELETE"
    tag = "DELETE_"
  end
  return tag
end
get_url() click to toggle source
# File lib/openshift/controller/api_behavior.rb, line 52
def get_url
  @rest_url ||= "#{rest_url}/"
end
if_included(sym, default=nil, &block) click to toggle source
# File lib/openshift/controller/api_behavior.rb, line 91
def if_included(sym, default=nil, &block)
  if get_includes.any?{ |i| i == sym.to_s }
    block_given? ? yield : true
  else
    default
  end
end
pre_and_post_condition(pre, post, run, fails) click to toggle source
# File lib/openshift/controller/api_behavior.rb, line 99
def pre_and_post_condition(pre, post, run, fails)
  return false if !pre.call
  run.call
  if post.call
    true
  else
    fails.call
    false
  end
end
set_locale() click to toggle source
# File lib/openshift/controller/api_behavior.rb, line 56
def set_locale
  I18n.locale = nil
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.