t2-server 1.1.0 → 1.2.0

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 (68) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +1 -0
  3. data/.ruby-env +1 -0
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/.travis.yml +7 -1
  7. data/CHANGES.rdoc +49 -0
  8. data/README.rdoc +10 -8
  9. data/bin/t2-delete-runs +0 -3
  10. data/lib/t2-server-cli.rb +16 -9
  11. data/lib/t2-server/exceptions.rb +7 -19
  12. data/lib/t2-server/net/connection.rb +14 -6
  13. data/lib/t2-server/net/credentials.rb +12 -1
  14. data/lib/t2-server/net/parameters.rb +3 -3
  15. data/lib/t2-server/port.rb +12 -29
  16. data/lib/t2-server/run.rb +54 -35
  17. data/lib/t2-server/server.rb +3 -4
  18. data/lib/t2-server/xml.rb +0 -1
  19. data/lib/t2-server/xml/methods.rb +97 -4
  20. data/t2-server.gemspec +4 -1
  21. data/test/helpers/fake-run.rb +47 -0
  22. data/test/helpers/test-cache.rb +49 -0
  23. data/test/helpers/test-xml.rb +36 -0
  24. data/test/helpers/timezone.rb +39 -0
  25. data/test/mocked-server-responses/.gitattributes +1 -0
  26. data/test/mocked-server-responses/get-admin.raw +6 -0
  27. data/test/mocked-server-responses/get-rest-policy-runlimit.raw +6 -0
  28. data/test/mocked-server-responses/get-rest-policy.raw +6 -0
  29. data/test/mocked-server-responses/get-rest-run-input-expected.raw +6 -0
  30. data/test/mocked-server-responses/get-rest-run-input.raw +6 -0
  31. data/test/mocked-server-responses/get-rest-run-interaction-feed-0.raw +11 -0
  32. data/test/mocked-server-responses/get-rest-run-interaction-feed-1.raw +92 -0
  33. data/test/mocked-server-responses/get-rest-run-interaction-feed-2.raw +80 -0
  34. data/test/mocked-server-responses/get-rest-run-name.raw +6 -0
  35. data/test/mocked-server-responses/get-rest-run-output-list-errors.raw +6 -0
  36. data/test/mocked-server-responses/get-rest-run-output.raw +6 -0
  37. data/test/mocked-server-responses/get-rest-run-security-permissions.raw +6 -0
  38. data/test/mocked-server-responses/get-rest-run-security.raw +6 -0
  39. data/test/mocked-server-responses/get-rest-run.raw +6 -0
  40. data/test/mocked-server-responses/get-rest-runs.raw +6 -0
  41. data/test/mocked-server-responses/get-rest.raw +6 -0
  42. data/test/mocked-server-responses/log.txt +1 -0
  43. data/test/mocked-server-responses/mocks.rb +107 -0
  44. data/test/mocked-server-responses/options-admin-allownew.raw +7 -0
  45. data/test/tc_admin.rb +52 -24
  46. data/test/tc_admin_live.rb +66 -0
  47. data/test/tc_connection.rb +87 -0
  48. data/test/tc_connection_exceptions.rb +86 -0
  49. data/test/tc_credentials.rb +73 -0
  50. data/test/tc_interaction.rb +182 -0
  51. data/test/{tc_misc.rb → tc_misc_live.rb} +3 -1
  52. data/test/tc_params.rb +82 -4
  53. data/test/tc_perms.rb +54 -101
  54. data/test/tc_perms_live.rb +150 -0
  55. data/test/tc_ports.rb +192 -0
  56. data/test/tc_run.rb +333 -350
  57. data/test/tc_run_live.rb +453 -0
  58. data/test/{tc_secure.rb → tc_secure_live.rb} +30 -29
  59. data/test/tc_server.rb +115 -42
  60. data/test/tc_server_live.rb +92 -0
  61. data/test/tc_server_version.rb +19 -0
  62. data/test/tc_xml_messages.rb +201 -0
  63. data/test/ts_t2server.rb +37 -43
  64. data/test/workflows/secure/heater-pk.pem +24 -18
  65. data/test/workflows/secure/user-cert.p12 +0 -0
  66. data/version.yml +1 -1
  67. metadata +136 -29
  68. data/lib/t2-server/xml/fragments.rb +0 -78
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MDViZjcxNjNjYzgwNjJkNThmYzEwMjcyOWRjZTYzM2ZlNGNmNzRmYg==
5
+ data.tar.gz: !binary |-
6
+ MjMyMWEzOGM2N2Q1YWQ1YTYwYmRjMGIyZGY1OGViY2IxMzAzM2NkYQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ Yzk5ZmFiYWE5NThmYzYyNDdjYzhkMjQ3ODAwNThkOTEwMDBkZjI4ZmY4ZjU4
10
+ YWQ2N2Q2N2EzN2VhNWU1OGNmYTFkMmVmMzFlOWQ3ZWQ3MTI2ZGY1NGZiMWZi
11
+ MGQ4MDcyMjRkYTkyNjU2NWFkZjM3YTVjOWU4ZmYwMWMzNDg3ZGM=
12
+ data.tar.gz: !binary |-
13
+ Mzk5NTU3MWE5ZjczMzM0YWViNTYyYTE5OWFiMzc5MzA4ZWEzODkzMWYwZThm
14
+ MGU5OGI4NjdjNmFlMzgzZjlkYzFlZjFjNjNhNDdmYjk3MWYyZDdjMDMzY2Y1
15
+ Yzk2MmE0YjVjZDAzMjc3ZGQyNjNkNzViNDNhODMxZTI1ODcxNDM=
data/.gitignore CHANGED
@@ -1,6 +1,7 @@
1
1
  *~
