bcome 1.3.6 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (165) hide show
  1. checksums.yaml +4 -4
  2. data/bin/bcome +13 -8
  3. data/lib/bcome.rb +7 -11
  4. data/lib/objects/bcome/version.rb +19 -1
  5. data/lib/objects/bootup.rb +13 -5
  6. data/lib/objects/command/local.rb +2 -0
  7. data/lib/objects/config_factory.rb +3 -0
  8. data/lib/objects/driver/base.rb +36 -4
  9. data/lib/objects/driver/bucket.rb +6 -4
  10. data/lib/objects/driver/ec2.rb +35 -4
  11. data/lib/objects/driver/gcp.rb +124 -0
  12. data/lib/objects/driver/gcp/authentication/api_key.rb +6 -0
  13. data/lib/objects/driver/gcp/authentication/oauth.rb +101 -0
  14. data/lib/objects/driver/gcp/authentication/service_account.rb +7 -0
  15. data/lib/objects/driver/static.rb +2 -0
  16. data/lib/objects/encryptor.rb +26 -24
  17. data/lib/objects/exception/argument_error_invoking_method_from_command_line.rb +8 -4
  18. data/lib/objects/exception/base.rb +14 -10
  19. data/lib/objects/exception/can_only_subselect_on_inventory.rb +8 -4
  20. data/lib/objects/exception/cannot_authenticate_to_gcp.rb +11 -0
  21. data/lib/objects/exception/cannot_find_internal_registry_klass.rb +8 -4
  22. data/lib/objects/exception/cannot_find_inventory.rb +11 -0
  23. data/lib/objects/exception/cannot_find_subselection_parent.rb +8 -4
  24. data/lib/objects/exception/cant_find_key_in_cloud_tags.rb +8 -4
  25. data/lib/objects/exception/cant_find_key_in_metadata.rb +8 -4
  26. data/lib/objects/exception/cant_find_proxy_host_by_identifier.rb +8 -4
  27. data/lib/objects/exception/cant_find_proxy_host_by_namespace.rb +8 -4
  28. data/lib/objects/exception/could_not_initiate_ssh_connection.rb +8 -4
  29. data/lib/objects/exception/could_not_initiate_ssh_connection_through_backend_proxy.rb +8 -4
  30. data/lib/objects/exception/could_not_retrieve_terraform_output.rb +11 -0
  31. data/lib/objects/exception/deprecation_warning.rb +9 -7
  32. data/lib/objects/exception/duplicate_command_line_argument_key.rb +8 -4
  33. data/lib/objects/exception/ec2_driver_missing_provisioning_region.rb +8 -4
  34. data/lib/objects/exception/failed_to_run_local_command.rb +8 -4
  35. data/lib/objects/exception/generic.rb +11 -0
  36. data/lib/objects/exception/interactive_session_halt.rb +6 -2
  37. data/lib/objects/exception/invalid_bcome_breadcrumb.rb +8 -4
  38. data/lib/objects/exception/invalid_breadcrumb.rb +8 -4
  39. data/lib/objects/exception/invalid_context_command.rb +8 -4
  40. data/lib/objects/exception/invalid_gcp_authentication_scheme.rb +11 -0
  41. data/lib/objects/exception/invalid_identifier.rb +8 -4
  42. data/lib/objects/exception/invalid_machines_cache_config.rb +8 -4
  43. data/lib/objects/exception/invalid_matcher_query.rb +8 -4
  44. data/lib/objects/exception/invalid_meta_data_config.rb +8 -4
  45. data/lib/objects/exception/invalid_metadata_encryption_key.rb +8 -4
  46. data/lib/objects/exception/invalid_network_config.rb +8 -4
  47. data/lib/objects/exception/invalid_network_driver_type.rb +8 -4
  48. data/lib/objects/exception/invalid_port_forward_request.rb +11 -0
  49. data/lib/objects/exception/invalid_proxy_config.rb +8 -4
  50. data/lib/objects/exception/invalid_regexp_matcher_in_registry.rb +8 -4
  51. data/lib/objects/exception/invalid_registry_arguments_type.rb +8 -4
  52. data/lib/objects/exception/invalid_registry_command_name_length.rb +8 -4
  53. data/lib/objects/exception/invalid_registry_data_config.rb +8 -4
  54. data/lib/objects/exception/invalid_restriction_key_in_registry.rb +8 -4
  55. data/lib/objects/exception/invalid_ssh_config.rb +8 -4
  56. data/lib/objects/exception/inventories_cannot_have_subviews.rb +8 -4
  57. data/lib/objects/exception/malformed_command_line_arguments.rb +8 -4
  58. data/lib/objects/exception/method_invocation_requires_parameter.rb +8 -4
  59. data/lib/objects/exception/method_name_conflict_in_registry.rb +8 -4
  60. data/lib/objects/exception/missing_argument_for_registry_command.rb +8 -4
  61. data/lib/objects/exception/missing_description_on_view.rb +8 -4
  62. data/lib/objects/exception/missing_execute_on_registry_object.rb +8 -4
  63. data/lib/objects/exception/missing_gcp_authentication_scheme.rb +11 -0
  64. data/lib/objects/exception/missing_gcp_service_scopes.rb +11 -0
  65. data/lib/objects/exception/missing_identifier_on_view.rb +8 -4
  66. data/lib/objects/exception/missing_inventory_contributors.rb +11 -0
  67. data/lib/objects/exception/missing_ip_address_on_server.rb +8 -4
  68. data/lib/objects/exception/missing_network_config.rb +8 -4
  69. data/lib/objects/exception/missing_or_invalid_client_secrets.rb +11 -0
  70. data/lib/objects/exception/missing_params_for_rsync.rb +8 -4
  71. data/lib/objects/exception/missing_params_for_scp.rb +8 -4
  72. data/lib/objects/exception/missing_subselection_key.rb +8 -4
  73. data/lib/objects/exception/missing_type_on_view.rb +8 -4
  74. data/lib/objects/exception/no_node_found_for_breadcrumb.rb +8 -4
  75. data/lib/objects/exception/no_node_named_by_identifier.rb +8 -4
  76. data/lib/objects/exception/node_identifiers_must_be_unique.rb +8 -4
  77. data/lib/objects/exception/orchestration_script_does_not_exist.rb +8 -4
  78. data/lib/objects/exception/proxy_host_node_does_not_have_public_ip_address.rb +8 -4
  79. data/lib/objects/exception/unknown_dynamic_server_type.rb +11 -0
  80. data/lib/objects/exception/unknown_method_for_namespace.rb +8 -4
  81. data/lib/objects/interactive/session.rb +4 -1
  82. data/lib/objects/interactive/session_item/base.rb +2 -0
  83. data/lib/objects/interactive/session_item/capture_input.rb +2 -0
  84. data/lib/objects/interactive/session_item/transparent_ssh.rb +29 -23
  85. data/lib/objects/loading_bar/handler.rb +80 -0
  86. data/lib/objects/loading_bar/indicator/base.rb +64 -0
  87. data/lib/objects/loading_bar/indicator/basic.rb +34 -0
  88. data/lib/objects/loading_bar/indicator/progress.rb +26 -0
  89. data/lib/objects/loading_bar/pid_bucket.rb +27 -0
  90. data/lib/objects/modules/context.rb +13 -9
  91. data/lib/objects/modules/registry_management.rb +16 -10
  92. data/lib/objects/modules/ui_output.rb +10 -6
  93. data/lib/objects/modules/workspace_commands.rb +159 -155
  94. data/lib/objects/modules/workspace_menu.rb +129 -130
  95. data/lib/objects/node/attributes.rb +13 -21
  96. data/lib/objects/node/base.rb +113 -71
  97. data/lib/objects/node/cache_handler.rb +2 -0
  98. data/lib/objects/node/collection.rb +10 -9
  99. data/lib/objects/node/factory.rb +35 -28
  100. data/lib/objects/node/inventory/base.rb +100 -100
  101. data/lib/objects/node/inventory/defined.rb +110 -89
  102. data/lib/objects/node/inventory/merge.rb +43 -0
  103. data/lib/objects/node/inventory/subselect.rb +64 -46
  104. data/lib/objects/node/kube/base.rb +51 -0
  105. data/lib/objects/node/kube/container.rb +9 -0
  106. data/lib/objects/node/kube/estate.rb +19 -0
  107. data/lib/objects/node/kube/namespace.rb +24 -0
  108. data/lib/objects/node/kube/pod.rb +24 -0
  109. data/lib/objects/node/kube_wrap.rb +26 -0
  110. data/lib/objects/node/meta/base.rb +8 -1
  111. data/lib/objects/node/meta/cloud.rb +2 -0
  112. data/lib/objects/node/meta/local.rb +2 -0
  113. data/lib/objects/node/meta_data_factory.rb +3 -1
  114. data/lib/objects/node/meta_data_loader.rb +27 -28
  115. data/lib/objects/node/resources/base.rb +5 -1
  116. data/lib/objects/node/resources/inventory.rb +7 -5
  117. data/lib/objects/node/resources/merged.rb +38 -0
  118. data/lib/objects/node/resources/sub_inventory.rb +7 -4
  119. data/lib/objects/node/server/base.rb +88 -66
  120. data/lib/objects/node/server/dynamic/base.rb +23 -0
  121. data/lib/objects/node/server/{dynamic.rb → dynamic/ec2.rb} +14 -13
  122. data/lib/objects/node/server/dynamic/gcp.rb +47 -0
  123. data/lib/objects/node/server/static.rb +13 -2
  124. data/lib/objects/orchestration/base.rb +10 -0
  125. data/lib/objects/orchestration/interactive_terraform.rb +62 -27
  126. data/lib/objects/orchestrator.rb +22 -0
  127. data/lib/objects/parser/bread_crumb.rb +3 -1
  128. data/lib/objects/registry/arguments/base.rb +3 -1
  129. data/lib/objects/registry/arguments/command_line.rb +6 -1
  130. data/lib/objects/registry/arguments/console.rb +4 -1
  131. data/lib/objects/registry/command/base.rb +3 -0
  132. data/lib/objects/registry/command/external.rb +4 -2
  133. data/lib/objects/registry/command/group.rb +6 -3
  134. data/lib/objects/registry/command/internal.rb +3 -1
  135. data/lib/objects/registry/command/shortcut.rb +17 -9
  136. data/lib/objects/registry/command_list.rb +2 -0
  137. data/lib/objects/registry/loader.rb +10 -10
  138. data/lib/objects/ssh/bootstrap.rb +3 -1
  139. data/lib/objects/ssh/command.rb +10 -5
  140. data/lib/objects/ssh/command_exec.rb +13 -9
  141. data/lib/objects/ssh/connection_wrangler.rb +105 -0
  142. data/lib/objects/ssh/connector.rb +100 -0
  143. data/lib/objects/ssh/driver.rb +27 -230
  144. data/lib/objects/ssh/driver_concerns/command_strings.rb +17 -0
  145. data/lib/objects/ssh/driver_concerns/connection.rb +78 -0
  146. data/lib/objects/ssh/driver_concerns/functions.rb +89 -0
  147. data/lib/objects/ssh/driver_concerns/user.rb +32 -0
  148. data/lib/objects/ssh/{proxy_data.rb → proxy_hop.rb} +52 -7
  149. data/lib/objects/ssh/script_exec.rb +4 -1
  150. data/lib/objects/ssh/tunnel/local_port_forward.rb +5 -6
  151. data/lib/objects/ssh/tunnel_keeper.rb +21 -0
  152. data/lib/objects/ssh/window.rb +31 -0
  153. data/lib/objects/startup.rb +52 -0
  154. data/lib/objects/system/local.rb +3 -0
  155. data/lib/objects/terraform/output.rb +41 -0
  156. data/lib/objects/workspace.rb +3 -14
  157. data/patches/irb.rb +27 -3
  158. data/patches/string-encrypt.rb +20 -23
  159. data/patches/string.rb +5 -1
  160. data/patches/string_stylesheet.rb +2 -0
  161. metadata +95 -18
  162. data/lib/objects/progress_bar.rb +0 -30
  163. data/lib/objects/ssh/connection_handler.rb +0 -101
  164. data/lib/objects/terraform/parser.rb +0 -23
  165. data/lib/objects/terraform/state.rb +0 -40
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ::Bcome::Ssh
4
+ module DriverCommandStrings
5
+ def ssh_command(as_pseudo_tty = false)
6
+ connection_wrangler.get_ssh_command(as_pseudo_tty: as_pseudo_tty)
7
+ end
8
+
9
+ def rsync_command(local_path, remote_path)
10
+ connection_wrangler.get_rsync_command(local_path, remote_path)
11
+ end
12
+
13
+ def local_port_forward_command(start_port, end_port)
14
+ connection_wrangler.get_local_port_forward_command(start_port, end_port)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ::Bcome::Ssh
4
+ module DriverConnection
5
+ DEFAULT_TIMEOUT_IN_SECONDS = 1
6
+
7
+ attr_reader :connection
8
+
9
+ ## CONNECTION --
10
+
11
+ def ssh_connect!
12
+ @connection = nil
13
+ begin
14
+ raise ::Bcome::Exception::InvalidProxyConfig, "missing target ip address for #{@context_node.identifier}. Perhaps you meant to configure a proxy?" unless node_host_or_ip
15
+
16
+ @connection = ::Net::SSH.start(node_host_or_ip, user, net_ssh_params)
17
+ rescue Net::SSH::Proxy::ConnectError, Net::SSH::ConnectionTimeout => e
18
+ raise Bcome::Exception::CouldNotInitiateSshConnection, @context_node.namespace + "\s-\s#{e.message}"
19
+ end
20
+ @connection
21
+ end
22
+
23
+ def close_ssh_connection
24
+ return unless @connection
25
+
26
+ begin
27
+ @connection.close unless @connection.closed?
28
+ @connection = nil
29
+ rescue Net::SCP::Error
30
+ @connection = nil
31
+ end
32
+ end
33
+
34
+ def ssh_connection(ping = false)
35
+ if ping
36
+ # We do not cache ping results
37
+ ssh_connect!
38
+ else
39
+ has_open_ssh_con? ? @connection : ssh_connect!
40
+ end
41
+ end
42
+
43
+ def has_open_ssh_con?
44
+ !@connection.nil? && !@connection.closed?
45
+ end
46
+
47
+ def node_host_or_ip
48
+ has_proxy? ? @context_node.internal_ip_address : @context_node.public_ip_address
49
+ end
50
+
51
+ def net_ssh_params
52
+ raise Bcome::Exception::InvalidSshConfig, "Missing ssh keys for #{@context_node.namespace}" unless ssh_keys
53
+
54
+ params = { keys: ssh_keys, paranoid: false }
55
+ params[:proxy] = proxy if has_proxy?
56
+ params[:timeout] = timeout_in_seconds
57
+ params[:verbose] = :fatal # All but silent
58
+
59
+ params
60
+ end
61
+
62
+ def timeout_in_seconds
63
+ @config[:timeout_in_seconds] ||= DEFAULT_TIMEOUT_IN_SECONDS
64
+ end
65
+
66
+ ## SSH KEYS
67
+
68
+ def ssh_keys
69
+ @config[:ssh_keys]
70
+ end
71
+
72
+ ## PROXYING --
73
+
74
+ def proxy
75
+ connection_wrangler.proxy
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,89 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ::Bcome::Ssh
4
+ module DriverFunctions
5
+ def do_ssh
6
+ cmd = ssh_command
7
+ @context_node.execute_local(cmd)
8
+ end
9
+
10
+ def rsync(local_path, remote_path)
11
+ raise Bcome::Exception::MissingParamsForRsync, "'rsync' requires a local_path and a remote_path" if local_path.to_s.empty? || remote_path.to_s.empty?
12
+
13
+ command = rsync_command(local_path, remote_path)
14
+ @context_node.execute_local(command)
15
+ end
16
+
17
+ def local_port_forward(start_port, end_port)
18
+ tunnel_command = local_port_forward_command(start_port, end_port)
19
+
20
+ if ::Bcome::Workspace.instance.console_set?
21
+ puts "\sOpening ssh tunnel:\s".informational + tunnel_command.to_s.terminal_prompt
22
+ tunnel = ::Bcome::Ssh::Tunnel::LocalPortForward.new(tunnel_command)
23
+ ::Bcome::Ssh::TunnelKeeper.instance << tunnel
24
+ tunnel.open!
25
+ tunnel
26
+ else
27
+ puts "\n\nOpening ssh tunnel".informational + "\slocalhost:#{start_port} ~> #{@context_node.namespace}:#{end_port}"
28
+ puts "\nTo use, navigate to another terminal window or application."
29
+ puts "\nctrl+c to close."
30
+ ::Bcome::Command::Local.run(tunnel_command)
31
+ end
32
+ end
33
+
34
+ def ping
35
+ ssh_connect!
36
+ { success: true }
37
+ rescue Exception => e
38
+ { success: false, error: e }
39
+ end
40
+
41
+ def scp
42
+ ssh_connection.scp
43
+ end
44
+
45
+ def put(local_path, remote_path)
46
+ raise Bcome::Exception::MissingParamsForScp, "'put' requires a local_path and a remote_path" if local_path.to_s.empty? || remote_path.to_s.empty?
47
+
48
+ puts "\n(#{@context_node.namespace})\s".namespace + "Uploading #{local_path} to #{remote_path}\n".informational
49
+
50
+ begin
51
+ scp.upload!(local_path, remote_path, recursive: true) do |_ch, name, sent, total|
52
+ puts "#{name}: #{sent}/#{total}".progress
53
+ end
54
+ rescue Exception => e # scp just throws generic exceptions :-/
55
+ puts e.message.error
56
+ end
57
+ nil
58
+ end
59
+
60
+ def put_str(string, remote_path)
61
+ raise Bcome::Exception::MissingParamsForScp, "'put' requires a string and a remote_path" if string.to_s.empty? || remote_path.to_s.empty?
62
+
63
+ puts "\n(#{@context_node.namespace})\s".namespace + "Uploading from string to #{remote_path}\n".informational
64
+
65
+ begin
66
+ scp.upload!(StringIO.new(string), remote_path) do |_ch, name, sent, total|
67
+ puts "#{name}: #{sent}/#{total}".progress
68
+ end
69
+ rescue Exception => e # scp just throws generic exceptions :-/
70
+ puts e.message.error
71
+ end
72
+ nil
73
+ end
74
+
75
+ def get(remote_path, local_path)
76
+ raise Bcome::Exception::MissingParamsForScp, "'get' requires a local_path and a remote_path" if local_path.to_s.empty? || remote_path.to_s.empty?
77
+
78
+ puts "\n(#{@context_node.namespace})\s".namespace + "Downloading #{remote_path} to #{local_path}\n".informational
79
+
80
+ begin
81
+ scp.download!(remote_path, local_path, recursive: true) do |_ch, name, sent, total|
82
+ puts "#{name}: #{sent}/#{total}".progress
83
+ end
84
+ rescue Exception => e
85
+ puts e.message.error
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ::Bcome::Ssh
4
+ module DriverUser
5
+ def user
6
+ # If we have a user explictly set in the config, then return it
7
+ return @config[:user] if @config[:user]
8
+
9
+ # If the local user has explicitly overriden their user, return that
10
+ return overriden_local_user if overriden_local_user
11
+
12
+ # Else fall back to whichever local user is using bcome
13
+ fallback_local_user
14
+ end
15
+
16
+ def overriden_local_user
17
+ @overriden_local_user ||= get_overriden_local_user
18
+ end
19
+
20
+ def get_overriden_local_user
21
+ ::Bcome::Node::Factory.instance.local_data[:ssh_user]
22
+ end
23
+
24
+ def fallback_local_user
25
+ @fallback_local_user ||= ::Bcome::System::Local.instance.local_user
26
+ end
27
+
28
+ def fallback_bastion_host_user
29
+ user
30
+ end
31
+ end
32
+ end
@@ -1,16 +1,55 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Bcome::Ssh
2
- class ProxyData
3
- def initialize(config, context_node)
4
+ class ProxyHop
5
+ attr_reader :parent
6
+
7
+ def initialize(config, context_node, parent)
4
8
  @config = config
