# frozen_string_literal: true require 'leap_salesforce/version' require 'soaspec' Soaspec::OAuth2.refresh_token = :once # Save access token and reuse it Soaspec.log_warnings = false # Log any API warnings Soaspec::OAuth2.request_message = false Soaspec::OAuth2.retry_limit = 1 # Retrying for OAuth token too many times results in user locked out require 'active_support/core_ext/integer/time' # Creating time objects require 'leap_salesforce/parameters' require 'leap_salesforce/ext/string' require 'leap_salesforce/ext/time' require 'require_all' require 'rake' require 'factory_bot' # For mass production of data require 'faker' # For fake data require 'leap_salesforce/error' LEAP_CONFIG_FILE = '.leap_salesforce.yml' CREDENTIAL_FILE = File.join('config', 'credentials', 'salesforce_oauth2.yml') leap_logger = Logger.new STDOUT leap_logger.level = Logger::DEBUG leap_logger.datetime_format = '%Y-%m-%d %H:%M:%S' if File.exist? LEAP_CONFIG_FILE leap_config = YAML.load_file LEAP_CONFIG_FILE LeapSalesforce.soql_objects = leap_config.delete('soql_objects') leap_config.each do |key, value| if %w[client_id client_secret password].include? key leap_logger.warn "Secret key '#{key}' should be in non version" \ " controlled #{CREDENTIAL_FILE} not in #{LEAP_CONFIG_FILE}" end LeapSalesforce.send("#{key}=", value) end else leap_logger.warn 'No config file found for Leap Salesforce' end raise LeapSalesforce::SetupError, 'LeapSalesforce.environment not set' if LeapSalesforce.environment.nil? if File.exist? CREDENTIAL_FILE YAML.load_file(CREDENTIAL_FILE).each do |key, value| LeapSalesforce.send("#{key}=", value) end end %w[client_id client_secret password].each do |param| raise LeapSalesforce::SetupError, "LeapSalesforce.#{param} not set" if LeapSalesforce.send(param).nil? end config_folder = File.join(Dir.pwd, LeapSalesforce.config_folder) general_file = File.join(config_folder, 'general') specific_environment_file = File.join(config_folder, 'environments', LeapSalesforce.environment) require general_file if File.exist? "#{general_file}.rb" require specific_environment_file if File.exist? "#{specific_environment_file}.rb" require 'leap_salesforce/soql_data/soql_data' require 'leap_salesforce/limits' FileUtils.mkdir_p LeapSalesforce.lib_folder unless Dir.exist? LeapSalesforce.lib_folder require_all LeapSalesforce.lib_folder LeapSalesforce.objects_to_verify = SoqlData.descendants if LeapSalesforce.objects_to_verify.empty?