class Utils::SshTunnelSpecification
spec.remote_port # => 22
spec.remote_addr # => ‘remote.host’
spec.local_port # => 8080
spec.local_addr # => ‘localhost’
spec = Utils::SshTunnelSpecification.new(‘localhost:8080:remote.host:22’)
@example
configuration.
representations, and access individual components of the tunnel
to validate the specification, convert it to string or array
including local and remote address/port combinations. It provides methods
This class parses and stores the configuration details for SSH tunnels,
connections.
A class that represents an SSH tunnel specification for configuring network
def initialize(spec_string)
-
spec_string
(String
) -- the specification string defining the SSH
def initialize(spec_string) interpret_spec(spec_string) end
def interpret_spec(spec_string)
-
(Array
- an array containing the local address,)
Parameters:
-
spec_string
(String
) -- the specification string defining the SSH tunnel configuration
def interpret_spec(spec_string) @local_addr, @local_port, @remote_addr, @remote_port = case spec_string when /\A(\d+)\z/ [ 'localhost', $1.to_i, 'localhost', $1.to_i ] when /\A(\[[^\]]+\]|[^:]+):(\d+)\z/ [ 'localhost', $2.to_i, $1, $2.to_i ] when /\A(\d+):(\[[^\]]+\]|[^:]+):(\d+)\z/ [ 'localhost', $1.to_i, $2, $3.to_i ] when /\A(\[[^\]]+\]|[^:]+):(\[[^\]]+\]|[^:]+):(\d+)\z/ [ $1, $3.to_i, $2, $3.to_i ] when /\A(\[[^\]]+\]|[^:]+):(\d+):(\[[^\]]+\]|[^:]+):(\d+)\z/ [ $1, $2.to_i, $3, $4.to_i ] end end
def to_a
-
(Array
- an array containing the)
def to_a [ local_addr, local_port, remote_addr, remote_port ] end
def to_s
-
(String)
- a colon-separated string containing the tunnel specification
def to_s to_a * ':' end
def valid?
-
(String, nil)
- the string representation of the specification if all
def valid? if to_a.all? to_s end end