5
9
  @context_node = context_node
10
+ @parent = parent
11
+ end
12
+
13
+ def proxy_details
14
+ @config.merge(
15
+ proxy_host: host,
16
+ user: user
17
+ )
6
18
  end
7
19
 
8
20
  def host
9
21
  @host ||= get_host
10
22
  end
11
23
 
12
- def bastion_host_user
13
- @bastion_host_user ||= get_bastion_host_user
24
+ def user
25
+ @user ||= get_user
26
+ end
27
+
28
+ def has_parent?
29
+ !parent.nil?
30
+ end
31
+
32
+ def get_ssh_string(_is_first_hop = false)
33
+ con_str = "#{user}@#{host}"
34
+ con_str
35
+ end
36
+
37
+ def get_rsync_string
38
+ con_str = ''
39
+
40
+ con_str += "#{parent.get_rsync_string}\s" if has_parent?
41
+
42
+ con_str += "'ssh -o \"ProxyCommand ssh -A #{user}@#{host} -W %h:%p\"'"
43
+ con_str
44
+ end
45
+
46
+ def get_local_port_forward_string
47
+ con_str = ''
48
+
49
+ con_str += parent.get_local_port_forward_string.to_s if has_parent?
50
+
51
+ con_str += "#{user}@#{host}\s"
52
+ con_str
14
53
  end
