Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add settings to connect to Salesforce MyDomain url #28

Merged
merged 14 commits into from
Nov 11, 2021
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/index.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ This plugin supports the following configuration options plus the <<plugins-{typ
| <<plugins-{type}s-{plugin}-security_token>> |<<string,string>>|Yes
| <<plugins-{type}s-{plugin}-sfdc_fields>> |<<array,array>>|No
| <<plugins-{type}s-{plugin}-sfdc_filters>> |<<string,string>>|No
| <<plugins-{type}s-{plugin}-sfdc_instance_url>> |<<string,string>>|No
| <<plugins-{type}s-{plugin}-sfdc_object_name>> |<<string,string>>|Yes
| <<plugins-{type}s-{plugin}-to_underscores>> |<<boolean,boolean>>|No
| <<plugins-{type}s-{plugin}-use_test_sandbox>> |<<boolean,boolean>>|No
Expand Down Expand Up @@ -161,6 +162,16 @@ These options will be added to the WHERE clause in the
SOQL statement. Additional fields can be filtered on by
adding field1 = value1 AND field2 = value2 AND...

[id="plugins-{type}s-{plugin}-sfdc_instance_url"]
===== `sfdc_instance_url`

* Value type is <<string,string>>
* There is no default value for this setting.

The url of a salesforce instance. Provide this if you already
during login want to connect to your instance url instead of
`login.salesforce.com` or `test.salesforce.com`.
mkreth marked this conversation as resolved.
Show resolved Hide resolved

mkreth marked this conversation as resolved.
Show resolved Hide resolved
[id="plugins-{type}s-{plugin}-sfdc_object_name"]
===== `sfdc_object_name`

Expand Down
14 changes: 13 additions & 1 deletion lib/logstash/inputs/salesforce.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ class LogStash::Inputs::Salesforce < LogStash::Inputs::Base
# Set this to true to connect to a sandbox sfdc instance
# logging in through test.salesforce.com
config :use_test_sandbox, :validate => :boolean, :default => false
# Set this to the instance url of the sfdc instance you want
# to connect to already during login. If you have configured
# a MyDomain in your sfdc instance you would provide
# <mydomain>.my.salesforce.com here.
config :sfdc_instance_url, :validate => :string, :required => false
# By default, this uses the default Restforce API version.
# To override this, set this to something like "32.0" for example
config :api_version, :validate => :string, :required => false
Expand Down Expand Up @@ -131,7 +136,14 @@ def client_options
:client_id => @client_id,
:client_secret => @client_secret
}
options.merge!({ :host => "test.salesforce.com" }) if @use_test_sandbox
# configure the endpoint to which restforce connects to for authentication
if @sfdc_instance_url && @use_test_sandbox
raise ::LogStash::ConfigurationError.new("Both \"use_test_sandbox\" and \"sfdc_instance_url\" can't be set simultaneously. Please specify either \"use_test_sandbox\" or \"sfdc_instance_url\"")
elsif @sfdc_instance_url
options.merge!({ :host => @sfdc_instance_url })
elsif @use_test_sandbox
options.merge!({ :host => "test.salesforce.com" })
end
options.merge!({ :api_version => @api_version }) if @api_version
return options
end
Expand Down
6 changes: 3 additions & 3 deletions logstash-input-salesforce.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ Gem::Specification.new do |s|

# Gem dependencies
s.add_runtime_dependency "logstash-core-plugin-api", ">= 1.60", "<= 2.99"
s.add_runtime_dependency 'logstash-codec-plain'
s.add_runtime_dependency 'restforce', '>= 3.2', '< 5'
s.add_runtime_dependency "logstash-codec-plain"
s.add_runtime_dependency "restforce", ">= 5", "< 5.2"
s.add_development_dependency 'logstash-devutils'
s.add_development_dependency 'vcr'
s.add_development_dependency 'webmock'
s.add_development_dependency 'json'
s.add_development_dependency 'public_suffix', '~> 1.4.6' # required due to ruby < 2.0
s.add_development_dependency 'public_suffix', '>= 1.4' # required due to ruby < 2.0
end
87 changes: 87 additions & 0 deletions spec/fixtures/vcr_cassettes/login_into_mydomain.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 62 additions & 0 deletions spec/inputs/salesforce_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,67 @@
end
end
end

context "use sfdc instance url" do
VCR.configure do |config|
config.cassette_library_dir = File.join(File.dirname(__FILE__), '..', 'fixtures', 'vcr_cassettes')
config.hook_into :webmock
config.before_record do |i|
if i.response.body.encoding.to_s == 'ASCII-8BIT'
# required because sfdc doesn't send back the content encoding and it
# confuses the yaml parser
json_body = JSON.load(i.response.body.encode("ASCII-8BIT").force_encoding("utf-8"))
i.response.body = json_body.to_json
i.response.update_content_length_header
end
end
end
let(:options) do
{
"client_id" => "",
"client_secret" => "",
"username" => "",
"password" => "",
"security_token" => "",
"sfdc_instance_url" => "my-domain.my.salesforce.com",
"sfdc_object_name" => "Lead"
}
end
let (:input) { LogStash::Inputs::Salesforce.new(options) }
let(:expected_fields_result) { ["Id", "IsDeleted",
"LastName", "FirstName", "Salutation"] }
let(:expected_types_result) { [["FirstName", "string"],
["Id", "id"],
["IsDeleted", "boolean"],
["LastName", "string"],
["Salutation", "picklist"]] }
subject { input }
it "logs into sfdc instance url" do
VCR.use_cassette("login_into_mydomain", :decode_compressed_response => true) do
subject.register
expect(subject.instance_variable_get(:@sfdc_field_types)).to match_array(expected_types_result)
expect(subject.instance_variable_get(:@sfdc_fields)).to match_array(expected_fields_result)
end
end
context "...but not use_test_sandbox" do
let(:options) do
{
"client_id" => "",
"client_secret" => "",
"username" => "",
"password" => "",
"security_token" => "",
"sfdc_instance_url" => "my-domain.my.salesforce.com",
"sfdc_object_name" => "Lead",
"use_test_sandbox" => true
}
end
let (:input) { LogStash::Inputs::Salesforce.new(options) }
subject { input }
it "should raise a LogStash::ConfigurationError" do
expect { subject.register }.to raise_error(::LogStash::ConfigurationError)
end
end
end
end
end