Module: LeapSalesforce
- Defined in:
- lib/leap_salesforce.rb,
lib/leap_salesforce/auth.rb,
lib/leap_salesforce/error.rb,
lib/leap_salesforce/limits.rb,
lib/leap_salesforce/loader.rb,
lib/leap_salesforce/session.rb,
lib/leap_salesforce/version.rb,
lib/leap_salesforce/parameters.rb,
lib/leap_salesforce/users/user.rb,
lib/leap_salesforce/soql_object.rb,
lib/leap_salesforce/users/users.rb,
lib/leap_salesforce/soql_data/soql.rb,
lib/leap_salesforce/generator/default.rb,
lib/leap_salesforce/soql_data/tooling.rb,
lib/leap_salesforce/generator/generator.rb,
lib/leap_salesforce/generator/soql_enums.rb,
lib/leap_salesforce/generator/exe_helpers.rb,
lib/leap_salesforce/generator/soql_objects.rb,
lib/leap_salesforce/soql_data/common_enum_methods.rb
Overview
Adding parameters to set for authentication, environment and other common settings
Defined Under Namespace
Modules: Auth, CommonEnumMethods, Default, ExeHelpers, Generator, Loader, Tooling, Users Classes: Error, Limits, RequestError, ResponseError, Session, SetupError, Soql, SoqlObject, User, UserError
Constant Summary collapse
- VERSION =
Returns Version of leap salesforce.
'1.3.1'
- CREDENTIALS_FOLDER =
Returns Folder where credentials are stored.
File.join('config', 'credentials')
- CREDENTIAL_FILE =
Returns File where Salesforce credentials are stored.
File.join(CREDENTIALS_FOLDER, 'salesforce_oauth2.yml')
Class Attribute Summary collapse
-
.client_id ⇒ String
Client id in Salesforce OAuth app.
-
.client_secret ⇒ String
Client secret in Salesforce OAuth app.
-
.config_folder ⇒ String
Folder where all configuration is stored.
-
.environment ⇒ String
Environment to use for tests.
-
.lib_folder ⇒ String
Path where library generated assets are stored.
-
.logger ⇒ Logger
Logger used by LeapSalesforce.
-
.objects_to_verify ⇒ Array
List of objects to verify metadata for.
-
.password ⇒ String
Common API password.
-
.security_token ⇒ String
Token specific to a user used for authentication.
-
.sfdx ⇒ Boolean
Setting this variable uses sfdx for authentication and other actions such as opening an organisation link.
-
.soql_objects ⇒ Array
List of Soql Objects identified for Leap Salesforce to maintain.
Class Method Summary collapse
-
.api_user ⇒ String
Salesforce username used to execute API tests.
- .api_user=(user) ⇒ Object
-
.general_url ⇒ String
General salesforce URL for logging in to.
-
.oauth_settings ⇒ Hash
OAuth parameters when using a custom Connected application not using sfdx.
-
.oauth_working? ⇒ TrueClass
If OAuth authentication is working, return true.
-
.salesforce_reachable? ⇒ Boolean
Verify connection to Salesforce environment.
-
.sfdx_auth_setup? ⇒ Boolean
Checks whether sfdx is setup according to standard approach.
Class Attribute Details
.client_id ⇒ String
Returns Client id in Salesforce OAuth app.
118 119 120 |
# File 'lib/leap_salesforce/parameters.rb', line 118 def client_id @client_id end |
.client_secret ⇒ String
Returns Client secret in Salesforce OAuth app.
120 121 122 |
# File 'lib/leap_salesforce/parameters.rb', line 120 def client_secret @client_secret end |
.config_folder ⇒ String
Returns Folder where all configuration is stored. By default this is ‘config’.
111 112 113 |
# File 'lib/leap_salesforce/parameters.rb', line 111 def config_folder @config_folder end |
.environment ⇒ String
Returns 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’.
31 32 33 |
# File 'lib/leap_salesforce/parameters.rb', line 31 def environment ENV['LEAP_ENV'] || @environment end |
.lib_folder ⇒ String
Returns Path where library generated assets are stored. By default lib/leap_salesforce.
124 125 126 |
# File 'lib/leap_salesforce/parameters.rb', line 124 def lib_folder @lib_folder end |
.logger ⇒ Logger
Returns Logger used by LeapSalesforce.
131 132 133 |
# File 'lib/leap_salesforce/parameters.rb', line 131 def logger @logger end |
.objects_to_verify ⇒ Array
Returns List of objects to verify metadata for. This includes enums, required values Changes to these values will need to be version controlled.
127 128 129 |
# File 'lib/leap_salesforce/parameters.rb', line 127 def objects_to_verify @objects_to_verify end |
.password ⇒ String
Returns Common API password. This assumes all users use the same password.
116 117 118 |
# File 'lib/leap_salesforce/parameters.rb', line 116 def password @password end |
.security_token ⇒ String
Returns Token specific to a user used for authentication.
122 123 124 |
# File 'lib/leap_salesforce/parameters.rb', line 122 def security_token @security_token end |
.sfdx ⇒ Boolean
Setting this variable uses sfdx for authentication and other actions such as opening an organisation link
142 143 144 |
# File 'lib/leap_salesforce/parameters.rb', line 142 def sfdx @sfdx end |
.soql_objects ⇒ Array
Returns List of Soql Objects identified for Leap Salesforce to maintain.
129 130 131 |
# File 'lib/leap_salesforce/parameters.rb', line 129 def soql_objects @soql_objects end |
Class Method Details
.api_user ⇒ String
Returns Salesforce username used to execute API tests. This can be changed during tests.
106 107 108 |
# File 'lib/leap_salesforce/parameters.rb', line 106 def api_user @api_user || LeapSalesforce::Users.list.first.username end |
.api_user=(user) ⇒ Object
94 95 96 97 98 99 100 101 102 103 |
# File 'lib/leap_salesforce/parameters.rb', line 94 def api_user=(user) @api_user = if user.is_a? String user else LeapSalesforce::Users.where(user)&.username end leaps_user = LeapSalesforce::Users.where username: @api_user LeapSalesforce.security_token = leaps_user.security_token Soaspec::SpecLogger.info "Using user '#{@api_user}' for API" end |
.general_url ⇒ String
Returns General salesforce URL for logging in to.
89 90 91 |
# File 'lib/leap_salesforce/parameters.rb', line 89 def general_url "https://#{LeapSalesforce.environment == 'prod' ? 'login' : 'test'}.salesforce.com" end |
.oauth_settings ⇒ Hash
OAuth parameters when using a custom Connected application not using sfdx
78 79 80 81 82 83 84 85 86 |
# File 'lib/leap_salesforce/parameters.rb', line 78 def oauth_settings { username: '<%= LeapSalesforce.api_user %>', password: '<%= LeapSalesforce.password + LeapSalesforce.security_token.to_s %>', client_id: LeapSalesforce.client_id, client_secret: LeapSalesforce.client_secret, token_url: "#{LeapSalesforce.general_url}/services/oauth2/token" } end |
.oauth_working? ⇒ TrueClass
Returns If OAuth authentication is working, return true. Otherwise raise exception.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# 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.} from #{e.backtrace}" else puts "\u2713 OAuth successful".colorize :green Soaspec::OAuth2.debug_oauth = false true end |
.salesforce_reachable? ⇒ Boolean
Verify connection to Salesforce environment
36 37 38 39 40 41 42 |
# File 'lib/leap_salesforce/parameters.rb', line 36 def salesforce_reachable? RestClient.get(LeapSalesforce.general_url) rescue SocketError = "Unable to connect to #{LeapSalesforce.general_url}. Potentially problem with" \ ' internet or proxy settings'.colorize :red raise LeapSalesforce::SetupError, end |
.sfdx_auth_setup? ⇒ Boolean
Checks whether sfdx is setup according to standard approach. Errors are logged
67 68 69 70 71 72 73 |
# 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 |