15
54
 
16
55
  private
@@ -23,16 +62,20 @@ module Bcome::Ssh
23
62
  }
24
63
  end
25
64
 
26
- def get_bastion_host_user
27
- @config[:bastion_host_user]
65
+ def get_user
66
+ @config[:bastion_host_user] || @config[:fallback_bastion_host_user]
28
67
  end
29
68
 
30
69
  def get_host
31
70
  raise Bcome::Exception::InvalidProxyConfig, 'Missing host id or namespace' unless @config[:host_id] || @config[:namespace]
32
71
  raise Bcome::Exception::InvalidProxyConfig, 'Missing host lookup method' unless @config[:host_lookup]
72
+
33
73
  host_lookup_method = valid_host_lookups[@config[:host_lookup].to_sym]
34
74
  raise Bcome::Exception::InvalidProxyConfig, "#{@config[:host_lookup]} is not a valid host lookup method" unless host_lookup_method
35
- send(host_lookup_method)
75
+
76
+ h = send(host_lookup_method)
77
+
78
+ h
36
79
  end
37
80
 
38
81
  def get_host_or_ip_from_config
@@ -44,12 +87,14 @@ module Bcome::Ssh
44
87
  resource = @context_node.recurse_resource_for_identifier(identifier)
45
88
  raise Bcome::Exception::CantFindProxyHostByIdentifier, identifier unless resource
