7
7
require 'xml'
8
8
9
9
# global log function
10
- $logfile = "/usr/local/var /log/connect_vbms.log"
10
+ $logfile = ".. /log/connect_vbms.log"
11
11
def log ( msg )
12
- log = File . open ( $logfile, 'a' )
12
+ log = open_relative ( $logfile, 'a' )
13
13
log . write ( "#{ Time . now . utc . iso8601 } : #{ msg } " )
14
14
log . write ( "\n " )
15
+ log . write msg
15
16
end
16
17
17
18
# needs to happen before we change directories
@@ -21,7 +22,7 @@ def rel(name)
21
22
end
22
23
23
24
# return open file relative to this file's current directory
24
- def openrel ( name , mode = 'r' )
25
+ def open_relative ( name , mode = 'r' )
25
26
File . open ( rel ( name ) , mode )
26
27
end
27
28
@@ -41,22 +42,19 @@ def sh(cmd, ignore_errors=false)
41
42
42
43
# Given an env name (like "test", "uat", "pre") go get the appropriate environment
43
44
# variables and make them relative to this file. Return an env hash.
44
- def getenv ( envname )
45
- envdir = File . join ( ENV [ "CONNECT_VBMS_ENV_DIR" ] , envname )
46
-
45
+ def getenv ( environment_name )
47
46
env = { }
47
+ environment_directory = File . join ( ENV [ "CONNECT_VBMS_ENV_DIR" ] , environment_name )
48
48
env [ :url ] = ENV . fetch ( "CONNECT_VBMS_URL" , nil )
49
49
env [ :keyfile ] = ENV . fetch ( "CONNECT_VBMS_KEYFILE" , nil )
50
50
env [ :saml ] = ENV . fetch ( "CONNECT_VBMS_SAML" , nil )
51
51
env [ :key ] = ENV . fetch ( "CONNECT_VBMS_KEY" , nil )
52
52
env [ :keypass ] = ENV . fetch ( "CONNECT_VBMS_KEYPASS" , nil )
53
53
env [ :cacert ] = ENV . fetch ( "CONNECT_VBMS_CACERT" , nil )
54
54
env [ :cert ] = ENV . fetch ( "CONNECT_VBMS_CERT" , nil )
55
-
56
55
[ :keyfile , :saml , :key , :cacert , :cert ] . each do |k |
57
- env [ k ] = File . absolute_path ( File . join ( envdir , env [ k ] ) ) if env [ k ]
56
+ env [ k ] = File . absolute_path ( File . join ( environment_directory , env [ k ] ) ) if env [ k ]
58
57
end
59
-
60
58
env
61
59
end
62
60
@@ -76,14 +74,14 @@ def upload_doc(options)
76
74
log ( "Connecting with env: #{ env } " )
77
75
file = prepare_xml ( options [ :pdf ] , options [ :file_number ] , options [ :received_dt ] , options [ :first_name ] , options [ :middle_name ] , options [ :last_name ] , options [ :exam_name ] )
78
76
encrypted_xml = prepare_upload ( file , env )
79
- response = send_document ( encrypted_xml , env , options [ :pdf ] )
77
+ response = send_document ( encrypted_xml , env , options )
80
78
#handle_response(response)
81
79
rescue Exception => e
82
80
puts e . backtrace
83
81
log ( e . backtrace )
84
82
puts e . message
85
83
log ( e . message )
86
- File . open ( "/tmp/ signed.xml", 'w ' ) . write ( encrypted_xml )
84
+ open_relative ( "../log/ #{ options [ :file_number ] } - signed.xml.log ", 'a ' ) . write ( encrypted_xml )
87
85
ensure
88
86
file . close
89
87
file . unlink
@@ -127,16 +125,14 @@ def prepare_xml(pdf, file_number, received_dt, first_name, middle_name, last_nam
127
125
# TODO: true if the claim associated with this evaluation is still pending,
128
126
# false otherwise
129
127
newMail = "true"
130
-
131
- template = openrel ( "upload_document_xml_template.xml.erb" ) . read
128
+ template = open_relative ( "templates/upload_document_xml_template.xml.erb" ) . read
132
129
xml = ERB . new ( template ) . result ( binding )
133
130
log ( "Unencrypted XML:\n #{ xml } " )
134
-
135
131
write_tempfile ( xml )
136
132
end
137
133
138
134
def prepare_upload ( xmlfile , env )
139
- sh "java -classpath '.:../lib/*' UploadDocumentWithAssociations #{ xmlfile . path } #{ env [ :keyfile ] } #{ env [ :keypass ] } "
135
+ sh "java -classpath '../classes :../lib/*:../lib ' UploadDocumentWithAssociations #{ xmlfile . path } #{ env [ :keyfile ] } #{ env [ :keypass ] } "
140
136
end
141
137
142
138
def inject_saml ( doc , env )
@@ -172,17 +168,16 @@ def build_request(url, data, headers, key: nil, keypass: nil, cert: nil, cacert:
172
168
request
173
169
end
174
170
175
- def send_document ( xml , env , pdf )
171
+ def send_document ( xml , env , options )
176
172
# inject SAML header
177
173
doc = XML ::Parser . string ( xml ) . parse
178
174
inject_saml ( doc , env )
179
175
remove_mustUnderstand ( doc )
180
176
xml = doc . to_s
181
- File . open ( "/tmp/final.xml" , 'w' ) . write ( xml )
182
- filename = File . split ( pdf ) [ 1 ]
183
- pdf = IO . read ( pdf )
184
-
185
- req = ERB . new ( openrel ( "mtom_request.erb" ) . read ) . result ( binding )
177
+ open_relative ( "../log/#{ options [ :file_number ] } -final.xml.log" , 'a' ) . write ( xml )
178
+ filename = File . split ( options [ :pdf ] ) [ 1 ]
179
+ pdf = IO . read ( options [ :pdf ] )
180
+ req = ERB . new ( open_relative ( "templates/mtom_request.erb" ) . read ) . result ( binding )
186
181
headers = {
187
182
'Content-Type' => 'Multipart/Related; type="application/xop+xml"; start-info="application/soap+xml"; boundary="boundary_1234"'
188
183
}
@@ -230,7 +225,7 @@ def handle_response(response)
230
225
# now here's the hackiest thing in the world. This command is going to fail,
231
226
# because we can't get the signatures to properly get decrypted. So run the
232
227
# command, handle the error, and pull the message out of the file >:|
233
- sh "java -classpath '.:../lib/*' DecryptMessage" , true
228
+ sh "java -classpath '../classes :../lib/*' DecryptMessage" , true
234
229
235
230
end
236
231
@@ -273,7 +268,7 @@ def parse(args)
273
268
options [ :env ] = v
274
269
end
275
270
276
- opts . on ( "--logfile [logfile]" , "Logfile to use. Defaults to /usr/local/var /log/connect_vbms.log" ) do |v |
271
+ opts . on ( "--logfile [logfile]" , "Logfile to use. Defaults to .. /log/connect_vbms.log" ) do |v |
277
272
$logfile = v
278
273
end
279
274
end
@@ -291,4 +286,4 @@ def parse(args)
291
286
end
292
287
293
288
options = parse ( ARGV )
294
- upload_doc ( options )
289
+ upload_doc ( options )
0 commit comments