use_salesforce_dataloader 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/use_salesforce_dataloader.rb +192 -0
  3. metadata +44 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4420a2c70a6e20c8bfafdc62d9e9f4a63af1adfc
4
+ data.tar.gz: fac3faaa5700c3926593af993f44f31b36377349
5
+ SHA512:
6
+ metadata.gz: aa07c0333f49136ec336d61142a348f5f5eae9778e5dab5d8c310393a0b2b5d451d23aa74d22a19983386dc1efaab791a92331976930348d94f7a8a3671e640f
7
+ data.tar.gz: e4e11ebe5da38ceab67e234a451928afb152b4b6032bba30599234459f425f87d5f66e53ecf8bda9d7180f380c1ff24273b6ccc5d6092cab9fa30c4808e827f5
@@ -0,0 +1,192 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ # see https://developer.salesforce.com/docs/atlas.en-us.dataLoader.meta/dataLoader/loader_params.htm
4
+ class UseSalesforceDataLoader
5
+
6
+ # file layout:
7
+ # conf_dir/key.txt
8
+ # conf_dir/process-conf.xml
9
+ # conf_dir/map.sdl
10
+ attr_accessor :conf_dir
11
+ attr_accessor :conf_key_file
12
+ attr_accessor :conf_process_xml_file
13
+ attr_accessor :conf_map_file
14
+ def conf_dir=(path)
15
+ @conf_dir = path
16
+ @conf_key_file = @conf_dir + '/key.txt'
17
+ @conf_process_xml_file = @conf_dir + '/process-conf.xml'
18
+ @conf_map_file = @conf_dir + '/map.sdl'
19
+ end
20
+
21
+ #
22
+ attr_accessor :bean_id
23
+ attr_accessor :bean_description
24
+ attr_accessor :property_name
25
+ attr_accessor :overwrite_entries
26
+
27
+ # salesforce.com authentication data
28
+ attr_accessor :endpoint # ex. https://test.salesforce.com
29
+ attr_accessor :username # ex. foo@example.com
30
+ attr_accessor :password # ex. 0123456789
31
+
32
+ # java: command line of java runtime, ex. "/usr/bin/java"
33
+ # java_opt: ex. "-Dfile.encoding=UTF-8"
34
+ # jar: path of dataloader-NN.N.N-uber.jar, ex. "/usr/lib/dataloader-41.0.0-uber.jar"
35
+ def initialize(jar, java, java_opt = nil)
36
+ path_check(java)
37
+ path_check(jar)
38
+ j = [java, java_opt, '-cp', jar].compact.join(' ')
39
+ @encrypt = "#{j} com.salesforce.dataloader.security.EncryptionUtil"
40
+ @process = "#{j} -Dsalesforce.config.dir=%s com.salesforce.dataloader.process.ProcessRunner process.name=%s"
41
+ end
42
+
43
+ # Original: dataloader/bin/encrypt.sh
44
+ # Usage: dataloader/bin/encrypt.sh
45
+ # Utility to encrypt a string based on a static or a provided key
46
+ # Options (mutually exclusive - use one at a time):
47
+ # -g <seed text> Generate key based on seed
48
+ # -v <encrypted> <decrypted value> [Path to Key] Validate whether decryption of encrypted value matches the decrypted value, optionally provide key file
49
+ # -e <plain text> [Path to Key] Encrypt a plain text value, optionally provide key file (generate key using option -g)
50
+ #
51
+ def encrypt(args)
52
+ cmd = "#{@encrypt} #{args} | sed 's/^.*) \- //g'"
53
+ `#{cmd}`.chomp
54
+ end
55
+
56
+ # Original: dataloader/bin/process.sh
57
+ # Usage: dataloader/bin/process.sh [conf-dir] <process-name>
58
+ #
59
+ def process_cmd(name)
60
+ path_check(@conf_dir)
61
+ path_check(@conf_key_file)
62
+ path_check(@conf_process_xml_file)
63
+ @process % [@conf_dir, name]
64
+ end
65
+
66
+ # Save encrypt key file
67
+ def save_conf_key_file
68
+ @conf_key_file.tap do |f|
69
+ open(f, 'w:UTF-8') do |o|
70
+ o.print encrypt("-g #{text_seed}")
71
+ end
72
+ end
73
+ end
74
+
75
+ # Save conf xml file
76
+ def save_conf_process_xml_file
77
+ @conf_process_xml_file.tap do |f|
78
+ open(f, 'w:UTF-8') do |o|
79
+ o.print conf_process_xml
80
+ end
81
+ end
82
+ end
83
+
84
+ # Generate XML config
85
+ def conf_process_xml
86
+ entries = BASE_ENTRIES.merge(default_overwrite_entries)
87
+ entries.merge!(@overwrite_entries) if @overwrite_entries
88
+ entries_xml = entries
89
+ .select{|k, v| v}
90
+ .map{|k, v| ENTRIES_XML_TEMPLATE % [k, v]}
91
+ .join("\n")
92
+ PROCESS_XML_TEMPLATE % [@bean_id,
93
+ @bean_descrption,
94
+ @property_name,
95
+ entries_xml]
96
+ end
97
+
98
+ # internal use
99
+ def default_overwrite_entries
100
+ encrypt_password = encrypt("-e '#{@password}' '#{@conf_key_file}'")
101
+ {
102
+ 'sfdc.endpoint' => @endpoint,
103
+ 'sfdc.username' => @username,
104
+ 'sfdc.password' => encrypt_password,
105
+ 'process.encryptionKeyFile' => @conf_key_file,
106
+ 'process.lastRunOutputDirectory' => @conf_dir,
107
+ 'process.statusOutputDirectory' => @conf_dir,
108
+ 'process.mappingFile' => @conf_map_file,
109
+ }
110
+ end
111
+
112
+ # interal use
113
+ def text_seed
114
+ rand(0xffff_ffff).to_s(16)
115
+ end
116
+
117
+ # internal use
118
+ def path_check(f)
119
+ raise "Path not found: #{f}" unless File.exist?(f)
120
+ end
121
+
122
+ PROCESS_XML_TEMPLATE = <<'PROCESS_XML'
123
+ <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
124
+ <beans>
125
+ <bean id="%s"
126
+ class="com.salesforce.dataloader.process.ProcessRunner"
127
+ singleton="false">
128
+ <description>%s</description>
129
+ <property name="name" value="%s"/>
130
+ <property name="configOverrideMap">
131
+ <map>
132
+ %s
133
+ </map>
134
+ </property>
135
+ </bean>
136
+ </beans>
137
+ PROCESS_XML
138
+
139
+ ENTRIES_XML_TEMPLATE = <<'ENTRIES_XML'
140
+ <entry key="%s" value="%s"/>
141
+ ENTRIES_XML
142
+
143
+ BASE_ENTRIES = {
144
+ 'dataAccess.readUTF8' => 'true',
145
+ 'dataAccess.writeUTF8' => 'true',
146
+ 'dataAccess.name' => nil,
147
+ 'dataAccess.readBatchSize' => nil,
148
+ 'dataAccess.type' => nil,
149
+ 'dataAccess.writeBatchSize' => nil,
150
+ 'process.enableExtractStatusOutput' => 'false',
151
+ 'process.enableLastRunOutput' => 'true',
152
+ 'process.encryptionKeyFile' => nil,
153
+ 'process.initialLastRunDate' => nil,
154
+ 'process.lastRunOutputDirectory' => nil,
155
+ 'process.loadRowToStartAt' => nil,
156
+ 'process.mappingFile' => nil,
157
+ 'process.operation' => nil,
158
+ 'process.statusOutputDirectory' => nil,
159
+ 'process.outputError' => nil,
160
+ 'process.outputSuccess' => nil,
161
+ 'process.useEuropeanDates' => nil,
162
+ 'sfdc.assignmentRule' => nil,
163
+ 'sfdc.bulkApiCheckStatusInterval' => nil,
164
+ 'sfdc.bulkApiSerialMode' => 'false',
165
+ 'sfdc.bulkApiZipContent' => nil,
166
+ 'sfdc.connectionTimeoutSecs' => nil,
167
+ 'sfdc.debugMessages' => nil,
168
+ 'sfdc.debugMessagesFile' => nil,
169
+ 'sfdc.enableRetries' => nil,
170
+ 'sfdc.endpoint' => nil,
171
+ 'sfdc.entity' => nil,
172
+ 'sfdc.externalIdField' => nil,
173
+ 'sfdc.extractionRequestSize' => nil,
174
+ 'sfdc.extractionSOQL' => nil,
175
+ 'sfdc.insertNulls' => nil,
176
+ 'sfdc.loadBatchSize' => nil,
177
+ 'sfdc.maxRetries' => nil,
178
+ 'sfdc.minRetrySleepSecs' => nil,
179
+ 'sfdc.noCompression' => nil,
180
+ 'sfdc.password' => nil,
181
+ 'sfdc.proxyHost' => nil,
182
+ 'sfdc.proxyPassword' => nil,
183
+ 'sfdc.proxyPort' => nil,
184
+ 'sfdc.proxyUsername' => nil,
185
+ 'sfdc.resetUrlOnLogin' => nil,
186
+ 'sfdc.timeoutSecs' => nil,
187
+ 'sfdc.timezone' => nil,
188
+ 'sfdc.truncateFields' => 'false',
189
+ 'sfdc.useBulkApi' => nil,
190
+ 'sfdc.username' => nil,
191
+ }
192
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: use_salesforce_dataloader
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Hiroaki Nagoya
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-12-30 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email: hnagoya@gmaiil.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/use_salesforce_dataloader.rb
20
+ homepage: http://rubygems.org/gems/use_salesforce_dataloader.rb
21
+ licenses:
22
+ - Apache 2.0
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.2.0
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: Force.com Apex Data Loader for Ruby/Linux - command line version
44
+ test_files: []