class Bcome::Ssh::ProxyHop
Attributes
bcome_proxy_node[R]
config[R]
host[R]
parent[R]
Public Class Methods
new(config, context_node, parent)
click to toggle source
# File lib/objects/ssh/proxy_hop.rb, line 9 def initialize(config, context_node, parent) @config = config @context_node = context_node @parent = parent set_host end
Public Instance Methods
==(other)
click to toggle source
# File lib/objects/ssh/proxy_hop.rb, line 42 def ==(other) config == other.config end
eql?(other)
click to toggle source
# File lib/objects/ssh/proxy_hop.rb, line 46 def eql?(other) config == other.config end
get_local_port_forward_string()
click to toggle source
# File lib/objects/ssh/proxy_hop.rb, line 64 def get_local_port_forward_string con_str = '' con_str += parent.get_local_port_forward_string.to_s if has_parent? con_str += "#{user}@#{host}\s" con_str end
get_rsync_string()
click to toggle source
# File lib/objects/ssh/proxy_hop.rb, line 55 def get_rsync_string con_str = '' con_str += "#{parent.get_rsync_string}\s" if has_parent? con_str += "'ssh -o \"ProxyCommand ssh -A #{user}@#{host} -W %h:%p\"'" con_str end
get_ssh_string(_is_first_hop = false)
click to toggle source
# File lib/objects/ssh/proxy_hop.rb, line 50 def get_ssh_string(_is_first_hop = false) con_str = "#{user}@#{host}" con_str end
has_parent?()
click to toggle source
# File lib/objects/ssh/proxy_hop.rb, line 38 def has_parent? !parent.nil? end
pretty_proxy_details(n = 1)
click to toggle source
# File lib/objects/ssh/proxy_hop.rb, line 23 def pretty_proxy_details(n = 1) lines = ["proxy\s".bc_cyan + "[#{n}]"] lines << "bcome node\s".bc_yellow + @bcome_proxy_node.keyed_namespace if @bcome_proxy_node lines << "host\s".bc_yellow + host lines << "user\s".bc_yellow + user lines end
proxy_details()
click to toggle source
# File lib/objects/ssh/proxy_hop.rb, line 16 def proxy_details @config.merge( proxy_host: host, user: user ).except!(:bastion_host_user, :fallback_bastion_host_user) end
user()
click to toggle source
# File lib/objects/ssh/proxy_hop.rb, line 34 def user @user ||= get_user end
Private Instance Methods
bcome_node_host()
click to toggle source
# File lib/objects/ssh/proxy_hop.rb, line 126 def bcome_node_host @bcome_proxy_node.public_ip_address || @bcome_proxy_node.internal_ip_address end
get_host_by_inventory_node()
click to toggle source
Older lookup - within same parent-child tree only. Retained for backwards compatibility
# File lib/objects/ssh/proxy_hop.rb, line 109 def get_host_by_inventory_node identifier = @config[:host_id] || @config[:node_identifier] @bcome_proxy_node = @context_node.recurse_resource_for_identifier(identifier) raise Bcome::Exception::CantFindProxyHostByIdentifier, identifier unless @bcome_proxy_node raise Bcome::Exception::ProxyHostNodeDoesNotHavePublicIp, identifier unless @bcome_proxy_node.public_ip_address bcome_node_host end
get_host_by_namespace()
click to toggle source
Newer lookup - across entire network
# File lib/objects/ssh/proxy_hop.rb, line 119 def get_host_by_namespace @bcome_proxy_node = ::Bcome::Orchestrator.instance.get(@config[:namespace]) raise Bcome::Exception::CantFindProxyHostByNamespace, @config[:namespace] unless @bcome_proxy_node bcome_node_host end
get_host_or_ip_from_config()
click to toggle source
# File lib/objects/ssh/proxy_hop.rb, line 104 def get_host_or_ip_from_config @config[:host_id] end
get_user()
click to toggle source
# File lib/objects/ssh/proxy_hop.rb, line 83 def get_user # If an explicit user has been set for this hop, use it. return @config[:bastion_host_user] if @config[:bastion_host_user] # Otherwise, if our proxy hop is a defined bcome server, i.e. it exists in the network map, we can infer the user and so we'll use that. return @bcome_proxy_node.ssh_driver.user if @bcome_proxy_node # Otherwise, we'll fallback @config[:fallback_bastion_host_user] end
set_host()
click to toggle source
# File lib/objects/ssh/proxy_hop.rb, line 94 def set_host raise Bcome::Exception::InvalidProxyConfig, 'Missing host id or namespace' unless @config[:node_identifier] || @config[:host_id] || @config[:namespace] raise Bcome::Exception::InvalidProxyConfig, 'Missing host lookup method' unless @config[:host_lookup] host_lookup_method = valid_host_lookups[@config[:host_lookup].to_sym] raise Bcome::Exception::InvalidProxyConfig, "#{@config[:host_lookup]} is not a valid host lookup method" unless host_lookup_method @host = send(host_lookup_method) end
valid_host_lookups()
click to toggle source
# File lib/objects/ssh/proxy_hop.rb, line 75 def valid_host_lookups { by_inventory_node: :get_host_by_inventory_node, by_host_or_ip: :get_host_or_ip_from_config, by_bcome_namespace: :get_host_by_namespace } end