Sha256: 20acba31936167974287bdd6e3851f2a6cc3e9f4f034597f83bc350e1f7e75bf

Contents?: true

Size: 1.23 KB

Versions: 40

Compression:

Stored size: 1.23 KB

Contents

module ForestLiana
  class IpWhitelist
    @@use_ip_whitelist = true
    @@ip_whitelist_rules = nil

    def self.retrieve
      begin
        response = ForestLiana::ForestApiRequester.get('/liana/v1/ip-whitelist-rules')

        if response.is_a?(Net::HTTPOK)
          body = JSON.parse(response.body)
          ip_whitelist_data = body['data']['attributes']

          @@use_ip_whitelist = ip_whitelist_data['use_ip_whitelist']
          @@ip_whitelist_rules = ip_whitelist_data['rules']
          true
        else
          raise "Cannot retrieve the data from the Forest server. Forest API returned an #{Errors::HTTPErrorHelper.format(response)}"
        end
      rescue => exception
        FOREST_LOGGER.error 'Cannot retrieve the IP Whitelist from the Forest server.'
        FOREST_LOGGER.error 'Which was caused by:'
        ForestLiana::Errors::ExceptionHelper.recursively_print(exception, margin: ' ', is_error: true)
        false
      end
    end

    def self.is_ip_whitelist_retrieved
      !@@use_ip_whitelist || !@@ip_whitelist_rules.nil?
    end

    def self.is_ip_valid(ip)
      if @@use_ip_whitelist
        return ForestLiana::IpWhitelistChecker.is_ip_matches_any_rule(ip, @@ip_whitelist_rules)
      end

      true
    end
  end
end

Version data entries

40 entries across 40 versions & 1 rubygems

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