t2-server 0.6.1 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/.rvmrc +1 -0
  2. data/CHANGES.rdoc +48 -0
  3. data/LICENCE.rdoc +2 -2
  4. data/README.rdoc +245 -10
  5. data/Rakefile +108 -0
  6. data/bin/t2-delete-runs +21 -34
  7. data/bin/t2-get-output +134 -0
  8. data/bin/t2-run-workflow +121 -109
  9. data/bin/t2-server-admin +128 -0
  10. data/bin/t2-server-info +25 -38
  11. data/lib/t2-server-cli.rb +116 -0
  12. data/lib/t2-server.rb +16 -27
  13. data/lib/t2-server/admin.rb +147 -0
  14. data/lib/t2-server/connection-parameters.rb +144 -0
  15. data/lib/t2-server/connection.rb +352 -0
  16. data/lib/t2-server/credentials.rb +84 -0
  17. data/lib/t2-server/exceptions.rb +42 -21
  18. data/lib/t2-server/port.rb +472 -0
  19. data/lib/t2-server/run.rb +822 -227
  20. data/lib/t2-server/server.rb +313 -317
  21. data/lib/t2-server/util.rb +71 -0
  22. data/lib/t2-server/xml/libxml.rb +87 -0
  23. data/lib/t2-server/xml/nokogiri.rb +85 -0
  24. data/lib/t2-server/xml/rexml.rb +85 -0
  25. data/lib/t2-server/xml/xml.rb +111 -0
  26. data/lib/t2server.rb +4 -1
  27. data/t2-server.gemspec +112 -0
  28. data/test/tc_admin.rb +63 -0
  29. data/test/{tc_paths.rb → tc_params.rb} +11 -25
  30. data/test/tc_perms.rb +132 -0
  31. data/test/tc_run.rb +200 -67
  32. data/test/tc_secure.rb +191 -0
  33. data/test/tc_server.rb +25 -23
  34. data/test/tc_util.rb +74 -0
  35. data/test/ts_t2server.rb +57 -12
  36. data/test/workflows/always_fail.t2flow +69 -0
  37. data/test/workflows/list_and_value.t2flow +12 -0
  38. data/test/workflows/list_with_errors.t2flow +107 -0
  39. data/test/workflows/secure/basic-http.t2flow +74 -0
  40. data/test/workflows/secure/basic-https.t2flow +74 -0
  41. data/test/workflows/secure/client-https.t2flow +162 -0
  42. data/test/workflows/secure/digest-http.t2flow +129 -0
  43. data/test/workflows/secure/digest-https.t2flow +107 -0
  44. data/test/workflows/secure/heater-pk.pem +20 -0
  45. data/test/workflows/secure/user-cert.p12 +0 -0
  46. data/test/workflows/secure/ws-http.t2flow +180 -0
  47. data/test/workflows/secure/ws-https.t2flow +180 -0
  48. data/test/workflows/strings.txt +10 -0
  49. data/test/workflows/xml_xpath.t2flow +136 -136
  50. data/version.yml +4 -0
  51. metadata +132 -34
  52. data/lib/t2-server/xml.rb +0 -86
