bcome 1.3.4 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/bin/bcome +13 -8
- data/lib/bcome.rb +14 -11
- data/lib/objects/bcome/version.rb +19 -1
- data/lib/objects/bootup.rb +16 -7
- data/lib/objects/command/local.rb +2 -0
- data/lib/objects/config_factory.rb +3 -0
- data/lib/objects/driver/base.rb +52 -6
- data/lib/objects/driver/bucket.rb +6 -4
- data/lib/objects/driver/ec2.rb +45 -5
- data/lib/objects/driver/gcp.rb +168 -0
- data/lib/objects/driver/gcp/authentication/api_key.rb +6 -0
- data/lib/objects/driver/gcp/authentication/base.rb +36 -0
- data/lib/objects/driver/gcp/authentication/oauth.rb +96 -0
- data/lib/objects/driver/gcp/authentication/oauth_client_config.rb +22 -0
- data/lib/objects/driver/gcp/authentication/oauth_session_store.rb +22 -0
- data/lib/objects/driver/gcp/authentication/service_account.rb +62 -0
- data/lib/objects/driver/gcp/authentication/signet/service_account.rb +27 -0
- data/lib/objects/driver/gcp/authentication/utilities.rb +42 -0
- data/lib/objects/encryptor.rb +109 -24
- data/lib/objects/exception/argument_error_invoking_method_from_command_line.rb +8 -4
- data/lib/objects/exception/base.rb +21 -10
- data/lib/objects/exception/can_only_subselect_on_inventory.rb +8 -4
- data/lib/objects/exception/cannot_authenticate_to_gcp.rb +11 -0
- data/lib/objects/exception/cannot_find_internal_registry_klass.rb +8 -4
- data/lib/objects/exception/cannot_find_inventory.rb +11 -0
- data/lib/objects/exception/cannot_find_subselection_parent.rb +8 -4
- data/lib/objects/exception/cant_find_key_in_cloud_tags.rb +8 -4
- data/lib/objects/exception/cant_find_key_in_metadata.rb +8 -4
- data/lib/objects/exception/cant_find_proxy_host_by_identifier.rb +8 -4
- data/lib/objects/exception/cant_find_proxy_host_by_namespace.rb +8 -4
- data/lib/objects/exception/could_not_initiate_ssh_connection.rb +8 -4
- data/lib/objects/exception/could_not_initiate_ssh_connection_through_backend_proxy.rb +8 -4
- data/lib/objects/exception/could_not_retrieve_terraform_output.rb +11 -0
- data/lib/objects/exception/deprecation_warning.rb +9 -7
- data/lib/objects/exception/duplicate_command_line_argument_key.rb +8 -4
- data/lib/objects/exception/ec2_driver_missing_authorization_keys.rb +11 -0
- data/lib/objects/exception/ec2_driver_missing_provisioning_region.rb +8 -4
- data/lib/objects/exception/empty_namespace_tree.rb +11 -0
- data/lib/objects/exception/failed_to_run_local_command.rb +8 -4
- data/lib/objects/exception/gcp_auth_service_account_missing_credentials.rb +11 -0
- data/lib/objects/exception/generic.rb +11 -0
- data/lib/objects/exception/interactive_session_halt.rb +6 -2
- data/lib/objects/exception/invalid_bcome_breadcrumb.rb +8 -4
- data/lib/objects/exception/invalid_breadcrumb.rb +8 -4
- data/lib/objects/exception/invalid_context_command.rb +8 -4
- data/lib/objects/exception/invalid_gcp_authentication_scheme.rb +11 -0
- data/lib/objects/exception/invalid_identifier.rb +8 -4
- data/lib/objects/exception/invalid_machines_cache_config.rb +8 -4
- data/lib/objects/exception/invalid_matcher_query.rb +8 -4
- data/lib/objects/exception/invalid_meta_data_config.rb +8 -4
- data/lib/objects/exception/invalid_metadata_encryption_key.rb +8 -4
- data/lib/objects/exception/invalid_network_config.rb +8 -4
- data/lib/objects/exception/invalid_network_driver_type.rb +8 -4
- data/lib/objects/exception/invalid_port_forward_request.rb +11 -0
- data/lib/objects/exception/invalid_proxy_config.rb +8 -4
- data/lib/objects/exception/invalid_regexp_matcher_in_registry.rb +8 -4
- data/lib/objects/exception/invalid_registry_arguments_type.rb +8 -4
- data/lib/objects/exception/invalid_registry_command_name_length.rb +8 -4
- data/lib/objects/exception/invalid_registry_data_config.rb +8 -4
- data/lib/objects/exception/invalid_restriction_key_in_registry.rb +8 -4
- data/lib/objects/exception/invalid_ssh_config.rb +8 -4
- data/lib/objects/exception/inventories_cannot_have_subviews.rb +8 -4
- data/lib/objects/exception/malformed_command_line_arguments.rb +8 -4
- data/lib/objects/exception/method_invocation_requires_parameter.rb +8 -4
- data/lib/objects/exception/method_name_conflict_in_registry.rb +8 -4
- data/lib/objects/exception/missing_argument_for_registry_command.rb +8 -4
- data/lib/objects/exception/missing_description_on_view.rb +8 -4
- data/lib/objects/exception/missing_execute_on_registry_object.rb +8 -4
- data/lib/objects/exception/missing_gcp_authentication_scheme.rb +11 -0
- data/lib/objects/exception/missing_gcp_service_account_credentials_filename.rb +11 -0
- data/lib/objects/exception/missing_gcp_service_scopes.rb +11 -0
- data/lib/objects/exception/missing_identifier_on_view.rb +8 -4
- data/lib/objects/exception/missing_inventory_contributors.rb +11 -0
- data/lib/objects/exception/missing_ip_address_on_server.rb +8 -4
- data/lib/objects/exception/missing_network_config.rb +8 -4
- data/lib/objects/exception/missing_or_invalid_client_secrets.rb +11 -0
- data/lib/objects/exception/missing_params_for_rsync.rb +8 -4
- data/lib/objects/exception/missing_params_for_scp.rb +8 -4
- data/lib/objects/exception/missing_subselection_key.rb +8 -4
- data/lib/objects/exception/missing_type_on_view.rb +8 -4
- data/lib/objects/exception/no_node_found_for_breadcrumb.rb +8 -4
- data/lib/objects/exception/no_node_named_by_identifier.rb +8 -4
- data/lib/objects/exception/node_identifiers_must_be_unique.rb +8 -4
- data/lib/objects/exception/orchestration_script_does_not_exist.rb +8 -4
- data/lib/objects/exception/proxy_host_node_does_not_have_public_ip_address.rb +8 -4
- data/lib/objects/exception/unknown_dynamic_server_type.rb +11 -0
- data/lib/objects/exception/unknown_method_for_namespace.rb +8 -4
- data/lib/objects/exception/user_orchestration_error.rb +11 -0
- data/lib/objects/initialization/factory.rb +36 -0
- data/lib/objects/initialization/structure.rb +18 -0
- data/lib/objects/initialization/utils.rb +20 -0
- data/lib/objects/interactive/session.rb +4 -1
- data/lib/objects/interactive/session_item/base.rb +2 -0
- data/lib/objects/interactive/session_item/capture_input.rb +2 -0
- data/lib/objects/interactive/session_item/transparent_ssh.rb +29 -23
- data/lib/objects/loading_bar/handler.rb +80 -0
- data/lib/objects/loading_bar/indicator/base.rb +65 -0
- data/lib/objects/loading_bar/indicator/basic.rb +34 -0
- data/lib/objects/loading_bar/indicator/progress.rb +26 -0
- data/lib/objects/loading_bar/pid_bucket.rb +27 -0
- data/lib/objects/modules/context.rb +13 -9
- data/lib/objects/modules/draw.rb +49 -0
- data/lib/objects/modules/registry_management.rb +16 -10
- data/lib/objects/modules/tree.rb +157 -0
- data/lib/objects/modules/ui_output.rb +10 -6
- data/lib/objects/modules/workspace_commands.rb +131 -157
- data/lib/objects/modules/workspace_menu.rb +193 -129
- data/lib/objects/node/attributes.rb +17 -19
- data/lib/objects/node/base.rb +136 -74
- data/lib/objects/node/cache_handler.rb +3 -1
- data/lib/objects/node/collection.rb +10 -9
- data/lib/objects/node/factory.rb +47 -36
- data/lib/objects/node/inventory/base.rb +106 -100
- data/lib/objects/node/inventory/defined.rb +113 -89
- data/lib/objects/node/inventory/merge.rb +51 -0
- data/lib/objects/node/inventory/subselect.rb +66 -46
- data/lib/objects/node/kube/base.rb +51 -0
- data/lib/objects/node/kube/container.rb +9 -0
- data/lib/objects/node/kube/estate.rb +19 -0
- data/lib/objects/node/kube/namespace.rb +24 -0
- data/lib/objects/node/kube/pod.rb +24 -0
- data/lib/objects/node/kube_wrap.rb +26 -0
- data/lib/objects/node/meta/base.rb +8 -1
- data/lib/objects/node/meta/cloud.rb +2 -0
- data/lib/objects/node/meta/local.rb +2 -0
- data/lib/objects/node/meta_data_factory.rb +4 -2
- data/lib/objects/node/meta_data_loader.rb +28 -29
- data/lib/objects/node/resources/base.rb +5 -1
- data/lib/objects/node/resources/inventory.rb +26 -5
- data/lib/objects/node/resources/merged.rb +47 -0
- data/lib/objects/node/resources/sub_inventory.rb +12 -8
- data/lib/objects/node/server/base.rb +105 -70
- data/lib/objects/node/server/dynamic/base.rb +23 -0
- data/lib/objects/node/server/{dynamic.rb → dynamic/ec2.rb} +13 -13
- data/lib/objects/node/server/dynamic/gcp.rb +46 -0
- data/lib/objects/node/server/static.rb +34 -10
- data/lib/objects/orchestration/base.rb +17 -1
- data/lib/objects/orchestration/interactive_terraform.rb +59 -30
- data/lib/objects/orchestrator.rb +22 -0
- data/lib/objects/parser/bread_crumb.rb +3 -1
- data/lib/objects/registry/arguments/base.rb +3 -1
- data/lib/objects/registry/arguments/command_line.rb +6 -1
- data/lib/objects/registry/arguments/console.rb +4 -1
- data/lib/objects/registry/command/base.rb +3 -0
- data/lib/objects/registry/command/external.rb +9 -3
- data/lib/objects/registry/command/group.rb +11 -4
- data/lib/objects/registry/command/internal.rb +3 -1
- data/lib/objects/registry/command/shortcut.rb +17 -9
- data/lib/objects/registry/command_list.rb +2 -0
- data/lib/objects/registry/loader.rb +13 -10
- data/lib/objects/ssh/bootstrap.rb +3 -1
- data/lib/objects/ssh/command.rb +9 -8
- data/lib/objects/ssh/command_exec.rb +16 -10
- data/lib/objects/ssh/connection_wrangler.rb +124 -0
- data/lib/objects/ssh/connector.rb +108 -0
- data/lib/objects/ssh/driver.rb +28 -242
- data/lib/objects/ssh/driver_concerns/command_strings.rb +17 -0
- data/lib/objects/ssh/driver_concerns/connection.rb +75 -0
- data/lib/objects/ssh/driver_concerns/functions.rb +89 -0
- data/lib/objects/ssh/driver_concerns/user.rb +32 -0
- data/lib/objects/ssh/proxy_chain.rb +19 -0
- data/lib/objects/ssh/proxy_chain_link.rb +26 -0
- data/lib/objects/ssh/proxy_hop.rb +130 -0
- data/lib/objects/ssh/script_exec.rb +12 -11
- data/lib/objects/ssh/tunnel/local_port_forward.rb +5 -6
- data/lib/objects/ssh/tunnel_keeper.rb +21 -0
- data/lib/objects/ssh/window.rb +31 -0
- data/lib/objects/startup.rb +58 -0
- data/lib/objects/system/local.rb +3 -0
- data/lib/objects/terraform/output.rb +45 -0
- data/lib/objects/workspace.rb +13 -14
- data/patches/irb.rb +63 -6
- data/patches/string-encrypt.rb +20 -23
- data/patches/string.rb +18 -1
- data/patches/string_stylesheet.rb +2 -0
- metadata +157 -33
- data/lib/objects/driver/static.rb +0 -4
- data/lib/objects/progress_bar.rb +0 -30
- data/lib/objects/ssh/connection_handler.rb +0 -101
- data/lib/objects/ssh/proxy_data.rb +0 -56
- data/lib/objects/terraform/parser.rb +0 -23
- data/lib/objects/terraform/state.rb +0 -40
@@ -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
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bcome::Ssh
|
4
|
+
class ProxyChain
|
5
|
+
attr_reader :hops
|
6
|
+
|
7
|
+
def initialize(wrangler)
|
8
|
+
@hops = wrangler.hops
|
9
|
+
end
|
10
|
+
|
11
|
+
def eql?(other_chain)
|
12
|
+
hops == other_chain.hops
|
13
|
+
end
|
14
|
+
|
15
|
+
def ==(other_chain)
|
16
|
+
eql?(other_chain)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bcome::Ssh
|
4
|
+
class ProxyChainLink
|
5
|
+
attr_reader :link
|
6
|
+
|
7
|
+
def initialize(node)
|
8
|
+
@link = {}
|
9
|
+
init(node.machines)
|
10
|
+
end
|
11
|
+
|
12
|
+
protected
|
13
|
+
|
14
|
+
def init(machines)
|
15
|
+
machines.each do |machine|
|
16
|
+
proxy_chain = machine.proxy_chain
|
17
|
+
|
18
|
+
if key = @link.keys.detect { |key| key.eql?(proxy_chain) }
|
19
|
+
@link[key] << machine
|
20
|
+
else
|
21
|
+
@link[proxy_chain] = [machine]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,130 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bcome::Ssh
|
4
|
+
class ProxyHop
|
5
|
+
include Bcome::Draw
|
6
|
+
|
7
|
+
attr_reader :parent, :config, :host, :bcome_proxy_node
|
8
|
+
|
9
|
+
def initialize(config, context_node, parent)
|
10
|
+
@config = config
|
11
|
+
@context_node = context_node
|
12
|
+
@parent = parent
|
13
|
+
set_host
|
14
|
+
end
|
15
|
+
|
16
|
+
def proxy_details
|
17
|
+
@config.merge(
|
18
|
+
proxy_host: host,
|
19
|
+
user: user
|
20
|
+
).except!(:bastion_host_user, :fallback_bastion_host_user)
|
21
|
+
end
|
22
|
+
|
23
|
+
def pretty_proxy_details(n = 1)
|
24
|
+
lines = ["proxy\s".bc_cyan + "[#{n}]"]
|
25
|
+
|
26
|
+
lines << "bcome node\s".bc_yellow + @bcome_proxy_node.keyed_namespace if @bcome_proxy_node
|
27
|
+
|
28
|
+
lines << "host\s".bc_yellow + host
|
29
|
+
lines << "user\s".bc_yellow + user
|
30
|
+
|
31
|
+
lines
|
32
|
+
end
|
33
|
+
|
34
|
+
def user
|
35
|
+
@user ||= get_user
|
36
|
+
end
|
37
|
+
|
38
|
+
def has_parent?
|
39
|
+
!parent.nil?
|
40
|
+
end
|
41
|
+
|
42
|
+
def ==(other)
|
43
|
+
config == other.config
|
44
|
+
end
|
45
|
+
|
46
|
+
def eql?(other)
|
47
|
+
config == other.config
|
48
|
+
end
|
49
|
+
|
50
|
+
def get_ssh_string(_is_first_hop = false)
|
51
|
+
con_str = "#{user}@#{host}"
|
52
|
+
con_str
|
53
|
+
end
|
54
|
+
|
55
|
+
def get_rsync_string
|
56
|
+
con_str = ''
|
57
|
+
|
58
|
+
con_str += "#{parent.get_rsync_string}\s" if has_parent?
|
59
|
+
|
60
|
+
con_str += "'ssh -o \"ProxyCommand ssh -A #{user}@#{host} -W %h:%p\"'"
|
61
|
+
con_str
|
62
|
+
end
|
63
|
+
|
64
|
+
def get_local_port_forward_string
|
65
|
+
con_str = ''
|
66
|
+
|
67
|
+
con_str += parent.get_local_port_forward_string.to_s if has_parent?
|
68
|
+
|
69
|
+
con_str += "#{user}@#{host}\s"
|
70
|
+
con_str
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
def valid_host_lookups
|
76
|
+
{
|
77
|
+
by_inventory_node: :get_host_by_inventory_node,
|
78
|
+
by_host_or_ip: :get_host_or_ip_from_config,
|
79
|
+
by_bcome_namespace: :get_host_by_namespace
|
80
|
+
}
|
81
|
+
end
|
82
|
+
|
83
|
+
def get_user
|
84
|
+
# If an explicit user has been set for this hop, use it.
|
85
|
+
return @config[:bastion_host_user] if @config[:bastion_host_user]
|
86
|
+
|
87
|
+
# 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.
|
88
|
+
return @bcome_proxy_node.ssh_driver.user if @bcome_proxy_node
|
89
|
+
|
90
|
+
# Otherwise, we'll fallback
|
91
|
+
@config[:fallback_bastion_host_user]
|
92
|
+
end
|
93
|
+
|
94
|
+
def set_host
|
95
|
+
raise Bcome::Exception::InvalidProxyConfig, 'Missing host id or namespace' unless @config[:node_identifier] || @config[:host_id] || @config[:namespace]
|
96
|
+
raise Bcome::Exception::InvalidProxyConfig, 'Missing host lookup method' unless @config[:host_lookup]
|
97
|
+
|
98
|
+
host_lookup_method = valid_host_lookups[@config[:host_lookup].to_sym]
|
99
|
+
raise Bcome::Exception::InvalidProxyConfig, "#{@config[:host_lookup]} is not a valid host lookup method" unless host_lookup_method
|
100
|
+
|
101
|
+
@host = send(host_lookup_method)
|
102
|
+
end
|
103
|
+
|
104
|
+
def get_host_or_ip_from_config
|
105
|
+
@config[:host_id]
|
106
|
+
end
|
107
|
+
|
108
|
+
# Older lookup - within same parent-child tree only. Retained for backwards compatibility
|
109
|
+
def get_host_by_inventory_node
|
110
|
+
identifier = @config[:host_id] || @config[:node_identifier]
|
111
|
+
@bcome_proxy_node = @context_node.recurse_resource_for_identifier(identifier)
|
112
|
+
raise Bcome::Exception::CantFindProxyHostByIdentifier, identifier unless @bcome_proxy_node
|
113
|
+
raise Bcome::Exception::ProxyHostNodeDoesNotHavePublicIp, identifier unless @bcome_proxy_node.public_ip_address
|
114
|
+
|
115
|
+
bcome_node_host
|
116
|
+
end
|
117
|
+
|
118
|
+
# Newer lookup - across entire network
|
119
|
+
def get_host_by_namespace
|
120
|
+
@bcome_proxy_node = ::Bcome::Orchestrator.instance.get(@config[:namespace])
|
121
|
+
raise Bcome::Exception::CantFindProxyHostByNamespace, @config[:namespace] unless @bcome_proxy_node
|
122
|
+
|
123
|
+
bcome_node_host
|
124
|
+
end
|
125
|
+
|
126
|
+
def bcome_node_host
|
127
|
+
@bcome_proxy_node.public_ip_address || @bcome_proxy_node.internal_ip_address
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
@@ -1,18 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ::Bcome::Ssh
|
2
4
|
class ScriptExec
|
3
|
-
SCRIPTS_PATH = 'bcome/scripts'.freeze
|
4
|
-
|
5
5
|
class << self
|
6
|
-
def execute(server,
|
7
|
-
executor = new(server,
|
6
|
+
def execute(server, path_to_script)
|
7
|
+
executor = new(server, path_to_script)
|
8
8
|
executor.execute
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
-
def initialize(server,
|
12
|
+
def initialize(server, path_to_script)
|
13
13
|
@server = server
|
14
|
-
@
|
14
|
+
@path_to_script = path_to_script
|
15
15
|
@ssh_driver = server.ssh_driver
|
16
|
+
@output_string = ''
|
16
17
|
end
|
17
18
|
|
18
19
|
def execute
|
@@ -22,22 +23,22 @@ module ::Bcome::Ssh
|
|
22
23
|
end
|
23
24
|
|
24
25
|
def execute_command
|
25
|
-
|
26
|
-
|
27
|
-
execute_script_command = "#{@ssh_driver.ssh_command} \"bash -s\" < #{
|
26
|
+
raise Bcome::Exception::OrchestrationScriptDoesNotExist, @path_to_script unless File.exist?(@path_to_script)
|
27
|
+
|
28
|
+
execute_script_command = "#{@ssh_driver.ssh_command} \"bash -s\" < #{@path_to_script}"
|
28
29
|
command = ::Bcome::Command::Local.run(execute_script_command)
|
29
30
|
command
|
30
31
|
end
|
31
32
|
|
32
33
|
def pretty_print(command)
|
33
|
-
output_append("\n(#{@server.namespace})$".terminal_prompt + "> ./#{
|
34
|
+
output_append("\n(#{@server.namespace})$".terminal_prompt + "> ./#{@path_to_script} - \s#{command.pretty_result}\n")
|
34
35
|
output_append(command.stdout) # append stderr
|
35
36
|
output_append "\nSTDERR: #{command.stderr}" if command.failed?
|
36
37
|
puts "\n\n#{@output_string}\n\n"
|
37
38
|
end
|
38
39
|
|
39
40
|
def output_append(output_string)
|
40
|
-
@output_string
|
41
|
+
@output_string += "#{@output_string}#{output_string}"
|
41
42
|
end
|
42
43
|
end
|
43
44
|
end
|
@@ -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
|
16
|
-
::Process.kill(
|
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,58 @@
|
|
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
|
+
when 'diff_metadata'
|
19
|
+
::Bcome::Encryptor.instance.diff
|
20
|
+
when 'init'
|
21
|
+
::Bcome::Initialization::Factory.do
|
22
|
+
else
|
23
|
+
bootup
|
24
|
+
end
|
25
|
+
rescue Bcome::Exception::Base => e
|
26
|
+
e.pretty_display
|
27
|
+
end
|
28
|
+
|
29
|
+
def bootup
|
30
|
+
spawn_into_console = true
|
31
|
+
::Bcome::Bootup.set_and_do({ breadcrumbs: @breadcrumbs, arguments: @arguments }, spawn_into_console)
|
32
|
+
clean_up
|
33
|
+
rescue ::Bcome::Exception::Base => e
|
34
|
+
clean_up
|
35
|
+
e.pretty_display
|
36
|
+
rescue Excon::Error::Socket => e
|
37
|
+
clean_up
|
38
|
+
puts "\nNo network access - please check your connection and try again\n".error
|
39
|
+
rescue Exception => e
|
40
|
+
clean_up
|
41
|
+
raise e
|
42
|
+
end
|
43
|
+
|
44
|
+
def clean_up
|
45
|
+
stop_loading_bars
|
46
|
+
close_connections
|
47
|
+
end
|
48
|
+
|
49
|
+
def close_connections
|
50
|
+
::Bcome::Bootup.instance.close_ssh_connections
|
51
|
+
::Bcome::Ssh::TunnelKeeper.instance.close_tunnels
|
52
|
+
end
|
53
|
+
|
54
|
+
def stop_loading_bars
|
55
|
+
::Bcome::LoadingBar::PidBucket.instance.stop_all
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/lib/objects/system/local.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Bcome::System
|
2
4
|
class Local
|
3
5
|
include Singleton
|
@@ -10,6 +12,7 @@ module Bcome::System
|
|
10
12
|
# we fail fast if we're not in a console session
|
11
13
|
raise Bcome::Exception::FailedToRunLocalCommand, "#{raw_command}. Error: " + local_command.stderr
|
12
14
|
end
|
15
|
+
|
13
16
|
local_command
|
14
17
|
end
|
15
18
|
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bcome::Terraform
|
4
|
+
class Output
|
5
|
+
require 'json'
|
6
|
+
|
7
|
+
OUTPUT_COMMAND = 'terraform output -json'
|
8
|
+
|
9
|
+
def initialize(namespace)
|
10
|
+
@namespace = namespace
|
11
|
+
end
|
12
|
+
|
13
|
+
def output
|
14
|
+
@output ||= get_output
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def terraform_installation_path
|
20
|
+
@terraform_installation_path ||= "terraform/environments/#{@namespace.gsub(':', '_')}"
|
21
|
+
end
|
22
|
+
|
23
|
+
def get_output
|
24
|
+
get_output_result = do_get_output
|
25
|
+
|
26
|
+
# Until this feature is officially featured, failure to get terraform data will fail silently
|
27
|
+
# One thing not decided upon yet is how to indicate that we wish to load terraform data or not.
|
28
|
+
if get_output_result.failed?
|
29
|
+
raise "Received authorisation error retrieving metadata from Terraform outputs for namespace #{@namespace}. Command was '#{get_output_command}'. Are you authorised to access the TFstate?" if get_output_result.stderr =~ /HTTP response code 401/
|
30
|
+
|
31
|
+
return {}
|
32
|
+
end
|
33
|
+
|
34
|
+
JSON.parse(get_output_result.stdout)
|
35
|
+
end
|
36
|
+
|
37
|
+
def get_output_command
|
38
|
+
"cd #{terraform_installation_path} ; #{OUTPUT_COMMAND}"
|
39
|
+
end
|
40
|
+
|
41
|
+
def do_get_output
|
42
|
+
::Bcome::Command::Local.run(get_output_command)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|