46
89
  raise Bcome::Exception::ProxyHostNodeDoesNotHavePublicIp, identifier unless resource.public_ip_address
90
+
47
91
  resource.public_ip_address
48
92
  end
49
93
 
50
94
  def get_host_by_namespace
51
95
  node = ::Bcome::Orchestrator.instance.get(@config[:namespace])
52
96
  raise Bcome::Exception::CantFindProxyHostByNamespace, @config[:namespace] unless node
97
+
53
98
  node.public_ip_address
54
99
  end
55
100
  end
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ::Bcome::Ssh
2
4
  class ScriptExec
3
- SCRIPTS_PATH = 'bcome/scripts'.freeze
5
+ SCRIPTS_PATH = 'bcome/scripts'
4
6
 
5
7
  class << self
6
8
  def execute(server, script_name)
@@ -24,6 +26,7 @@ module ::Bcome::Ssh
24
26
  def execute_command
25
27
  local_path_to_script = "#{SCRIPTS_PATH}/#{@script_name}.sh"
26
28
  raise Bcome::Exception::OrchestrationScriptDoesNotExist, local_path_to_script unless File.exist?(local_path_to_script)
29
+
27
30
  execute_script_command = "#{@ssh_driver.ssh_command} \"bash -s\" < #{local_path_to_script}"