@@ -0,0 +1,128 @@
1
+ #!/usr/bin/env ruby
2
+ # Copyright (c) 2010-2012 The University of Manchester, UK.
3
+ #
4
+ # All rights reserved.
5
+ #
6
+ # Redistribution and use in source and binary forms, with or without
7
+ # modification, are permitted provided that the following conditions are met:
8
+ #
9
+ # * Redistributions of source code must retain the above copyright notice,
10
+ # this list of conditions and the following disclaimer.
11
+ #
12
+ # * Redistributions in binary form must reproduce the above copyright notice,
13
+ # this list of conditions and the following disclaimer in the documentation
14
+ # and/or other materials provided with the distribution.
15
+ #
16
+ # * Neither the names of The University of Manchester nor the names of its
17
+ # contributors may be used to endorse or promote products derived from this
18
+ # software without specific prior written permission.
19
+ #
20
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
+ # POSSIBILITY OF SUCH DAMAGE.
31
+ #
32
+ # Author: Robert Haines
33
+
34
+ require 'rubygems'
35
+ require 't2-server-cli'
36
+ require 'hirb'
37
+
38
+ include T2Server::CLI
39
+
40
+ set = {}
41
+ options = {}
42
+ conn_params, creds = register_options("Usage: t2-server-admin [options] " +
43
+ "server-address [resource(s)]") do |opt|
44
+ opt.separator " Where server-address is the full URI of the server to"
45
+ opt.separator " connect to, e.g.: http://example.com:8080/taverna"
46
+ opt.separator " and [options] can be:"
47
+ opt.on("-l", "--list", "List all administrative resources.") do
48
+ options[:list] = true
49
+ end
50
+ opt.on("-a", "--all",
51
+ "List all administrative resources and their current values.") do
52
+ options[:all] = true
53
+ end
54
+ opt.on("-s RESOURCE:VALUE", "--set=RESOURCE:VALUE",
55
+ "Set admin resource RESOURCE to VALUE.") do |val|
56
+ resource, value = val.chomp.split(':', 2)
57
+ set[resource.downcase] = value
58
+ end
59
+ end
60
+
61
+ # get runs and server address from the arguments
62
+ resources = []
63
+ address = ""
64
+ for arg in ARGV
65
+ argc = arg.chomp
66
+ if argc.match(/https?:\/\//).nil?
67
+ resources << argc
68
+ else
69
+ address = argc
70
+ end
71
+ end
72
+
73
+ # read and check server address and credentials
74
+ uri, creds = parse_address(address, creds)
75
+
76
+ # pretty printer for resource access mode
77
+ def access(write)
78
+ write ? "read/write" : "read only"
79
+ end
80
+
81
+ begin
82
+ server = T2Server::Server.new(uri, conn_params)
83
+
84
+ server.administrator(creds) do |admin|
85
+ # list and exit?
86
+ if options[:list]
87
+ puts (Hirb::Helpers::ObjectTable.render admin.resources.values,
88
+ :fields=>[:name, :writable?],
89
+ :headers=>{:name => 'Resource name', :writable? => 'Access'},
90
+ :filters=>{:writable? => :access},
91
+ :description=>false)
92
+ exit 0
93
+ end
94
+
95
+ # enumerate all resources?
96
+ resources = admin.resources.keys if options[:all]
97
+
98
+ # list given resources and their values
99
+ resources.each do |resource|
100
+ begin
101
+ res = admin[resource]
102
+ result = res.value
103
+ puts "#{res.name}\t#{result}"
104
+ rescue => e
105
+ puts "#{res.name}\tERROR! - #{e}"
106
+ end
107
+ end
108
+
109
+ # set resources as requested
110
+ admin.resources.each do |name, resource|
111
+ if set.include? name and resource.writable?
112
+ begin
113
+ resource.value = set[name]
114
+ puts "Resource #{resource.name} set to '#{set[name]}'"
115
+ rescue => e
116
+ puts "Failed to set resource #{resource.name} - #{e}"
117
+ end
118
+ end
119
+ end
120
+ end
121
+ rescue T2Server::AccessForbiddenError => e
122
+ puts "You are not authorized to access the administrator interface of " +
123
+ "this server\n(#{uri})."
124
+ exit 1
125
+ rescue RuntimeError => e
126
+ puts e
127
+ exit 1
128
+ end
data/bin/t2-server-info CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
- # Copyright (c) 2010, 2011 The University of Manchester, UK.
2
+ # Copyright (c) 2010-2012 The University of Manchester, UK.
3
3
  #
4
4
  # All rights reserved.
5
5
  #
@@ -15,7 +15,7 @@
15
15
  #
16
16
  # * Neither the names of The University of Manchester nor the names of its
17
17
  # contributors may be used to endorse or promote products derived from this
18
- # software without specific prior written permission.
18
+ # software without specific prior written permission.
19
19
  #
20
20
  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
21
  # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@@ -32,53 +32,40 @@
32
32
  # Author: Robert Haines
33
33
 
34
34
  require 'rubygems'
35
- require 't2-server'
36
- require 'optparse'
35
+ require 't2-server-cli'
37
36
  require 'hirb'
38
37
 
39
- opts = OptionParser.new do |opt|
40
- opt.banner = "Usage: t2-server-info [options] server-address"
41
- opt.separator ""
38
+ include T2Server::CLI
39
+
40
+ conn_params, creds = register_options("Usage: t2-server-info [options] " +
41
+ "server-address") do |opt|
42
42
  opt.separator " Where server-address is the full URI of the server to"
43
43
  opt.separator " connect to, e.g.: http://example.com:8080/taverna"
44
44
  opt.separator " and [options] can be:"
45
- opt.on_tail("-h", "-?", "--help", "Show this message") do
46
- puts opt
47
- exit
48
- end
49
- opt.on_tail("-v", "--version", "Show the version") do
50
- puts "Taverna 2 Server Ruby Gem version: #{T2Server::GEM_VERSION}"
51
- puts "Taverna 2 Server REST API version: #{T2Server::API_VERSION}"
52
- exit
53
- end
54
45
  end
55
46
 
56
- # parse options
57
- opts.parse!
58
-
59
- # read and check server address
60
- uri = ARGV.shift
61
- if uri == nil
62
- puts opts
63
- exit 1
64
- end
47
+ # read and check server address and credentials
48
+ uri, creds = parse_address(ARGV.shift, creds)
65
49
 
66
50
  # connect to server and output information
67
51
  begin
68
- server = T2Server::Server.connect(uri)
69
- print " Server: #{uri}\n"
70
- print " Run limit: #{server.run_limit}\n"
71
- runs = server.runs
72
- print "No. of runs: #{runs.length}\n"
73
- if runs.length > 0
74
- puts (Hirb::Helpers::ObjectTable.render runs,
75
- :fields=>[:uuid, :status, :expiry],
76
- :headers=>{:uuid=>'Run ID', :status=>'Status', :expiry=>'Expiry time (local)'},
77
- :filters=>{:expiry=>[:strftime, "%H:%M:%S %d/%m/%Y"]},
78
- :max_fields=>{:expiry=>19},
79
- :description=>false)
52
+ T2Server::Server.new(uri, conn_params) do |server|
53
+ print " Server: #{server.uri}\n"
54
+ print " Version: #{server.version}\n"
55
+ print " Run limit: #{server.run_limit(creds)}\n"
56
+ runs = server.runs(creds)
57
+ print "No. of runs: #{runs.length}\n"
58
+ if runs.length > 0
59
+ puts (Hirb::Helpers::ObjectTable.render runs,
60
+ :fields=>[:identifier, :status, :expiry],
61
+ :headers=>{:identifier=>'Run ID', :status=>'Status',
62
+ :expiry=>'Expiry time (local)'},
63
+ :filters=>{:expiry=>[:strftime, "%H:%M:%S %d/%m/%Y"]},
64
+ :max_fields=>{:expiry=>19},
65
+ :description=>false)
66
+ end
80
67
  end
81
- rescue T2Server::T2ServerError => e
68
+ rescue RuntimeError => e
82
69
  puts e
83
70
  exit 1
84
71
  end
@@ -0,0 +1,116 @@
1
+ # Copyright (c) 2010-2012 The University of Manchester, UK.
2
+ #
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ #
8
+ # * Redistributions of source code must retain the above copyright notice,
9
+ # this list of conditions and the following disclaimer.
10
+ #
11
+ # * Redistributions in binary form must reproduce the above copyright notice,
12
+ # this list of conditions and the following disclaimer in the documentation
13
+ # and/or other materials provided with the distribution.
14
+ #
15
+ # * Neither the names of The University of Manchester nor the names of its
16
+ # contributors may be used to endorse or promote products derived from this
17
+ # software without specific prior written permission.
18
+ #
19
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
+ # POSSIBILITY OF SUCH DAMAGE.
30
+ #
31
+ # Author: Robert Haines
32
+
33
+ require 'optparse'
34
+ require 't2-server'
35
+
36
+ module T2Server
37
+ module CLI
38
+ @opts = nil
39
+
40
+ # set up common options and return creds if provided
41
+ def register_options(banner)
42
+ user = nil
43
+ pass = ""
44
+ conn_params = DefaultConnectionParameters.new
45
+
46
+ @opts = OptionParser.new do |opt|
47
+ opt.banner = banner
48
+ if block_given?
49
+ yield opt
50
+ end
51
+
52
+ # SSL options
53
+ opt.on("-E CERT_FILE:PASSWORD", "--cert=CERT_FILE:PASSWORD", "Use " +
54
+ "the specified certificate file for client authentication. If the " +
55
+ "optional password is not provided it will be asked for on the " +
56
+ "command line. Must be in PEM format.") do |val|
57
+ cert, cpass = val.chomp.split(":", 2)
58
+ conn_params[:client_certificate] = cert
59
+ conn_params[:client_password] = cpass if cpass
60
+ end
61
+ opt.on("--cacert=CERT_FILE", "Use the specified certificate file to " +
62
+ "verify the peer. Must be in PEM format.") do |val|
63
+ conn_params[:ca_file] = val.chomp
64
+ end
65
+ opt.on("--capath=CERTS_PATH", "Use the specified certificate " +
66
+ "directory to verify the peer. Certificates must be in PEM " +
67
+ "format") do |val|
68
+ conn_params[:ca_path] = val.chomp
69
+ end
70
+ opt.on("-k", "--insecure", "Allow insecure connections: no peer " +
71
+ "verification.") do
72
+ conn_params[:verify_peer] = false
73
+ end
74
+
75
+ # common options
76
+ opt.on_tail("-u", "--username=USERNAME", "The username to use for " +
77
+ "server operations.") do |val|
78
+ user = val.chomp
79
+ end
80
+ opt.on_tail("-p", "--password=PASSWORD", "The password to use for " +
81
+ "the supplied username.") do |val|
82
+ pass = val.chomp
83
+ end
84
+ opt.on_tail("-h", "-?", "--help", "Show this help message.") do
85
+ puts opt
86
+ exit
87
+ end
88
+ opt.on_tail("-v", "--version", "Show the version.") do
89
+ puts "Taverna 2 Server Ruby Gem version: #{T2Server::Version::STRING}"
90
+ exit
91
+ end
92
+ end
93
+
94
+ # parse options
95
+ @opts.parse!
96
+
97
+ creds = user.nil? ? nil : HttpBasic.new(user, pass)
98
+ [conn_params, creds]
99
+ end
100
+
101
+ # separate the creds if they are supplied in the uri
102
+ def parse_address(address, creds)
103
+ if address == nil or address == ""
104
+ puts @opts
105
+ exit 1
106
+ end
107
+
108
+ p_uri, p_creds = Util.strip_uri_credentials(address)
109
+ creds != nil ? [p_uri, creds] : [p_uri, p_creds]
110
+ end
111
+
112
+ def opts
113
+ @opts
114
+ end
115
+ end
116
+ end
data/lib/t2-server.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2010, 2011 The University of Manchester, UK.
1
+ # Copyright (c) 2010-2012 The University of Manchester, UK.
2
2
  #
3
3
  # All rights reserved.
4
4
  #
@@ -14,7 +14,7 @@
14
14
  #
15
15
  # * Neither the names of The University of Manchester nor the names of its
16
16
  # contributors may be used to endorse or promote products derived from this
17
- # software without specific prior written permission.
17
+ # software without specific prior written permission.
18
18
  #
19
19
  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
20
  # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@@ -30,10 +30,17 @@
30
30
  #
31
31
  # Author: Robert Haines
32
32
 
33
- require 't2-server/xml'
33
+ require 'yaml'
34
+ require 't2-server/util'
35
+ require 't2-server/xml/xml'
34
36
  require 't2-server/exceptions'
37
+ require 't2-server/credentials'
38
+ require 't2-server/connection'
39
+ require 't2-server/connection-parameters'
40
+ require 't2-server/port'
35
41
  require 't2-server/server'
36
42
  require 't2-server/run'
43
+ require 't2-server/admin'
37
44
 
38
45
  # This is a Ruby library to interface with the Taverna 2 Server REST API.
39
46
  #
@@ -42,30 +49,12 @@ require 't2-server/run'
42
49
  # * T2Server::Server - Use this if you are providing a web interface to a
43
50
  # Taverna 2 Server instance.
44
51
  module T2Server
45
- # The version of this library
46
- GEM_VERSION = "0.6.1"
47
- # The version of the Taverna 2 Server API that this library can interface with
48
- API_VERSION = "2.2a1"
49
- end
50
-
51
- # Add methods to the String class to operate on file paths.
52
- class String
53
- # :call-seq:
54
- # str.strip_path -> string
55
- #
56
- # Returns a new String with one leading and one trailing slash
57
- # removed from the ends of _str_ (if present).
58
- def strip_path
59
- self.gsub(/^\//, "").chomp("/")
60
- end
52
+ module Version
53
+ # Version information in a Hash
54
+ INFO = YAML.load_file(File.join(File.dirname(__FILE__), "..",
55
+ "version.yml"))
61
56
 
62
- # :call-seq:
63
- # str.strip_path! -> str or nil
64
- #
65
- # Modifies _str_ in place as described for String#strip_path,
66
- # returning _str_, or returning +nil+ if no modifications were made.
67
- def strip_path!
68
- g = self.gsub!(/^\//, "")
69
- self.chomp!("/") || g
57
+ # Version number as a String
58
+ STRING = [:major, :minor, :patch].map {|d| INFO[d]}.compact.join('.')
70
59
  end
71
60
  end
@@ -0,0 +1,147 @@
1
+ # Copyright (c) 2010-2012 The University of Manchester, UK.
2
+ #
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ #
8
+ # * Redistributions of source code must retain the above copyright notice,
9
+ # this list of conditions and the following disclaimer.
10
+ #
11
+ # * Redistributions in binary form must reproduce the above copyright notice,
12
+ # this list of conditions and the following disclaimer in the documentation
13
+ # and/or other materials provided with the distribution.
14
+ #
15
+ # * Neither the names of The University of Manchester nor the names of its
16
+ # contributors may be used to endorse or promote products derived from this
17
+ # software without specific prior written permission.
18
+ #
19
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
+ # POSSIBILITY OF SUCH DAMAGE.
30
+ #
31
+ # Author: Robert Haines
32
+
33
+ module T2Server
34
+
35
+ # This call provides access to the administrative interface of a Taverna
36
+ # Server instance.
37
+ #
38
+ # To get an instance of this class use the Server#administrator method.
39
+ # Special permissions will most likely be required above and beyond those
40
+ # assigned to most Taverna Server users.
41
+ class Administrator
42
+ include XML::Methods
43
+
44
+ # The resources held by this administrative interface. This is a Hash
45
+ # indexed by the name of the resource in lowercase.
46
+ attr_reader :resources
47
+
48
+ # :stopdoc:
49
+ def initialize(server, credentials = nil)
50
+ @server = server
51
+ @credentials = credentials
52
+
53
+ admin_description = xml_document(@server.get_admin_attribute("",
54
+ @credentials))
55
+ @resources = get_resources(admin_description)
56
+ #@resources.each {|key, value| puts "#{key}: #{value}"}
57
+
58
+ yield(self) if block_given?
59
+ end
60
+ # :startdoc:
61
+
62
+ # :call-seq:
63
+ # [name] -> AdminResource
64
+ #
65
+ # Return the named AdminResource.
66
+ def [](name)
67
+ @resources[name.downcase]
68
+ end
69
+
70
+ # :stopdoc:
71
+ def get_resource_value(path)
72
+ @server.get_admin_attribute(path, @credentials)
73
+ end
74
+
75
+ def set_resource_value(path, val)
76
+ @server.set_admin_attribute(path, val.to_s, @credentials)
77
+ end
78
+ # :startdoc:
79
+
80
+ private
81
+ def get_resources(doc)
82
+ links = {}
83
+
84
+ xml_children(doc.root) do |res|
85
+ path = xml_node_attribute(res, 'href').split('/')[-1]
86
+ write = @server.admin_resource_writable?(path, @credentials)
87
+ links[res.name.downcase] = AdminResource.new(res.name, path,
88
+ write, self)
89
+ end
90
+
91
+ links
92
+ end
93
+
94
+ # This class represents a resource in the Taverna Server administrative
95
+ # interface. A resource can be read only or read/write.
96
+ #
97
+ # Resources are created when the parent Administrator class is created and
98
+ # are accessed via the [] method within that class.
99
+ class AdminResource
100
+ # The name of this resource.
101
+ attr_reader :name
102
+
103
+ # The path to this resource on the server.
104
+ attr_reader :path
105
+
106
+ # :stopdoc:
107
+ def initialize(name, path, writeable, parent)
108
+ @name = name
109
+ @path = path
110
+ @admin = parent
111
+ @writeable = writeable
112
+
113
+ make_writable if @writeable
114
+ end
115
+ # :startdoc:
116
+
117
+ # :call-seq:
118
+ # value -> String
119
+ # value=
120
+ #
121
+ # Get or set the value held by this resource. This call always queries
122
+ # the server as values can change without user intervention.
123
+ #
124
+ # The resource can only be set if it is writable.
125
+ def value
126
+ @admin.get_resource_value(@path)
127
+ end
128
+
129
+ # :call-seq:
130
+ # writable? -> bool
131
+ #
132
+ # Is this resource writable?
133
+ def writable?
134
+ @writeable
135
+ end
136
+
137
+ private
138
+ def make_writable
139
+ (class << self; self; end).instance_eval do
140
+ define_method "value=" do |value|
141
+ @admin.set_resource_value(@path, value)
142
+ end
143
+ end
144
+ end
145
+ end
146
+ end
147
+ end