fluent-plugin-sforce 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/fluent-plugin-sforce.gemspec +1 -1
- data/lib/fluent/plugin/in_sforce.rb +41 -27
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b4ff49d08efb9e0482784eef7c6f1d82d5443ab308927503139c4bb7292115b4
|
4
|
+
data.tar.gz: c0d700e517977b84396d8f278c7df0101f8bb791584ac871d0ca44dc92c2a3ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f269381abecc41ec3989d480de019aaae4309a5d698953642ae2bb07d7a1944a8d712f45464df4c0655cd482146b98b87117d35adaa2d04c28e10ad97c1f11dd
|
7
|
+
data.tar.gz: ac768d6ff62866898ae961d7cd2f6fa54b833b144b55f5383c3012d472bb2a201c89186cb312cb68ed200d7625c61fc6c1cac6a039e54372efa07540a5890478
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.6
|
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.add_dependency 'fluentd'
|
20
20
|
spec.add_dependency 'restforce', '~> 3.0.0'
|
21
21
|
spec.add_dependency 'faye', '~> 1.2.4'
|
22
|
-
spec.add_dependency 'nokogiri', '
|
22
|
+
spec.add_dependency 'nokogiri', '>= 1.10.4'
|
23
23
|
spec.add_development_dependency 'rake'
|
24
24
|
spec.add_development_dependency 'test-unit'
|
25
25
|
end
|
@@ -23,52 +23,40 @@ module Fluent
|
|
23
23
|
config_param :version, :string, default: '43.0'
|
24
24
|
config_param :login_endpoint, :string, default: 'login.salesforce.com'
|
25
25
|
|
26
|
+
attr_accessor :client
|
27
|
+
|
26
28
|
def configure(conf)
|
27
29
|
super
|
28
30
|
end
|
29
31
|
|
30
32
|
def start
|
31
33
|
super
|
32
|
-
|
33
|
-
client = Restforce.new login_info.merge(api_version: @version)
|
34
|
+
@client = generate_client
|
34
35
|
|
35
|
-
|
36
|
-
|
37
|
-
if @topic == nil then
|
38
|
-
sleep(@polling_interval)
|
39
|
-
th_high = DateTime.now.strftime('%Y-%m-%dT%H:%M:%S.000%Z')
|
36
|
+
if @topic == nil
|
37
|
+
start_at = now
|
40
38
|
loop do
|
41
|
-
|
42
|
-
|
43
|
-
soql =
|
44
|
-
if @query =~ /^(.+)\s(where|WHERE)\s(.+)$/ then
|
45
|
-
soql = "#{$1} WHERE #{where} AND #{$3}"
|
46
|
-
elsif @query =~ /^(.+)$/ then
|
47
|
-
soql = "#{$1} WHERE #{where}"
|
48
|
-
end
|
39
|
+
sleep(@polling_interval)
|
40
|
+
end_at = now
|
41
|
+
soql = build_query(start_at, end_at)
|
49
42
|
|
50
43
|
begin
|
51
44
|
log.info "query: #{soql}"
|
52
|
-
records =
|
45
|
+
records = exec_query(soql)
|
53
46
|
records.each do |record|
|
54
47
|
router.emit(@tag, Fluent::Engine.now, record)
|
55
48
|
end
|
56
|
-
|
57
|
-
th_low = th_high
|
58
|
-
th_high = DateTime.now.strftime('%Y-%m-%dT%H:%M:%S.000%Z')
|
49
|
+
start_at = end_at
|
59
50
|
rescue Restforce::UnauthorizedError => e
|
60
51
|
log.error e
|
61
52
|
# retry login
|
62
|
-
|
63
|
-
client = Restforce.new login_info.merge(api_version: @version)
|
53
|
+
@client = generate_client
|
64
54
|
end
|
65
55
|
end
|
66
|
-
# streaming api
|
67
56
|
else
|
68
57
|
EM.run do
|
69
58
|
log.info "suscribe: #{@topic}"
|
70
|
-
|
71
|
-
client.subscribe @topic do |message|
|
59
|
+
subscribe @topic do |message|
|
72
60
|
router.emit(@tag, Fluent::Engine.now, message)
|
73
61
|
end
|
74
62
|
end
|
@@ -85,7 +73,7 @@ module Fluent
|
|
85
73
|
|
86
74
|
def login
|
87
75
|
uri = URI(login_endpoint)
|
88
|
-
request = Net::HTTP::Post.new(uri.request_uri,
|
76
|
+
request = Net::HTTP::Post.new(uri.request_uri, {'Content-Type' =>'text/xml', 'SOAPAction' => "''"})
|
89
77
|
request.body = <<BODY
|
90
78
|
<?xml version="1.0" encoding="utf-8"?>
|
91
79
|
<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
@@ -112,8 +100,8 @@ BODY
|
|
112
100
|
raise SforceConnectionError, fault unless fault.empty?
|
113
101
|
|
114
102
|
session_id = doc.css('sessionId').inner_text
|
115
|
-
/^(https:\/\/.+\.salesforce\.com)\//.match(doc.css('serverUrl').inner_text)
|
116
|
-
instance_url =
|
103
|
+
m = /^(https:\/\/.+\.salesforce\.com)\//.match(doc.css('serverUrl').inner_text)
|
104
|
+
instance_url = m[1]
|
117
105
|
log.info "login is successful. instance_url = '#{instance_url}'"
|
118
106
|
|
119
107
|
{oauth_token: session_id, instance_url: instance_url}
|
@@ -123,6 +111,32 @@ BODY
|
|
123
111
|
def login_endpoint
|
124
112
|
"https://#{@login_endpoint}/services/Soap/u/#{@version}"
|
125
113
|
end
|
114
|
+
|
115
|
+
def build_query(start_at, end_at)
|
116
|
+
where = "CreatedDate <= #{end_at} AND CreatedDate > #{start_at}"
|
117
|
+
if m = /^(.+)\s(where|WHERE)\s(.+)$/.match(@query)
|
118
|
+
return "#{m[1]} WHERE #{where} AND #{m[3]}"
|
119
|
+
end
|
120
|
+
|
121
|
+
"#{@query} WHERE #{where}"
|
122
|
+
end
|
123
|
+
|
124
|
+
def generate_client
|
125
|
+
login_info = login
|
126
|
+
Restforce.new login_info.merge(api_version: @version)
|
127
|
+
end
|
128
|
+
|
129
|
+
def exec_query(soql)
|
130
|
+
@client.query(soql)
|
131
|
+
end
|
132
|
+
|
133
|
+
def subscribe(name, &block)
|
134
|
+
@client.subscribe(name, &block)
|
135
|
+
end
|
136
|
+
|
137
|
+
def now
|
138
|
+
DateTime.now.strftime('%Y-%m-%dT%H:%M:%S.000%Z')
|
139
|
+
end
|
126
140
|
end
|
127
141
|
end
|
128
142
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-sforce
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Makoto Tajitsu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-11-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fluentd
|
@@ -56,16 +56,16 @@ dependencies:
|
|
56
56
|
name: nokogiri
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 1.
|
61
|
+
version: 1.10.4
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 1.
|
68
|
+
version: 1.10.4
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rake
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|