2
2
  pkg/
3
3
  html/
4
+ coverage/
4
5
  .buildpath
5
6
  .project
6
7
  .idea
@@ -0,0 +1 @@
1
+ RUBYLIB=./lib:../lib
@@ -0,0 +1 @@
1
+ t2-server
@@ -0,0 +1 @@
1
+ ruby-1.9.3-p484
@@ -3,4 +3,10 @@ cache: bundler
3
3
  rvm:
4
4
  - 1.9.3
5
5
  - 2.0.0
6
- - 2.1.0
6
+ - 2.1.2
7
+ - rbx-2
8
+ - ruby-head
9
+ matrix:
10
+ allow_failures:
11
+ - rvm: rbx-2
12
+ - rvm: ruby-head
@@ -1,5 +1,54 @@
1
1
  = Changes log for the T2 Ruby Gem
2
2
 
3
+ == Version 1.2.0
4
+
5
+ * Test provenance collection on version 2.5.4 and up only.
6
+ * Only run tests against a live server if an address is supplied.
7
+ * Add a test case to test the connection factory.
8
+ * Set up mocking of Net::HTTP and mock creation of a run.
9
+ * Mock testing server run limits and deleting all runs.
10
+ * Add Coveralls integration to the tests.
11
+ * Add tests for the credentials classes.
12
+ * Add a simple check for parsing the server version.
13
+ * Test a full run of a workflow.
14
+ * Fix the parameters classes with initial parameters.
15
+ * Test custom CA connection parameters.
16
+ * Test a network timeout.
17
+ * Catch Net::HTTP::Persistent::Error internally.
18
+ * Net::HTTP::Persistent::Error is now wrapped internally.
19
+ * Remove the unused RunNotFoundError.
20
+ * Fix documentation for Run#upload_data.
21
+ * Set minimum ruby version to be 1.9.3 in the spec.
22
+ * Modernize the installation instructions.
23
+ * Remove the unused workflow upload XML fragment.
24
+ * Add XML generation methods for server messages.
25
+ * Programmatic generation of mkdir server message.
26
+ * Programmatic generation of the upload server message.
27
+ * Streamline XML node generation methods.
28
+ * Programmatically generate input server messages.
29
+ * Generate permissions server message fragment.
30
+ * Generate trusts server message fragment.
31
+ * Generate credentials server messages.
32
+ * Streamline the generation of hierarchical XML nodes.
33
+ * Setup tests for the XML messages sent to server.
34
+ * Factor out the common help and version CLI options.
35
+ * Factor out the different SSL config options for HTTPS connections.
36
+ * Neaten up the code to get a run's resource links.
37
+ * Fix typo in Run#grant_permission.
38
+ * Add a parse method to the credentials objects.
39
+ * Found a way to better test the credentials objects.
40
+ * Fix up the test suite driver code.
41
+ * Update the public key of the secure remote services.
42
+ * Update the client certificate for secure remote services.
43
+ * Stop using a pre-cooked server reply for Run#status.
44
+ * Only download a range of bytes if requested for outputs.
45
+ * Streamline the OutputPort methods for getting data.
46
+ * Remove unused private method (path) from OutputPort.
47
+ * Factor out I/O Port processing.
48
+ * Cache a run's finished state when it has finished.
49
+ * Fix the client authentication connection settings.
50
+ * Test InputPort and OutputPort.
51
+
3
52
  == Version 1.1.0
