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.

Returns:

  • (String)

    Version of leap salesforce

'1.5.0'
CREDENTIALS_FOLDER =

Returns Folder where credentials are stored.

Returns:

  • (String)

    Folder where credentials are stored

File.join('config', 'credentials')
CREDENTIAL_FILE =

Returns File where Salesforce credentials are stored.

Returns:

  • (String)

    File where Salesforce credentials are stored

File.join(CREDENTIALS_FOLDER, 'salesforce_oauth2.yml')

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.client_idString

Returns Client id in Salesforce OAuth app.

Returns:

  • (String)

    Client id in Salesforce OAuth app



122
123
124
# File 'lib/leap_salesforce/parameters.rb', line 122

def client_id
  @client_id
end

.client_secretString

Returns Client secret in Salesforce OAuth app.

Returns:

  • (String)

    Client secret in Salesforce OAuth app



124
125
126
# File 'lib/leap_salesforce/parameters.rb', line 124

def client_secret
  @client_secret
end

.config_folderString

Returns Folder where all configuration is stored. By default this is ‘config’.

Returns:

  • (String)

    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_folderString

Returns Path where generated enum files are stored. By default this is null and just appeneded to lib_folder.

Returns:

  • (String)

    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

.environmentString

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’.

Returns:

  • (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’



35
36
37
# File 'lib/leap_salesforce/parameters.rb', line 35

def environment
  ENV['LEAP_ENV'] || @environment
end

.languageSymbol

Returns Name of the language used.

Returns:

  • (Symbol)

    Name of the language used



140
141
142
# File 'lib/leap_salesforce/parameters.rb', line 140

def language
  @language
end

.lib_folderString

Returns Path where library generated assets are stored. By default lib/leap_salesforce.

Returns:

  • (String)

    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

.loggerLogger

Returns Logger used by LeapSalesforce.

Returns:

  • (Logger)

    Logger used by LeapSalesforce



137
138
139
# File 'lib/leap_salesforce/parameters.rb', line 137

def logger
  @logger
end

.objects_to_verifyArray

Returns List of objects to verify metadata for. This includes enums, required values Changes to these values will need to be version controlled.

Returns:

  • (Array)

    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

.passwordString

Returns Common API password. This assumes all users use the same password.

Returns:

  • (String)

    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_tokenString

Returns Token specific to a user used for authentication.

Returns:

  • (String)

    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

.sfdxBoolean

Setting this variable uses sfdx for authentication and other actions such as opening an organisation link

Returns:

  • (Boolean)

    Whether Salesforce sfdx is being used



158
159
160
# File 'lib/leap_salesforce/parameters.rb', line 158

def sfdx
  @sfdx
end

.soql_enum_start_textString

Returns Text to be added as start of auto generated Soql enums.

Returns:

  • (String)

    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_textString

classes in the Salesforce object

Returns:

  • (String)

    Text to be added as start of auto generated Soql field names



144
145
146
# File 'lib/leap_salesforce/parameters.rb', line 144

def soql_field_start_text
  @soql_field_start_text
end

.soql_objectsArray

Returns List of Soql Objects identified for Leap Salesforce to maintain.

Returns:

  • (Array)

    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_userString

Returns Salesforce username used to execute API tests. This can be changed during tests.

Returns:

  • (String)

    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

Parameters:



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_urlString

Returns General salesforce URL for logging in to.

Returns:

  • (String)

    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_settingsHash

OAuth parameters when using a custom Connected application not using sfdx

Returns:

  • (Hash)

    OAuth2 parameters used in connecting to salesforce



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.

Returns:

  • (TrueClass)

    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.message} 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

Returns:

  • (Boolean)


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
  message = "Unable to connect to #{LeapSalesforce.general_url}. Potentially problem with" \
  ' internet or proxy settings'.colorize :red
  raise LeapSalesforce::SetupError, message
end

.sfdx_auth_setup?Boolean

Checks whether sfdx is setup according to standard approach. Errors are logged

Returns:

  • (Boolean)

    Whether sfdx is setup correctly

Raises:



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