Sha256: df42e694ba0e82d4f645ed167f15497794f354e28989bcc6280f3d92813eb6af

Contents?: true

Size: 1.24 KB

Versions: 40

Compression:

Stored size: 1.24 KB

Contents

module ForestLiana
  class BaseController < ::ActionController::Base
    skip_before_action :verify_authenticity_token, raise: false
    wrap_parameters false
    before_action :reject_unauthorized_ip

    private

    def reject_unauthorized_ip
      begin
        ip = request.remote_ip

        if !ForestLiana::IpWhitelist.is_ip_whitelist_retrieved || !ForestLiana::IpWhitelist.is_ip_valid(ip)
          unless ForestLiana::IpWhitelist.retrieve
            raise ForestLiana::Errors::HTTP403Error.new("IP whitelist not retrieved")
          end

          unless ForestLiana::IpWhitelist.is_ip_valid(ip)
            raise ForestLiana::Errors::HTTP403Error.new("IP address rejected (#{ip})")
          end
        end
      rescue ForestLiana::Errors::ExpectedError => exception
        exception.display_error
        error_data = JSONAPI::Serializer.serialize_errors([{
          status: exception.error_code,
          detail: exception.message
        }])
        render(serializer: nil, json: error_data, status: exception.status)
      rescue => exception
        FOREST_LOGGER.error(exception)
        FOREST_LOGGER.error(exception.backtrace.join("\n"))
        render(serializer: nil, json: nil, status: :internal_server_error)
      end
    end
  end
end

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
forest_liana-3.0.0.pre.beta.16 app/controllers/forest_liana/base_controller.rb
forest_liana-3.0.0.pre.beta.15 app/controllers/forest_liana/base_controller.rb
forest_liana-3.0.0.pre.beta.14 app/controllers/forest_liana/base_controller.rb
forest_liana-2.15.8 app/controllers/forest_liana/base_controller.rb
forest_liana-3.0.0.pre.beta.13 app/controllers/forest_liana/base_controller.rb
forest_liana-2.15.7 app/controllers/forest_liana/base_controller.rb
forest_liana-3.0.0.pre.beta.12 app/controllers/forest_liana/base_controller.rb
forest_liana-2.15.6 app/controllers/forest_liana/base_controller.rb
forest_liana-3.0.0.pre.beta.11 app/controllers/forest_liana/base_controller.rb
forest_liana-2.15.5 app/controllers/forest_liana/base_controller.rb
forest_liana-3.0.0.pre.beta.10 app/controllers/forest_liana/base_controller.rb
forest_liana-2.15.4 app/controllers/forest_liana/base_controller.rb
forest_liana-3.0.0.pre.beta.9 app/controllers/forest_liana/base_controller.rb
forest_liana-2.15.3 app/controllers/forest_liana/base_controller.rb
forest_liana-3.0.0.pre.beta.8 app/controllers/forest_liana/base_controller.rb
forest_liana-2.15.2 app/controllers/forest_liana/base_controller.rb
forest_liana-2.15.1 app/controllers/forest_liana/base_controller.rb
forest_liana-3.0.0.pre.beta.7 app/controllers/forest_liana/base_controller.rb
forest_liana-3.0.0.pre.beta.6 app/controllers/forest_liana/base_controller.rb
forest_liana-2.15.0 app/controllers/forest_liana/base_controller.rb