leap_salesforce 1.1.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ChangeLog +14 -0
- data/README.md +4 -0
- data/Rakefile +2 -0
- data/bin/console +3 -2
- data/config/general.rb +3 -0
- data/exe/leap_salesforce +5 -0
- data/lib/leap_salesforce/parameters.rb +5 -4
- data/lib/leap_salesforce/session.rb +45 -0
- data/lib/leap_salesforce/soql_data/soql_settings.rb +0 -6
- data/lib/leap_salesforce/users/user.rb +7 -2
- data/lib/leap_salesforce/version.rb +1 -1
- data/lib/leap_salesforce.rb +3 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44ffa8e3367450ab36724adf3fc899d2cb95afe6f53d35e691f0b195abb76951
|
4
|
+
data.tar.gz: 913a39e2840894dd0c1a906a301ae864b1e368b9ebc80fa4e547315c06c25497
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0f4e1e61acf32114e51fe16451ea745d92198eb3944177885bc0f3cbc36bada65bc70c5efaa596978422b31246eaf3cd16aeab927ede42662dff79aa74d97dd
|
7
|
+
data.tar.gz: a8f1cfaea86a0766dbe58889e46c9a51370c2a934140bb37f55d5da235b31af7640aa2b79d70125aa6b9626d92d722d35c19d85d89e018f21d0b3f8210409ba1
|
data/ChangeLog
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
Version 1.2.1
|
2
|
+
* Debug SOAP login request so it can be debugged
|
3
|
+
|
4
|
+
Version 1.2.0
|
5
|
+
* Ability to set security token on leap_salesforce user by setting an environment variable with the format
|
6
|
+
`ENV["#{key}_token"]``
|
7
|
+
* Remove deprecated method of create_enum within soql_settings class
|
8
|
+
|
9
|
+
Version 1.1.2
|
10
|
+
* Fix user_id from session
|
11
|
+
|
12
|
+
Version 1.1.1
|
13
|
+
* Allow session information from SOAP login to be available with LeapSalesforce::Session class
|
14
|
+
|
1
15
|
Version 1.1.0
|
2
16
|
* Proper fix to work with activerecord 7 - requires ruby > 2.7
|
3
17
|
|
data/README.md
CHANGED
@@ -104,6 +104,10 @@ Credentials are not stored in stored in source control. They can be setting thro
|
|
104
104
|
* 'client_secret'
|
105
105
|
* 'password'
|
106
106
|
|
107
|
+
> Security tokens can be set for each user (adding to password in OAuth like in [this article](https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_calls_login.htm))
|
108
|
+
> To do that set an environment variable as USER_KEY_token. E.g, so for a user with a key of :admin
|
109
|
+
> the token would be set with the `admin_token` environment variable
|
110
|
+
|
107
111
|
Tests can be run using the default `Rake` task.
|
108
112
|
|
109
113
|
E.g.,
|
data/Rakefile
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative 'config/credentials/token' if File.exist? 'config/credentials/token.rb'
|
3
4
|
require 'bundler/gem_tasks'
|
4
5
|
require 'rspec/core/rake_task'
|
5
6
|
require 'rake/clean'
|
@@ -14,6 +15,7 @@ RSpec::Core::RakeTask.new(:spec)
|
|
14
15
|
|
15
16
|
desc 'Check Salesforce OAuth2 authentication is working'
|
16
17
|
task :check_oauth do
|
18
|
+
Soaspec::OAuth2.debug_oauth = true
|
17
19
|
LeapSalesforce.oauth_working?
|
18
20
|
end
|
19
21
|
|
data/bin/console
CHANGED
@@ -7,6 +7,7 @@ require 'leap_salesforce'
|
|
7
7
|
# You can add fixtures and/or initialization code here to make experimenting
|
8
8
|
# with your gem easier. You can also use a different console, if you like.
|
9
9
|
|
10
|
-
require '
|
10
|
+
require 'irb'
|
11
|
+
require 'irb/completion'
|
11
12
|
|
12
|
-
|
13
|
+
IRB.start(__FILE__)
|
data/config/general.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# Set environment variable to set a security token that will be sent for a user
|
4
|
+
# ENV['admin_token'] = 'test'
|
5
|
+
|
3
6
|
# Add users to LeapSalesforce context. First user is the default
|
4
7
|
module LeapSalesforce
|
5
8
|
Users.add User.new :admin, 'samuel.garratt@brave-otter-ttxype.com'
|
data/exe/leap_salesforce
CHANGED
@@ -36,6 +36,7 @@ module LeapSalesforce
|
|
36
36
|
exit if oauth_setup.downcase == 'n'
|
37
37
|
end
|
38
38
|
query_for_parameters # TODO: for sfdx
|
39
|
+
has_ignore_file = File.exist?('.gitignore')
|
39
40
|
generate_files binding, ['Gemfile', 'Rakefile', '.leap_salesforce.yml', '.rspec', '.gitignore',
|
40
41
|
{ config: ['general.rb', { credentials: 'salesforce_oauth2.yml' }] },
|
41
42
|
{ spec: %w[spec_helper.rb limit_spec.rb crud_eg_spec.rb picklists_spec.rb] }]
|
@@ -52,6 +53,10 @@ module LeapSalesforce
|
|
52
53
|
puts `rake leaps:create_soql_objects`
|
53
54
|
puts 'Creating enums'.colorize :yellow
|
54
55
|
puts `rake leaps:create_enums`
|
56
|
+
return unless has_ignore_file
|
57
|
+
|
58
|
+
puts 'Your .gitignore is already present so not updated.
|
59
|
+
Please ignore "config/credentials/" and "logs/"'.colorize :red
|
55
60
|
end
|
56
61
|
end
|
57
62
|
end
|
@@ -76,14 +76,13 @@ module LeapSalesforce
|
|
76
76
|
# using sfdx
|
77
77
|
# @return [Hash] OAuth2 parameters used in connecting to salesforce
|
78
78
|
def oauth_settings
|
79
|
-
|
80
|
-
username: '<%= LeapSalesforce.api_user %>',
|
79
|
+
{
|
80
|
+
username: '<%= LeapSalesforce.api_user %>',
|
81
|
+
password: '<%= LeapSalesforce.password + LeapSalesforce.security_token.to_s %>',
|
81
82
|
client_id: LeapSalesforce.client_id,
|
82
83
|
client_secret: LeapSalesforce.client_secret,
|
83
84
|
token_url: "#{LeapSalesforce.general_url}/services/oauth2/token"
|
84
85
|
}
|
85
|
-
settings[:security_token] = LeapSalesforce.security_token if LeapSalesforce.security_token
|
86
|
-
settings
|
87
86
|
end
|
88
87
|
|
89
88
|
# @return [String] General salesforce URL for logging in to
|
@@ -98,6 +97,8 @@ module LeapSalesforce
|
|
98
97
|
else
|
99
98
|
LeapSalesforce::Users.where(user)&.username
|
100
99
|
end
|
100
|
+
leaps_user = LeapSalesforce::Users.where username: @api_user
|
101
|
+
LeapSalesforce.security_token = leaps_user.security_token
|
101
102
|
Soaspec::SpecLogger.info "Using user '#{@api_user}' for API"
|
102
103
|
end
|
103
104
|
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require_relative 'auth'
|
2
|
+
require 'savon'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module LeapSalesforce
|
6
|
+
# Holds information about a login session
|
7
|
+
class Session
|
8
|
+
# @return [String] Session id returned from SOAP API
|
9
|
+
attr_accessor :session_id
|
10
|
+
# @return [String] User id returned from SOAP API
|
11
|
+
attr_accessor :user_id
|
12
|
+
# @return [Hash] Login response
|
13
|
+
attr_accessor :login_response
|
14
|
+
|
15
|
+
def initialize(username, password, security_token = '')
|
16
|
+
login_body = LeapSalesforce::Session.soap_login username, password, security_token
|
17
|
+
|
18
|
+
self.session_id = login_body[:login_response][:result][:session_id]
|
19
|
+
self.user_id = login_body[:login_response][:result][:user_id]
|
20
|
+
self.login_response = login_body[:login_response]
|
21
|
+
end
|
22
|
+
|
23
|
+
class << self
|
24
|
+
|
25
|
+
# Login via SOAP API
|
26
|
+
def soap_login(username, password, security_token)
|
27
|
+
client = Savon.client do
|
28
|
+
endpoint "#{SoqlHandler.instance_url}/services/Soap/u/51.0"
|
29
|
+
namespace "urn:partner.soap.sforce.com"
|
30
|
+
log true # See request and response. (Put this in traffic file)
|
31
|
+
log_level :debug
|
32
|
+
logger Soaspec::SpecLogger.create
|
33
|
+
pretty_print_xml true # Prints XML pretty
|
34
|
+
end
|
35
|
+
|
36
|
+
response = client.call(:login, message:
|
37
|
+
{
|
38
|
+
username: username,
|
39
|
+
password: password + security_token.to_s
|
40
|
+
})
|
41
|
+
response.body
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -13,10 +13,4 @@ module SoqlSettings
|
|
13
13
|
def soql_object_name
|
14
14
|
@soql_object_name || to_s
|
15
15
|
end
|
16
|
-
|
17
|
-
# @deprecated Not used, setting in '.leap_salesforce.yml' controls this now
|
18
|
-
def create_enum(_set)
|
19
|
-
LeapSalesforce.logger.warn "Method 'create_enum' called when it is deprecated" \
|
20
|
-
" from #{caller_locations[0]}"
|
21
|
-
end
|
22
16
|
end
|
@@ -14,11 +14,16 @@ module LeapSalesforce
|
|
14
14
|
# readable format is required such as in a Cucumber test
|
15
15
|
attr_accessor :description
|
16
16
|
|
17
|
-
# @
|
18
|
-
|
17
|
+
# @return [String] Security token of user. Recommend this be set through ENV variable
|
18
|
+
attr_accessor :security_token
|
19
|
+
|
20
|
+
# @param [String, Symbol] user_params[0] key Key used to identify a test user
|
21
|
+
# @param [String] user_params[1] username Name used to login with user. In email address format.
|
22
|
+
# @param [String] user_params[1] security_token Security token of user
|
19
23
|
def initialize(*user_params, description: nil)
|
20
24
|
self.key = user_params[0]
|
21
25
|
self.username = user_params[1]
|
26
|
+
self.security_token = ENV["#{key}_token"] || nil
|
22
27
|
self.description = description
|
23
28
|
end
|
24
29
|
|
data/lib/leap_salesforce.rb
CHANGED
@@ -19,6 +19,7 @@ require 'factory_bot' # For mass production of data
|
|
19
19
|
require 'faker' # For fake data
|
20
20
|
require 'leap_salesforce/error'
|
21
21
|
require 'leap_salesforce/loader'
|
22
|
+
require 'leap_salesforce/session'
|
22
23
|
|
23
24
|
# If variable is present within LeapSalesforce set it
|
24
25
|
def load_variables_from(file)
|
@@ -82,3 +83,5 @@ module LeapSalesforce
|
|
82
83
|
|
83
84
|
self.objects_to_verify = SoqlData.descendants if objects_to_verify.empty?
|
84
85
|
end
|
86
|
+
|
87
|
+
LeapSalesforce.api_user = LeapSalesforce::Users.list.first.username
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: leap_salesforce
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- IQA
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2022-
|
12
|
+
date: 2022-02-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -333,6 +333,7 @@ files:
|
|
333
333
|
- lib/leap_salesforce/rake.rb
|
334
334
|
- lib/leap_salesforce/rake/setup.rake
|
335
335
|
- lib/leap_salesforce/rake/sfdx.rake
|
336
|
+
- lib/leap_salesforce/session.rb
|
336
337
|
- lib/leap_salesforce/soql_data/common_enum_methods.rb
|
337
338
|
- lib/leap_salesforce/soql_data/data_relationships.rb
|
338
339
|
- lib/leap_salesforce/soql_data/meta_data_handler.rb
|