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,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bcome::Node::Server::Dynamic
|
4
|
+
class Base < Bcome::Node::Server::Base
|
5
|
+
class << self
|
6
|
+
def override_identifier(parent, identifier)
|
7
|
+
if parent.override_server_identifier?
|
8
|
+
identifier =~ /#{parent.override_identifier}/
|
9
|
+
identifier = Regexp.last_match(1) if Regexp.last_match(1)
|
10
|
+
end
|
11
|
+
identifier
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def do_generate_cloud_tags
|
16
|
+
raise 'Should be overidden'
|
17
|
+
end
|
18
|
+
|
19
|
+
def cloud_server
|
20
|
+
raise 'Should be overidden'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -1,18 +1,15 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bcome::Node::Server::Dynamic
|
4
|
+
class Ec2 < Bcome::Node::Server::Dynamic::Base
|
3
5
|
class << self
|
4
|
-
def
|
5
|
-
|
6
|
+
def dynamic_server_type
|
7
|
+
:ec2
|
6
8
|
end
|
7
9
|
|
8
10
|
def new_from_fog_instance(fog_instance, parent)
|
9
11
|
identifier = fog_instance.tags['Name']
|
10
12
|
|
11
|
-
if parent.override_server_identifier?
|
12
|
-
identifier =~ /#{parent.override_identifier}/
|
13
|
-
identifier = Regexp.last_match(1) if Regexp.last_match(1)
|
14
|
-
end
|
15
|
-
|
16
13
|
params = {
|
17
14
|
identifier: identifier,
|
18
15
|
internal_ip_address: fog_instance.private_ip_address,
|
@@ -22,17 +19,20 @@ module Bcome::Node::Server
|
|
22
19
|
ec2_server: fog_instance
|
23
20
|
}
|
24
21
|
|
25
|
-
new(parent: parent,
|
26
|
-
views: params)
|
22
|
+
new(parent: parent, views: params)
|
27
23
|
end
|
28
24
|
end
|
29
25
|
|
26
|
+
def host
|
27
|
+
'EC2'
|
28
|
+
end
|
29
|
+
|
30
30
|
def do_generate_cloud_tags
|
31
|
-
raw_tags =
|
31
|
+
raw_tags = cloud_server ? cloud_server.tags.deep_symbolize_keys : {}
|
32
32
|
::Bcome::Node::Meta::Cloud.new(raw_tags)
|
33
33
|
end
|
34
34
|
|
35
|
-
def
|
35
|
+
def cloud_server
|
36
36
|
views[:ec2_server]
|
37
37
|
end
|
38
38
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bcome::Node::Server::Dynamic
|
4
|
+
class Gcp < Bcome::Node::Server::Dynamic::Base
|
5
|
+
class << self
|
6
|
+
def dynamic_server_type
|
7
|
+
:gcp
|
8
|
+
end
|
9
|
+
|
10
|
+
def new_from_gcp_instance(gcp_instance, parent)
|
11
|
+
identifier = gcp_instance.name
|
12
|
+
|
13
|
+
## For now we support only the first network interface
|
14
|
+
first_interface = gcp_instance.network_interfaces.first
|
15
|
+
network_ip = first_interface.network_ip
|
16
|
+
|
17
|
+
## And we get the first access config (terraform uses the same pattern for accessing GCP machines also)
|
18
|
+
first_access_config = first_interface.access_configs ? first_interface.access_configs.first : nil
|
19
|
+
nat_ip = first_access_config ? first_access_config.nat_ip : nil
|
20
|
+
|
21
|
+
params = {
|
22
|
+
identifier: identifier,
|
23
|
+
description: "GCP server - #{identifier}",
|
24
|
+
internal_ip_address: network_ip,
|
25
|
+
public_ip_address: nat_ip,
|
26
|
+
gcp_server: gcp_instance
|
27
|
+
}
|
28
|
+
|
29
|
+
new(parent: parent, views: params)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def host
|
34
|
+
'GCP'
|
35
|
+
end
|
36
|
+
|
37
|
+
def do_generate_cloud_tags
|
38
|
+
raw_labels = cloud_server.labels ? cloud_server.labels.deep_symbolize_keys : {}
|
39
|
+
::Bcome::Node::Meta::Cloud.new(raw_labels)
|
40
|
+
end
|
41
|
+
|
42
|
+
def cloud_server
|
43
|
+
views[:gcp_server]
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -1,23 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Bcome::Node::Server
|
2
4
|
class Static < Bcome::Node::Server::Base
|
3
|
-
def
|
4
|
-
'static
|
5
|
+
def host
|
6
|
+
'static'
|
5
7
|
end
|
6
8
|
|
7
9
|
def initialize(params)
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
@
|
13
|
-
|
10
|
+
@view_config = params[:views]
|
11
|
+
|
12
|
+
set_cloud_tags
|
13
|
+
|
14
|
+
@identifier = @view_config[:identifier]
|
15
|
+
@public_ip_address = @view_config[:public_ip_address]
|
16
|
+
@internal_ip_address = @view_config[:internal_ip_address]
|
17
|
+
@cloud_tags = @view_config[:cloud_tags]
|
18
|
+
@description = @view_config[:description]
|
19
|
+
verify_we_have_at_least_one_interface
|
20
|
+
verify_identifier_and_description
|
14
21
|
super
|
15
22
|
end
|
16
23
|
|
17
24
|
attr_reader :cloud_tags
|
18
25
|
|
19
|
-
|
20
|
-
|
26
|
+
attr_reader :public_ip_address
|
27
|
+
|
28
|
+
attr_reader :internal_ip_address
|
29
|
+
|
30
|
+
attr_reader :cloud_tags
|
31
|
+
|
32
|
+
attr_reader :description
|
33
|
+
|
34
|
+
def set_cloud_tags
|
35
|
+
@view_config[:cloud_tags] = ::Bcome::Node::Meta::Cloud.new(@view_config[:cloud_tags]) unless @view_config[:cloud_tags].is_a?(::Bcome::Node::Meta::Cloud)
|
36
|
+
end
|
37
|
+
|
38
|
+
def verify_we_have_at_least_one_interface
|
39
|
+
raise Bcome::Exception::MissingIpaddressOnServer, @view_config unless has_at_least_one_interface?
|
40
|
+
end
|
41
|
+
|
42
|
+
def verify_identifier_and_description
|
43
|
+
raise Bcome::Exception::Generic, "Your static server defined by #{@view_config} is missing a description" unless @description
|
44
|
+
raise Bcome::Exception::Generic, "Your static server defined by #{@view_config} is missing an identifier" unless @identifier
|
21
45
|
end
|
22
46
|
|
23
47
|
def has_at_least_one_interface?
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Bcome::Orchestration
|
2
4
|
class Base
|
3
5
|
def initialize(node, arguments)
|
@@ -7,7 +9,21 @@ module Bcome::Orchestration
|
|
7
9
|
|
8
10
|
def do_execute
|
9
11
|
raise Bcome::Exception::MissingExecuteOnRegistryObject, self.class.to_s unless respond_to?(:execute)
|
10
|
-
|
12
|
+
|
13
|
+
begin
|
14
|
+
execute
|
15
|
+
rescue ::Bcome::Exception::Base => bcome_exception
|
16
|
+
show_backtrace = true unless bcome_exception.is_a?(::Bcome::Exception::InvalidMetaDataEncryptionKey)
|
17
|
+
bcome_exception.pretty_display(show_backtrace)
|
18
|
+
raise ::Bcome::Exception::UserOrchestrationError, self.class.to_s
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def method_missing(method_sym, *_arguments)
|
23
|
+
## A thread error deep in the bowels of IRB is not playing well with orchestration missing methods within the orchestration namespace. Until this can be resolved,
|
24
|
+
## I've re-implemented it here.
|
25
|
+
|
26
|
+
raise NameError, "NameError (undefined local variable or method '#{method_sym}' for #{self.class}"
|
11
27
|
end
|
12
28
|
end
|
13
29
|
end
|
@@ -1,18 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Bcome::Orchestration
|
2
|
-
class InteractiveTerraform < Bcome::Orchestration::Base
|
4
|
+
class InteractiveTerraform < Bcome::Orchestration::Base
|
5
|
+
## Prototype interactive terraform shell embedded within bcome.
|
6
|
+
|
7
|
+
# * Provides access to the metadata framework, so that data may be shared between Orchestrative processes and Terraform
|
8
|
+
# * Transparent authorization, by passing in cloud authorisation details from the bcome session
|
9
|
+
# * Passes in SSH credentials directly, which can be used to bootstrap machines.
|
10
|
+
|
11
|
+
QUIT = '\\q'
|
12
|
+
COMMAND_PROMPT = "enter command or '#{QUIT}' to quit: " + 'terraform'.informational + "\s"
|
3
13
|
|
4
|
-
|
5
|
-
|
14
|
+
def initialize(*params)
|
15
|
+
super
|
16
|
+
raise ::Bcome::Exception::Generic, "Missing terraform configuration directory #{path_to_env_config}" unless File.exist?(path_to_env_config)
|
17
|
+
end
|
6
18
|
|
7
19
|
def execute
|
8
20
|
show_intro_text
|
9
21
|
wait_for_command_input
|
10
22
|
end
|
11
|
-
|
23
|
+
|
12
24
|
def show_intro_text
|
13
|
-
puts "\n"
|
14
|
-
puts "
|
15
|
-
puts "Namespace:\s" +
|
25
|
+
puts "\n\n"
|
26
|
+
puts "Interactive Terraform\n".underline
|
27
|
+
puts "Namespace:\s" + @node.namespace.to_s.informational
|
16
28
|
puts "Configuration Path:\s" + "#{path_to_env_config}/*".informational
|
17
29
|
puts "\nConfigured metadata:\s" + terraform_metadata.inspect.informational
|
18
30
|
|
@@ -31,50 +43,67 @@ module Bcome::Orchestration
|
|
31
43
|
#
|
32
44
|
def wait_for_command_input
|
33
45
|
raw_command = wait_for_input
|
34
|
-
unless raw_command == QUIT
|
35
|
-
process_command(raw_command)
|
36
|
-
end
|
46
|
+
process_command(raw_command) unless raw_command == QUIT
|
37
47
|
end
|
38
|
-
|
48
|
+
|
39
49
|
def wait_for_input(message = COMMAND_PROMPT)
|
40
50
|
::Readline.readline("\n#{message}", true).squeeze('').to_s
|
41
|
-
end
|
51
|
+
end
|
42
52
|
|
43
53
|
# COMMAND PROCESSING
|
44
54
|
def terraform_metadata
|
45
|
-
@terraform_metadata ||= @node.metadata.fetch(
|
46
|
-
end
|
55
|
+
@terraform_metadata ||= @node.metadata.fetch('terraform', @node.metadata.fetch(:terraform, {}))
|
56
|
+
end
|
47
57
|
|
48
|
-
# Get the terraform variables for this stack, and merge in with our
|
58
|
+
# Get the terraform variables for this stack, and merge in with our networking & ssh credentials
|
49
59
|
def form_var_string
|
50
60
|
terraform_vars = terraform_metadata
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
61
|
+
|
62
|
+
terraform_vars.each do |key, value|
|
63
|
+
# Join arrays into a string (note we cannot handle nested arrays yet)
|
64
|
+
terraform_vars[key] = value.join(',') if value.is_a?(Array)
|
65
|
+
end
|
66
|
+
|
67
|
+
cleaned_data = terraform_vars.reject do |_k, v|
|
68
|
+
v.is_a?(Hash)
|
69
|
+
end # we can't yet handle nested terraform metadata on the command line so no hashes
|
70
|
+
|
71
|
+
all_vars = cleaned_data
|
72
|
+
|
73
|
+
if @node.network_driver.has_network_credentials?
|
74
|
+
network_credentials = @node.network_driver.network_credentials
|
75
|
+
all_vars = cleaned_data.merge(network_credentials)
|
76
|
+
end
|
77
|
+
|
78
|
+
all_vars[:ssh_user] = @node.ssh_driver.user
|
79
|
+
all_vars.collect { |key, value| "-var #{key}=\"#{value}\"" }.join("\s")
|
63
80
|
end
|
64
81
|
|
65
82
|
def var_string
|
66
83
|
@var_string ||= form_var_string
|
67
84
|
end
|
68
85
|
|
86
|
+
def backend_config_parameter_string
|
87
|
+
## Backend configs are loaded before Terraform Core which means that we cannot use variables directly in our backend config.
|
88
|
+
## This is a pain as we'll have authorised with GCP via the console, and so all sesssion have an access token readily available.
|
89
|
+
## This patch passes the access token directly to terraform as a parameter.
|
90
|
+
|
91
|
+
## GCP only for now. Support for AWS may come later as needed/requested.
|
92
|
+
return '' unless @node.network_driver.is_a?(::Bcome::Driver::Gcp)
|
93
|
+
|
94
|
+
"\s-backend-config \"access_token=#{@node.network_driver.network_credentials[:access_token]}\"\s"
|
95
|
+
end
|
96
|
+
|
69
97
|
# Retrieve the path to the terraform configurations for this stack
|
70
98
|
def path_to_env_config
|
71
|
-
@path_to_env_config ||= "terraform/environments/#{@node.namespace.gsub(
|
99
|
+
@path_to_env_config ||= "terraform/environments/#{@node.namespace.gsub(':', '_')}"
|
72
100
|
end
|
73
101
|
|
74
102
|
# Formulate a terraform command
|
75
103
|
def command(raw_command)
|
76
|
-
"cd #{path_to_env_config} ; terraform #{raw_command}
|
104
|
+
cmd = "cd #{path_to_env_config} ; terraform #{raw_command}"
|
105
|
+
cmd = "#{cmd} #{var_string}" if raw_command =~ Regexp.new(/^apply$|plan|destroy|refresh/)
|
106
|
+
cmd
|
77
107
|
end
|
78
|
-
|
79
108
|
end
|
80
109
|
end
|
data/lib/objects/orchestrator.rb
CHANGED
@@ -1,10 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class ::Bcome::Orchestrator
|
2
4
|
include ::Singleton
|
3
5
|
|
4
6
|
attr_reader :context
|
5
7
|
|
6
8
|
def initialize
|
9
|
+
reset!
|
10
|
+
end
|
11
|
+
|
12
|
+
def reset!
|
7
13
|
@silence = false
|
14
|
+
@tail_command_output = false
|
15
|
+
@multi_node = false
|
16
|
+
end
|
17
|
+
|
18
|
+
def is_multi_node?
|
19
|
+
@multi_node == true
|
8
20
|
end
|
9
21
|
|
10
22
|
def silence_command_output!
|
@@ -15,9 +27,19 @@ class ::Bcome::Orchestrator
|
|
15
27
|
@silence == true
|
16
28
|
end
|
17
29
|
|
30
|
+
def tail_all_command_output!(node)
|
31
|
+
@multi_node = node.machines.size > 1
|
32
|
+
@tail_command_output = true
|
33
|
+
end
|
34
|
+
|
35
|
+
def tail_all_command_output?
|
36
|
+
@tail_command_output == true
|
37
|
+
end
|
38
|
+
|
18
39
|
def get(breadcrumb = nil)
|
19
40
|
context = ::Bcome::Bootup.traverse(breadcrumb)
|
20
41
|
raise Bcome::Exception::NoNodeFoundForBreadcrumb, breadcrumb unless context
|
42
|
+
|
21
43
|
context.load_nodes if context.inventory? && !context.nodes_loaded?
|
22
44
|
context
|
23
45
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Bcome::Parser
|
2
4
|
class BreadCrumb
|
3
5
|
attr_reader :crumbs
|
@@ -25,7 +27,7 @@ module Bcome::Parser
|
|
25
27
|
end
|
26
28
|
|
27
29
|
def validate!
|
28
|
-
#raise Bcome::Exception::InvalidBcomeBreadcrumb.new "- letters, numbers & underscores only" unless @raw_crumbs =~ /^([a-z0-9A-Z_]+)(:\s*[a-z0-9A-Z_]+)*:?$/i
|
30
|
+
# raise Bcome::Exception::InvalidBcomeBreadcrumb.new "- letters, numbers & underscores only" unless @raw_crumbs =~ /^([a-z0-9A-Z_]+)(:\s*[a-z0-9A-Z_]+)*:?$/i
|
29
31
|
end
|
30
32
|
end
|
31
33
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Bcome::Registry::Arguments
|
2
4
|
class Base
|
3
5
|
attr_reader :arguments, :defaults, :processed_arguments, :merged_arguments
|
@@ -10,7 +12,7 @@ module Bcome::Registry::Arguments
|
|
10
12
|
end
|
11
13
|
|
12
14
|
def initialize(_arguments, defaults)
|
13
|
-
@defaults = defaults
|
15
|
+
@defaults = defaults || {}
|
14
16
|
validate
|
15
17
|
end
|
16
18
|
|
@@ -1,7 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Bcome::Registry::Arguments
|
2
4
|
class CommandLine < Base
|
3
5
|
def initialize(arguments, defaults)
|
4
|
-
@arguments = arguments
|
6
|
+
@arguments = arguments || []
|
5
7
|
@processed_arguments = {}
|
6
8
|
super
|
7
9
|
end
|
@@ -21,14 +23,17 @@ module Bcome::Registry::Arguments
|
|
21
23
|
@arguments.each do |argument|
|
22
24
|
argument =~ /^(.+)=(.+)$/
|
23
25
|
raise Bcome::Exception::MalformedCommandLineArguments, argument unless Regexp.last_match(1) || Regexp.last_match(2)
|
26
|
+
|
24
27
|
key = Regexp.last_match(1).to_sym; value = Regexp.last_match(2)
|
25
28
|
raise Bcome::Exception::DuplicateCommandLineArgumentKey, "'#{key}'" if @processed_arguments.key?(key)
|
29
|
+
|
26
30
|
@processed_arguments[key] = value
|
27
31
|
end
|
28
32
|
end
|
29
33
|
|
30
34
|
def validate
|
31
35
|
raise Bcome::Exception::InvalidRegistryArgumentType, 'invalid argument format' unless @arguments.is_a?(Array)
|
36
|
+
|
32
37
|
super
|
33
38
|
end
|
34
39
|
end
|
@@ -1,7 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Bcome::Registry::Arguments
|
2
4
|
class Console < Base
|
3
5
|
def initialize(arguments, defaults)
|
4
|
-
@arguments = arguments
|
6
|
+
@arguments = arguments || {}
|
5
7
|
super
|
6
8
|
end
|
7
9
|
|
@@ -9,6 +11,7 @@ module Bcome::Registry::Arguments
|
|
9
11
|
|
10
12
|
def validate
|
11
13
|
raise Bcome::Exception::InvalidRegistryArgumentType, 'invalid argument format' unless @arguments.is_a?(Hash)
|
14
|
+
|
12
15
|
super
|
13
16
|
end
|
14
17
|
end
|