4
53
 
5
54
  * Remove hirb as a runtime dependency.
@@ -6,9 +6,10 @@ URL:: http://www.taverna.org.uk/
6
6
  Licence:: BSD (See LICENCE or http://www.opensource.org/licenses/bsd-license.php)
7
7
  Copyright:: (c) 2010-2014 The University of Manchester, UK
8
8
 
9
- {<img src="https://badge.fury.io/rb/t2-server.png" alt="Gem Version" />}[http://badge.fury.io/rb/t2-server]
10
- {<img src="https://codeclimate.com/github/myGrid/t2-server-gem.png" />}[https://codeclimate.com/github/myGrid/t2-server-gem]
9
+ {<img src="https://badge.fury.io/rb/t2-server.svg" alt="Gem Version" />}[http://badge.fury.io/rb/t2-server]
10
+ {<img src="https://codeclimate.com/github/myGrid/t2-server-gem/badges/gpa.svg" />}[https://codeclimate.com/github/myGrid/t2-server-gem]
11
11
  {<img src="https://travis-ci.org/myGrid/t2-server-gem.svg?branch=master" alt="Build Status" />}[https://travis-ci.org/myGrid/t2-server-gem]
12
+ {<img src="https://coveralls.io/repos/myGrid/t2-server-gem/badge.png?branch=master" alt="Coverage Status" />}[https://coveralls.io/r/myGrid/t2-server-gem?branch=master]
12
13
 
13
14
  == Synopsis
14
15
 
@@ -16,12 +17,13 @@ This is a Ruby library to interface with the Taverna 2 Server REST API.
16
17
 
17
18
  == Installation
18
19
 
19
- Ensure that gem itself is up to date:
20
- [sudo] gem update --system
21
-
22
- Then simply install as you would any other gem:
20
+ Simply install as you would any other gem:
23
21
  [sudo] gem install t2-server
24
22
 
23
+ Or use {Bundler}[http://bundler.io/], with
24
+ gem 't2-server', '~> 1.0'
25
+ in your +Gemfile+, for example.
26
+
25
27
  In case of problems with the above the gem is available for download here:
26
28
  https://rubygems.org/gems/t2-server
27
29
 
@@ -57,10 +59,10 @@ version pairings:
57
59
  === Ruby
58
60
 
59
61
  This library is known to work with the following versions of Ruby:
60
- * 1.9.2
61
62
  * 1.9.3 +*
62
63
  * 2.0.0 +*
63
- * 2.1.0 +
64
+ * 2.1.2 +*
65
+ * rbx 2.2 +
64
66
 
65
67
  Those marked with an asterisk (*) are fully supported and bugs found against
66
68
  them will be fixed. Other versions may work but are not tested or supported.
@@ -88,9 +88,6 @@ for run in server_runs
88
88
  run.delete
89
89
  end
90
90
  end
91
- rescue T2Server::RunNotFoundError => rnf
92
- puts "Run '#{run.id}' not found - skipping."
93
- next
94
91
  rescue T2Server::AuthorizationError => ae
95
92
  puts "You are not authorized to delete run '#{run.id}' - skipping."
96
93
  next
@@ -53,7 +53,7 @@ module T2Server
53
53
  ssl_auth_opts(opt, conn_params)
54
54
  ssl_transport_opts(opt, conn_params)
55
55
 
56
- # common options
56
+ # Simple credential options
57
57
  opt.on_tail("-u", "--username=USERNAME", "The username to use for " +
58
58
  "server operations.") do |val|
59
59
  user = val.chomp
@@ -62,14 +62,9 @@ module T2Server
62
62
  "the supplied username.") do |val|
63
63
  pass = val.chomp
64
64
  end
65
- opt.on_tail("-h", "-?", "--help", "Show this help message.") do
66
- puts opt
67
- exit
68
- end
69
- opt.on_tail("-v", "--version", "Show the version.") do
70
- puts "Taverna 2 Server Ruby Gem version: #{T2Server::Version::STRING}"
71
- exit
72
- end
65
+
66
+ # Common options
67
+ common_opts(opt)
73
68
  end
74
69
 
75
70
  # parse options
@@ -96,6 +91,18 @@ module T2Server
96
91
 
97
92
  private
98
93
 
94
+ # The help and version options.
95
+ def common_opts(opt)
96
+ opt.on_tail("-h", "-?", "--help", "Show this help message.") do
97
+ puts opt
98
+ exit
99
+ end
100
+ opt.on_tail("-v", "--version", "Show the version.") do
101
+ puts "Taverna 2 Server Ruby Gem version: #{T2Server::Version::STRING}"
102
+ exit
103
+ end
104
+ end
105
+
99
106
  # The SSL authentication and peer verification options.
100
107
  def ssl_auth_opts(opt, conn_params)
101
108
  opt.on("-E CERT_FILE:PASSWORD", "--cert=CERT_FILE:PASSWORD", "Use " +
@@ -30,7 +30,7 @@
30
30
  #
31
31
  # Author: Robert Haines
32
32
 
33
- require 'net/http'
33
+ require 'net/http/persistent'
34
34
 
35
35
  module T2Server
36
36
  # :stopdoc:
@@ -41,8 +41,10 @@ module T2Server
41
41
  module InternalHTTPError
42
42
  end
43
43
 
44
- # These are the HTTP errors we want to catch.
45
- # Add the above exception as an ancestor to them all.
44
+ # These are the HTTP errors we want to catch. Add the above exception as an
45
+ # ancestor to them all. Some are caught by Net::HTTP::Persistent and
46
+ # re-raised as a Net::HTTP::Persistent::Error but keep them listed here just
47
+ # in case.
46
48
  [
47
49
  EOFError,
48
50
  SocketError,
@@ -53,7 +55,8 @@ module T2Server
53
55
  Errno::ECONNREFUSED,
54
56
  Net::HTTPBadResponse,
55
57
  Net::HTTPHeaderSyntaxError,
56
- Net::ProtocolError
58
+ Net::ProtocolError,
59
+ Net::HTTP::Persistent::Error
57
60
  ].each {|err| err.send(:include, InternalHTTPError)}
58
61
 
59
62
  # :startdoc:
@@ -112,21 +115,6 @@ module T2Server
112
115
  end
113
116
  end
114
117
 
115
- # Raised when the run that is being operated on cannot be found. If the
116
- # expectation is that the run exists then it could have been destroyed by
117
- # a timeout or another user.
118
- class RunNotFoundError < T2ServerError
119
-
120
- # The identifier of the run that was not found on the server.
121
- attr_reader :identifier
122
-
123
- # Create a new RunNotFoundError with the specified identifier.
124
- def initialize(id)
125
- @identifier = id
126
- super "Could not find run #{@identifier}"
127
- end
128
- end
129
-
130
118
  # Indicates that the attribute that the user is trying to read/change does
131
119
  # not exist. The attribute could be a server or run attribute.
132
120
  class AttributeNotFoundError < T2ServerError
@@ -306,7 +306,13 @@ module T2Server
306
306
  @http.ssl_version = @params[:ssl_version]
307
307
  end
308
308
 
309
- # Peer verification
309
+ set_peer_verification
310
+ set_client_authentication
311
+ end
312
+
313
+ private
314
+
315
+ def set_peer_verification
310
316
  if @params[:verify_peer]
311
317
  if @params[:ca_file]
312
318
  @http.ca_file = @params[:ca_file]
@@ -328,14 +334,16 @@ module T2Server
328
334
  else
329
335
  @http.verify_mode = OpenSSL::SSL::VERIFY_NONE
330
336
  end
337
+ end
331
338
 
332
- # Client authentication
339
+ def set_client_authentication
333
340
  if @params[:client_certificate]
334
- pem = File.read(@params[:client_certificate])
335
- @http.certificate = OpenSSL::X509::Certificate.new(pem)
336
- @http.private_key = OpenSSL::PKey::RSA.new(pem,
337
- @params[:client_password])
341
+ cert = File.read(@params[:client_certificate])
342
+ pkcs12 = OpenSSL::PKCS12.new(cert, @params[:client_password])
343
+ @http.certificate = pkcs12.certificate
344
+ @http.private_key = pkcs12.key
338
345
  end
339
346
  end
347
+
340
348
  end
341
349
  end
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2010-2012 The University of Manchester, UK.
1
+ # Copyright (c) 2010-2014 The University of Manchester, UK.
2
2
  #
3
3
  # All rights reserved.
4
4
  #
@@ -52,6 +52,17 @@ module T2Server
52
52
  end
53
53
  # :startdoc:
54
54
 
55
+ # :call-seq:
56
+ # parse(userinfo) -> Credentials
57
+ #
58
+ # Parse a typical userinfo style string, such as "username:password", into
59
+ # a credentials object. In this case the credentials would have a username
60
+ # of "username" and a password of "password".
61
+ def self.parse(userinfo)
62
+ user, pass = userinfo.split(':', 2)
63
+ new(user, pass)
64
+ end
65
+
55
66
  # :call-seq:
56
67
  # to_s -> string
57
68
  #
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2010-2012 The University of Manchester, UK.
1
+ # Copyright (c) 2010-2014 The University of Manchester, UK.
2
2
  #
3
3
  # All rights reserved.
4
4
  #
@@ -122,7 +122,7 @@ module T2Server
122
122
  # _path_ can either be a directory where the required certificate is stored
123
123
  # or the path to the certificate file itself.
124
124
  def initialize(path)
125
- super
125
+ super()
126
126
 
127
127
  case path
128
128
  when String
@@ -147,7 +147,7 @@ module T2Server
147
147
  # encrypted. If _password_ is not specified, but needed, then the
148
148
  # underlying SSL implementation may ask for it if it can.
149
149
  def initialize(cert, password = nil)
150
- super
150
+ super()
151
151
 
152
152
  case cert
153
153
  when String
@@ -231,14 +231,9 @@ module T2Server
231
231
  # run.output_port("port_name")[0].value(0..100)
232
232
  def value(range = nil, &block)
233
233
  if depth == 0
234
- if range.nil?
235
- @structure.value(&block)
236
- else
237
- @structure.value(range, &block)
238
- end
234
+ @structure.value(range, &block)
239
235
  else
240
- @values = strip(:value) if @values.nil?
241
- @values
236
+ @values ||= strip(:value)
242
237
  end
243
238
  end
244
239
 
@@ -261,11 +256,7 @@ module T2Server
261
256
  "Stream passed in must provide a write method" unless
262
257
  stream.respond_to? :write
263
258
 
264
- if range.nil?
265
- @structure.stream_value(stream)
266
- else
267
- @structure.stream_value(stream, range)
268
- end
259
+ @structure.stream_value(stream, range)
269
260
  end
270
261
 
271
262
  # :call-seq:
@@ -282,11 +273,7 @@ module T2Server
282
273
  def write_value_to_file(filename, range = nil)
283
274
  return 0 unless depth == 0
284
275
 
285
- if range.nil?
286
- @structure.write_value_to_file(filename)
287
- else
288
- @structure.write_value_to_file(filename, range)
289
- end
276
+ @structure.write_value_to_file(filename, range)
290
277
  end
291
278
 
292
279
  # :call-seq:
@@ -407,12 +394,6 @@ module T2Server
407
394
  end
408
395
  end
409
396
 
410
- # Generate the path to the actual data for a data value.
411
- def path(ref)
412
- parts = ref.split('/')
413
- @depth == 0 ? parts[-1] : "/" + parts[-(@depth + 1)..-1].join('/')
414
- end
415
-
416
397
  # Strip the requested attribute from the raw values structure.
417
398
  def strip(attribute, struct = @structure)
418
399
  if struct.instance_of? Array
@@ -477,22 +458,24 @@ module T2Server
477
458
  # This method does not cache any data.
478
459
  #
479
460
  # If this port is an error then this value will be the error message.
480
- def value(range = 0...@size, &block)
461
+ def value(range = nil, &block)
481
462
  # The following block is a workaround for Taverna Server versions prior
482
463
  # to 2.4.1 and can be removed when support for those versions is no
483
464
  # longer required.
484
465
  if error? && @size == 0
485
466
  value = @port.download(@reference)
486
467
  @size = value.size
487
- range = 0...@size if range.min.nil?
468
+ range = 0...@size if range.nil? || range.min.nil?
488
469
  return value[range]
489
470
  end
490
471
 
491
472
  return "" if @type == EMPTY_TYPE
492
473
 
493
474
  # Check that the range provided is sensible
494
- range = 0..range.max if range.min < 0
495
- range = range.min...@size if range.max >= @size
475
+ unless range.nil?
476
+ range = 0..range.max if range.min < 0
477
+ range = range.min...@size if range.max >= @size
478
+ end
496
479
 
497
480
  @port.download(@reference, range, &block)
498
481
  end
@@ -506,7 +489,7 @@ module T2Server
506
489
  # File, for example. No data is cached by this method.
507
490
  #
508
491
  # The number of bytes written to the stream is returned.
509
- def stream_value(stream, range = 0...@size)
492
+ def stream_value(stream, range = nil)
510
493
  raise ArgumentError,
511
494
  "Stream passed in must provide a write method" unless
512
495
  stream.respond_to? :write
@@ -527,7 +510,7 @@ module T2Server
527
510
  # Stream this port value directly to a file. If a range is supplied then
528
511
  # just that range of data is downloaded from the server. No data is cached
529
512
  # by this method.
530
- def write_value_to_file(filename, range = 0...@size)
513
+ def write_value_to_file(filename, range = nil)
531
514
  File.open(filename, "wb") do |file|
532
515
  stream_value(file, range)
533
516
  end
@@ -115,6 +115,9 @@ module T2Server
115
115
 
116
116
  @credentials = credentials
117
117
 
118
+ # Has this Run finished executing on the server?
119
+ @finished = false
120
+
118
121
  # Has this Run object been deleted from the server?
119
122
  @deleted = false
120
123
 
@@ -320,7 +323,13 @@ module T2Server
320
323
  # :running or :finished.
321
324
  def status
322
325
  return :deleted if @deleted
323
- Status.to_sym(@server.read(links[:status], "text/plain", @credentials))
326
+ return :finished if @finished
327
+
328
+ state = Status.to_sym(@server.read(links[:status], "text/plain",
329
+ @credentials))
330
+
331
+ @finished = (state == :finished)
332
+ state
324
333
  end
325
334
 
326
335
  # :call-seq:
@@ -441,11 +450,14 @@ module T2Server
441
450
  end
442
451
 
443
452
  # :call-seq:
444
- # upload_data(data, remote_name, remote_directory = "") -> true or false
453
+ # upload_data(data, remote_name, remote_directory = "") -> URI
445
454
  #
446
455
  # Upload data to the server and store it in <tt>remote_file</tt>. The
447
456
  # remote directory to put this file in can also be specified, but if it is
448
457
  # it must first have been created by a call to Run#mkdir.
458
+ #
459
+ # Returns the URI of the file on the server in which the data has been
460
+ # stored.
449
461
  def upload_data(data, remote_name, remote_directory = "")
450
462
  location_uri = Util.append_to_uri_path(links[:wdir], remote_directory)
451
463
  @server.upload_data(data, remote_name, location_uri, @credentials)
@@ -730,7 +742,7 @@ module T2Server
730
742
  def grant_permission(username, permission)
731
743
  return unless owner?
732
744
 
733
- value = XML::Fragments::PERM_UPDATE % [username, permission.to_s]
745
+ value = xml_permissions_fragment(username, permission.to_s)
734
746
  @server.create(links[:sec_perms], value, "application/xml", @credentials)
735
747
  end
736
748
 
@@ -797,8 +809,7 @@ module T2Server
797
809
  # basic uri checks
798
810
  uri = _check_cred_uri(uri)
799
811
 
800
- cred = XML::Fragments::USERPASS_CRED % [uri, username, password]
801
- value = XML::Fragments::CREDENTIAL % cred
812
+ value = xml_password_cred_fragment(uri, username, password)
802
813
 
803
814
  if cred_uri.nil?
804
815
  @server.create(links[:sec_creds], value, "application/xml",
@@ -829,9 +840,7 @@ module T2Server
829
840
  # basic uri checks
830
841
  uri = _check_cred_uri(uri)
831
842
 
832
- cred = XML::Fragments::KEYPAIR_CRED % [uri, name, contents,
833
- type, password]
834
- value = XML::Fragments::CREDENTIAL % cred
843
+ value = xml_keypair_cred_fragment(uri, name, contents, type, password)
835
844
 
836
845
  @server.create(links[:sec_creds], value, "application/xml", @credentials)
837
846
  end
@@ -908,7 +917,7 @@ module T2Server
908
917
 
909
918
  contents = Base64.encode64(IO.read(filename))
910
919
 
911
- value = XML::Fragments::TRUST % [contents, type]
920
+ value = xml_trust_fragment(contents, type)
912
921
  @server.create(links[:sec_trusts], value, "application/xml", @credentials)
913
922
  end
914
923
 
@@ -1060,9 +1069,9 @@ module T2Server
1060
1069
  # use a remote file.
1061
1070
  port.remote_file = upload_file(port.file) unless port.remote_file?
1062
1071
 
1063
- xml_value = XML::Fragments::RUNINPUTFILE % xml_text_node(port.file)
1072
+ xml_value = xml_input_fragment(port.file, :file)
1064
1073
  else
1065
- xml_value = XML::Fragments::RUNINPUTVALUE % xml_text_node(port.value)
1074
+ xml_value = xml_input_fragment(port.value)
1066
1075
  end
1067
1076
 
1068
1077
  @server.update(uri, xml_value, "application/xml", @credentials)
@@ -1112,33 +1121,35 @@ module T2Server
1112
1121
  end
1113
1122
 
1114
1123
  def _get_input_port_info
1115
- ports = {}
1116
1124
  port_desc = @server.read(links[:inputexp], "application/xml",
1117
1125
  @credentials)
1118
1126
 
1119
1127
  doc = xml_document(port_desc)
1120
1128
 
1121
- xpath_find(doc, @@xpaths[:port_in]).each do |inp|
1122
- port = InputPort.new(self, inp)
1123
- ports[port.name] = port
1124
- end
1125
-
1126
- ports
1129
+ _get_port_info(doc, :port_in)
1127
1130
  end
1128
1131
 
1129
1132
  def _get_output_port_info
1130
- ports = {}
1131
-
1132
1133
  begin
1133
1134
  port_desc = @server.read(links[:output], "application/xml", @credentials)
1134
1135
  rescue AttributeNotFoundError => anfe
1135
- return ports
1136
+ return {}
1136
1137
  end
1137
1138
 
1138
1139
  doc = xml_document(port_desc)
1139
1140
 
1140
- xpath_find(doc, @@xpaths[:port_out]).each do |out|
1141
- port = OutputPort.new(self, out)
1141
+ _get_port_info(doc, :port_out)
1142
+ end
1143
+
1144
+ def _get_port_info(doc, type)
1145
+ ports = {}
1146
+
1147
+ xpath_find(doc, @@xpaths[type]).each do |desc|
1148
+ port = if type == :port_out
1149
+ OutputPort.new(self, desc)
1150
+ else
1151
+ InputPort.new(self, desc)
1152
+ end
1142
1153
  ports[port.name] = port
1143
1154
  end
1144
1155
 
@@ -1177,20 +1188,12 @@ module T2Server
1177
1188
 
1178
1189
  links.merge! get_uris_from_doc(doc, [:baclava, :inputexp])
1179
1190
 
1180
- # set io properties
1181
- links[:io] = Util.append_to_uri_path(links[:listeners], "io")
1182
- [:stdout, :stderr, :exitcode].each do |res|
1183
- links[res] = Util.append_to_uri_path(links[:io], "properties/#{res}")
1184
- end
1191
+ # IO properties links
1192
+ _get_io_properties_links(links)
1185
1193
 
1186
- # security properties - only available to the owner of a run
1194
+ # Security properties links - only available to the owner of a run
1187
1195
  if owner?
1188
- securectx = @server.read(links[:securectx], "application/xml",
1189
- @credentials)
1190
- doc = xml_document(securectx)
1191
-
1192
- links.merge! get_uris_from_doc(doc,
1193
- [:sec_creds, :sec_perms, :sec_trusts])
1196
+ _get_security_links(links)
1194
1197
  end
1195
1198
 
1196
1199
  links
@@ -1209,6 +1212,22 @@ module T2Server
1209
1212
  end
1210
1213
  end
1211
1214
 
1215
+ def _get_io_properties_links(links)
1216
+ links[:io] = Util.append_to_uri_path(links[:listeners], "io")
1217
+ [:stdout, :stderr, :exitcode].each do |res|
1218
+ links[res] = Util.append_to_uri_path(links[:io], "properties/#{res}")
1219
+ end
1220
+ end
1221
+
1222
+ def _get_security_links(links)
1223
+ securectx = @server.read(links[:securectx], "application/xml",
1224
+ @credentials)
1225
+ doc = xml_document(securectx)
1226
+
1227
+ links.merge! get_uris_from_doc(doc,
1228
+ [:sec_creds, :sec_perms, :sec_trusts])
1229
+ end
1230
+
1212
1231
  def download_or_stream(param, uri, type, &block)
1213
1232
  if param.respond_to? :write
1214
1233
  @server.read_to_stream(param, uri, type, @credentials)