28
31
  command = ::Bcome::Command::Local.run(execute_script_command)
29
32
  command
@@ -1,20 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Bcome::Ssh::Tunnel
2
4
  class LocalPortForward
3
-
4
5
  def initialize(tunnel_command)
5
6
  @tunnel_command = tunnel_command
6
7
  @process_pid = nil
7
- end
8
+ end
8
9
 
9
10
  def open!
10
- puts "Opening tunnel: #{@tunnel_command}".informational
11
11
  @process_pid = spawn(@tunnel_command)
12
12
  end
13
13
 
14
14
  def close!
15
- puts "Closing tunnel with process pid ##{@process_pid}: #{@tunnel_command}".informational
16
- ::Process.kill("HUP", @process_pid)
15
+ puts "Closing tunnel:\s".informational + @tunnel_command.to_s.terminal_prompt
16
+ ::Process.kill('HUP', @process_pid)
17
17
  end
18
-
19
18
  end
20
19
  end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bcome
4
+ module Ssh
5
+ class TunnelKeeper
6
+ include Singleton
7
+
8
+ def initialize
9
+ @tunnels = []
10
+ end
11
+
12
+ def <<(tunnel)
13
+ @tunnels << tunnel
14
+ end
15
+
16
+ def close_tunnels
17
+ @tunnels.each(&:close!)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bcome
4
+ module Ssh
5
+ class Window
6
+ attr_reader :lines
7
+
8
+ include Singleton
9
+
10
+ def initialize(*_params)
11
+ @lines = []
12
+ end
13
+
14
+ def add(node, log_line)
15
+ multi_line = log_line =~ /\n/ ? true : false
16
+
17
+ @lines << if ::Bcome::Orchestrator.instance.is_multi_node?
18
+ "\n#{node.namespace}".terminal_prompt + "\n#{log_line}"
19
+ else
20
+ log_line
21
+ end
22
+
23
+ pop
24
+ end
25
+
26
+ def pop
27
+ print @lines.pop
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bcome
4
+ class Startup
5
+ def initialize(breadcrumbs, arguments)
6
+ @breadcrumbs = breadcrumbs
7
+ @arguments = arguments
8
+ end
9
+
10
+ def do
11
+ case @breadcrumbs
12
+ when '-v', '--version', '--v'
13
+ puts ::Bcome::Version.display
14
+ when 'pack_metadata'
15
+ ::Bcome::Encryptor.instance.pack
16
+ when 'unpack_metadata'
17
+ ::Bcome::Encryptor.instance.unpack
18
+ else
19
+ bootup
20
+ end
21
+ end
22
+
23
+ def bootup
24
+ spawn_into_console = true
25
+ ::Bcome::Bootup.set_and_do({ breadcrumbs: @breadcrumbs, arguments: @arguments }, spawn_into_console)
26
+ clean_up
27
+ rescue ::Bcome::Exception::Base => e
28
+ clean_up
29
+ puts e.pretty_display
30
+ rescue Excon::Error::Socket => e
31
+ clean_up
32
+ puts "\nNo network access - please check your connection and try again\n".error
33
+ rescue Exception => e
34
+ clean_up
35
+ raise e
36
+ end
37
+
38
+ def clean_up
39
+ stop_loading_bars
40
+ close_connections
41
+ end
42
+
43
+ def close_connections
44
+ ::Bcome::Bootup.instance.close_ssh_connections
45
+ ::Bcome::Ssh::TunnelKeeper.instance.close_tunnels
46
+ end
47
+
48
+ def stop_loading_bars
49
+ ::Bcome::LoadingBar::PidBucket.instance.stop_all
50
+ end
51
+ end
52
+ end