module T2Server::CLI

Public Instance Methods

opts() click to toggle source
   # File lib/t2-server-cli.rb
88 def opts
89   @opts
90 end
parse_address(address, creds) click to toggle source

separate the creds if they are supplied in the uri

   # File lib/t2-server-cli.rb
78 def parse_address(address, creds)
79   if address == nil || address == ""
80     puts @opts
81     exit 1
82   end
83 
84   p_uri, p_creds = Util.strip_uri_credentials(address)
85   creds != nil ? [p_uri, creds] : [p_uri, p_creds]
86 end
register_options(banner) { |opt| ... } click to toggle source

set up common options and return creds if provided

   # File lib/t2-server-cli.rb
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     ssl_auth_opts(opt, conn_params)
54     ssl_transport_opts(opt, conn_params)
55 
56     # Simple credential options
57     opt.on_tail("-u", "--username=USERNAME", "The username to use for " +
58       "server operations.") do |val|
59         user = val.chomp
60     end
61     opt.on_tail("-p", "--password=PASSWORD", "The password to use for " +
62       "the supplied username.") do |val|
63         pass = val.chomp
64     end
65 
66     # Common options
67     common_opts(opt)
68   end
69 
70   # parse options
71   @opts.parse!
72 
73   creds = user.nil? ? nil : HttpBasic.new(user, pass)
74   [conn_params, creds]
75 end

Private Instance Methods

common_opts(opt) click to toggle source

The help and version options.

    # File lib/t2-server-cli.rb
 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
ssl_auth_opts(opt, conn_params) click to toggle source

The SSL authentication and peer verification options.

    # File lib/t2-server-cli.rb
107 def ssl_auth_opts(opt, conn_params)
108   opt.on("-E CERT_FILE:PASSWORD", "--cert=CERT_FILE:PASSWORD", "Use " +
109     "the specified certificate file for client authentication. If the " +
110     "optional password is not provided it will be asked for on the " +
111     "command line. Must be in PEM format.") do |val|
112       cert, cpass = val.chomp.split(":", 2)
113       conn_params[:client_certificate] = cert
114       conn_params[:client_password] = cpass if cpass
115   end
116   opt.on("--cacert=CERT_FILE", "Use the specified certificate file to " +
117     "verify the peer. Must be in PEM format.") do |val|
118       conn_params[:ca_file] = val.chomp
119   end
120   opt.on("--capath=CERTS_PATH", "Use the specified certificate " +
121     "directory to verify the peer. Certificates must be in PEM " +
122     "format") do |val|
123       conn_params[:ca_path] = val.chomp
124   end
125   opt.on("-k", "--insecure", "Allow insecure connections: no peer " +
126     "verification.") do
127       conn_params[:verify_peer] = false
128   end
129 end
ssl_transport_opts(opt, conn_params) click to toggle source

The SSL transport options.

    # File lib/t2-server-cli.rb
132 def ssl_transport_opts(opt, conn_params)
133   opt.on("-1", "--tlsv1", "Use TLS version 1 when negotiating with " +
134     "the remote Taverna Server server.") do
135       conn_params[:ssl_version] = :TLSv1
136   end
137   opt.on("-2", "--sslv2", "Use SSL version 2 when negotiating with " +
138     "the remote Taverna Server server.") do
139       conn_params[:ssl_version] = :SSLv23
140   end
141   opt.on("-3", "--sslv3", "Use SSL version 3 when negotiating with " +
142     "the remote Taverna Server server.") do
143       conn_params[:ssl_version] = :SSLv3
144   end
145 end