Class: CFTunnelPlugin::Tunnel

Inherits:
CF::CLI
  • Object
show all
Defined in:
lib/tunnel/plugin.rb

Constant Summary collapse

CLIENTS_FILE =
"tunnel-clients.yml"
STOCK_CLIENTS =
File.expand_path("../config/clients.yml", __FILE__)

Instance Method Summary collapse

Methods inherited from CF::CLI

#add_exception_name_to_msg, #build_client, #check_logged_in, #check_target, client, #client, client=, #client_target, #color_enabled?, #debug?, #default_action, #ensure_config_dir, #err, #execute, #fail, #fail_unknown, #force?, #formatted_exception_output, #help, #help_header, #invalidate_client, #log_error, #log_error_and_dump_crashlog, #name_list, #normalize_targets_info, #one_of, #quiet?, #remove_target_info, #sane_target_url, #save_target_info, #save_targets, #save_token_if_it_changes, #set_target, #table, #target_info, #targets_info, #user_colors, #verbose?, #wrap_errors

Methods included from CF::Spacing

#indented, #justify, #line, #lines, #quiet?, #spaced, #start_line, #tabular, #text_width, #trim_escapes

Methods included from CF::Interactive

#ask, #handler, #input_state, #list_choices, #prompt, #show_default

Instance Method Details

#tunnelObject


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/tunnel/plugin.rb', line 27

def tunnel
  instances = client.service_instances
  fail "No services available for tunneling." if instances.empty?

  instance = input[:instance, instances.sort_by(&:name)]
  vendor = instance.service_plan.service.label
  clients = tunnel_clients[vendor] || {}
  client_name = input[:client, clients]

  tunnel = CFTunnel.new(client, instance)
  port = tunnel.pick_port!(input[:port])

  conn_info =
    with_progress("Opening tunnel on port #{c(port, :name)}") do
      tunnel.open!
    end

  if client_name == "none"
    unless quiet?
      line
      display_tunnel_connection_info(conn_info)

      line
      line "Open another shell to run command-line clients or"
      line "use a UI tool to connect using the displayed information."
      line "Press Ctrl-C to exit..."
    end

    tunnel.wait_for_end
  else
    with_progress("Waiting for local tunnel to become available") do
      tunnel.wait_for_start
    end

    unless start_local_prog(clients, client_name, conn_info, port)
      fail "'#{client_name}' execution failed; is it in your $PATH?"
    end
  end
end

#tunnel_clientsObject


67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/tunnel/plugin.rb', line 67

def tunnel_clients
  return @tunnel_clients if @tunnel_clients
  stock_config = YAML.load_file(STOCK_CLIENTS)
  custom_config_file = config_file_path

  if File.exists?(custom_config_file)
    custom_config = YAML.load_file(custom_config_file)
    @tunnel_clients = deep_merge(stock_config, custom_config)
  else
    @tunnel_clients = stock_config
  end
end