module LeapSalesforce
Global configuration for LeapSalesforce
Adding parameters to set for authentication, environment and other common settings
Constants
- CREDENTIALS_FOLDER
@return [String] Folder where credentials are stored
- CREDENTIAL_FILE
@return [String] File where
Salesforce
credentials are stored- VERSION
@return [String] Version of leap salesforce
Attributes
@return [String] Client id in Salesforce
OAuth app
@return [String] Client secret in Salesforce
OAuth app
@return [String] Folder where all configuration is stored. By default this is 'config'
@return [String] Environment to use for tests. This can be accessed to change the username used to login
to test.salesforce with
@return [String] Path where library generated assets are stored. By default lib/leap_salesforce
@return [Logger] Logger used by LeapSalesforce
@return [Array] List of objects to verify metadata for. This includes enums, required values
Changes to these values will need to be version controlled
@return [String] Common API password. This assumes all users use the same password
@return [String] Token specific to a user used for authentication
Setting this variable uses sfdx for authentication and other actions such as opening an organisation link @return [Boolean] Whether Salesforce
sfdx is being used
@return [Array] List of Soql
Objects identified for Leap Salesforce
to maintain
Public Class Methods
@return [String] Salesforce
username used to execute API tests. This can be changed during tests
# File lib/leap_salesforce/parameters.rb, line 105 def api_user @api_user || LeapSalesforce::Users.list.first.username end
@param [String, Symbol, Regexp, LeapSalesforce::User] user User
or email address of user
# File lib/leap_salesforce/parameters.rb, line 95 def api_user=(user) @api_user = if user.is_a? String user else LeapSalesforce::Users.where(user)&.username end Soaspec::SpecLogger.info "Using user '#{@api_user}' for API" end
@return [String] Environment to use for tests. This can be accessed to change the username used to login
to test.salesforce with. This can be set on the command line with 'LEAP_ENV'
# File lib/leap_salesforce/parameters.rb, line 31 def environment ENV['LEAP_ENV'] || @environment end
@return [String] General salesforce URL for logging in to
# File lib/leap_salesforce/parameters.rb, line 90 def general_url "https://#{LeapSalesforce.environment == 'prod' ? 'login' : 'test'}.salesforce.com" end
OAuth parameters when using a custom Connected application not using sfdx @return [Hash] OAuth2 parameters used in connecting to salesforce
# File lib/leap_salesforce/parameters.rb, line 78 def oauth_settings settings = { username: '<%= LeapSalesforce.api_user %>', password: LeapSalesforce.password, client_id: LeapSalesforce.client_id, client_secret: LeapSalesforce.client_secret, token_url: "#{LeapSalesforce.general_url}/services/oauth2/token" } settings[:security_token] = LeapSalesforce.security_token if LeapSalesforce.security_token settings end
@return [TrueClass] If OAuth authentication is working, return true.
Otherwise raise exception
# File lib/leap_salesforce/parameters.rb, line 46 def oauth_working? salesforce_reachable? if LeapSalesforce.sfdx sfdx_auth_setup? else Soaspec::OAuth2.debug_oauth = true Soaspec::OAuth2.new(LeapSalesforce.oauth_settings).access_token end rescue StandardError => e raise LeapSalesforce::SetupError, "Cannot perform OAuth. See 'logs'" \ ' folder for details of what was sent. ' \ "Error caused by #{e.message} from #{e.backtrace}" else puts "\u2713 OAuth successful".colorize :green Soaspec::OAuth2.debug_oauth = false true end
Verify connection to Salesforce
environment
# File lib/leap_salesforce/parameters.rb, line 36 def salesforce_reachable? RestClient.get(LeapSalesforce.general_url) rescue SocketError message = "Unable to connect to #{LeapSalesforce.general_url}. Potentially problem with" \ ' internet or proxy settings'.colorize :red raise LeapSalesforce::SetupError, message end
Checks whether sfdx is setup according to standard approach. Errors are logged @return [Boolean] Whether sfdx is setup correctly
# File lib/leap_salesforce/parameters.rb, line 67 def sfdx_auth_setup? Auth.manually_set_auth? || Auth.jwt_file? return true if LeapSalesforce::Auth.sfdx_variables? raise LeapSalesforce::SetupError, 'LeapSalesforce::Auth.access_token and ' \ 'instance_url were not able to be retrieved by sfdx' end
@return [Array] list_of_soql_objects Array describing Soql
objects taken from .leap_salesforce.yml
# File lib/leap_salesforce/parameters.rb, line 133 def soql_objects=(list_of_soql_objects) @soql_objects = list_of_soql_objects.collect do |soql_object_desc| SoqlObject.new(soql_object_desc) end end