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.5.0'
- 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.
-
.enum_folder ⇒ String
Path where generated enum files are stored.
-
.environment ⇒ String
Environment to use for tests.
-
.language ⇒ Symbol
Name of the language used.
-
.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_enum_start_text ⇒ String
Text to be added as start of auto generated Soql enums.
-
.soql_field_start_text ⇒ String
classes in the Salesforce object.
-
.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.
122 123 124 |
# File 'lib/leap_salesforce/parameters.rb', line 122 def client_id @client_id end |
.client_secret ⇒ String
Returns Client secret in Salesforce OAuth app.
124 125 126 |
# File 'lib/leap_salesforce/parameters.rb', line 124 def client_secret @client_secret end |
.config_folder ⇒ String
Returns Folder where all configuration is stored. By default this is ‘config’.
115 116 117 |
# File 'lib/leap_salesforce/parameters.rb', line 115 def config_folder @config_folder end |
.enum_folder ⇒ String
Returns Path where generated enum files are stored. By default this is null and just appeneded to lib_folder.
130 131 132 |
# File 'lib/leap_salesforce/parameters.rb', line 130 def enum_folder @enum_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’.
35 36 37 |
# File 'lib/leap_salesforce/parameters.rb', line 35 def environment ENV['LEAP_ENV'] || @environment end |
.language ⇒ Symbol
Returns Name of the language used.
140 141 142 |
# File 'lib/leap_salesforce/parameters.rb', line 140 def language @language end |
.lib_folder ⇒ String
Returns Path where library generated assets are stored. By default lib/leap_salesforce.
128 129 130 |
# File 'lib/leap_salesforce/parameters.rb', line 128 def lib_folder @lib_folder end |
.logger ⇒ Logger
Returns Logger used by LeapSalesforce.
137 138 139 |
# File 'lib/leap_salesforce/parameters.rb', line 137 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.
133 134 135 |
# File 'lib/leap_salesforce/parameters.rb', line 133 def objects_to_verify @objects_to_verify end |
.password ⇒ String
Returns Common API password. This assumes all users use the same password.
120 121 122 |
# File 'lib/leap_salesforce/parameters.rb', line 120 def password @password end |
.security_token ⇒ String
Returns Token specific to a user used for authentication.
126 127 128 |
# File 'lib/leap_salesforce/parameters.rb', line 126 def security_token @security_token end |
.sfdx ⇒ Boolean
Setting this variable uses sfdx for authentication and other actions such as opening an organisation link
158 159 160 |
# File 'lib/leap_salesforce/parameters.rb', line 158 def sfdx @sfdx end |
.soql_enum_start_text ⇒ String
Returns Text to be added as start of auto generated Soql enums.
147 148 149 |
# File 'lib/leap_salesforce/parameters.rb', line 147 def soql_enum_start_text @soql_enum_start_text end |
.soql_field_start_text ⇒ String
classes in the Salesforce object
144 145 146 |
# File 'lib/leap_salesforce/parameters.rb', line 144 def soql_field_start_text @soql_field_start_text end |
.soql_objects ⇒ Array
Returns List of Soql Objects identified for Leap Salesforce to maintain.
135 136 137 |
# File 'lib/leap_salesforce/parameters.rb', line 135 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.
110 111 112 |
# File 'lib/leap_salesforce/parameters.rb', line 110 def api_user @api_user || LeapSalesforce::Users.list.first.username end |
.api_user=(user) ⇒ Object
98 99 100 101 102 103 104 105 106 107 |
# File 'lib/leap_salesforce/parameters.rb', line 98 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.
93 94 95 |
# File 'lib/leap_salesforce/parameters.rb', line 93 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
82 83 84 85 86 87 88 89 90 |
# File 'lib/leap_salesforce/parameters.rb', line 82 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.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/leap_salesforce/parameters.rb', line 50 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
40 41 42 43 44 45 46 |
# File 'lib/leap_salesforce/parameters.rb', line 40 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
71 72 73 74 75 76 77 |
# File 'lib/leap_salesforce/parameters.rb', line 71 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 |