bcome 1.3.6 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/bcome +13 -8
- data/lib/bcome.rb +7 -11
- data/lib/objects/bcome/version.rb +19 -1
- data/lib/objects/bootup.rb +13 -5
- data/lib/objects/command/local.rb +2 -0
- data/lib/objects/config_factory.rb +3 -0
- data/lib/objects/driver/base.rb +36 -4
- data/lib/objects/driver/bucket.rb +6 -4
- data/lib/objects/driver/ec2.rb +35 -4
- data/lib/objects/driver/gcp.rb +124 -0
- data/lib/objects/driver/gcp/authentication/api_key.rb +6 -0
- data/lib/objects/driver/gcp/authentication/oauth.rb +101 -0
- data/lib/objects/driver/gcp/authentication/service_account.rb +7 -0
- data/lib/objects/driver/static.rb +2 -0
- data/lib/objects/encryptor.rb +26 -24
- data/lib/objects/exception/argument_error_invoking_method_from_command_line.rb +8 -4
- data/lib/objects/exception/base.rb +14 -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_provisioning_region.rb +8 -4
- data/lib/objects/exception/failed_to_run_local_command.rb +8 -4
- 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_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/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 +64 -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/registry_management.rb +16 -10
- data/lib/objects/modules/ui_output.rb +10 -6
- data/lib/objects/modules/workspace_commands.rb +159 -155
- data/lib/objects/modules/workspace_menu.rb +129 -130
- data/lib/objects/node/attributes.rb +13 -21
- data/lib/objects/node/base.rb +113 -71
- data/lib/objects/node/cache_handler.rb +2 -0
- data/lib/objects/node/collection.rb +10 -9
- data/lib/objects/node/factory.rb +35 -28
- data/lib/objects/node/inventory/base.rb +100 -100
- data/lib/objects/node/inventory/defined.rb +110 -89
- data/lib/objects/node/inventory/merge.rb +43 -0
- data/lib/objects/node/inventory/subselect.rb +64 -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 +3 -1
- data/lib/objects/node/meta_data_loader.rb +27 -28
- data/lib/objects/node/resources/base.rb +5 -1
- data/lib/objects/node/resources/inventory.rb +7 -5
- data/lib/objects/node/resources/merged.rb +38 -0
- data/lib/objects/node/resources/sub_inventory.rb +7 -4
- data/lib/objects/node/server/base.rb +88 -66
- data/lib/objects/node/server/dynamic/base.rb +23 -0
- data/lib/objects/node/server/{dynamic.rb → dynamic/ec2.rb} +14 -13
- data/lib/objects/node/server/dynamic/gcp.rb +47 -0
- data/lib/objects/node/server/static.rb +13 -2
- data/lib/objects/orchestration/base.rb +10 -0
- data/lib/objects/orchestration/interactive_terraform.rb +62 -27
- 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 +4 -2
- data/lib/objects/registry/command/group.rb +6 -3
- 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 +10 -10
- data/lib/objects/ssh/bootstrap.rb +3 -1
- data/lib/objects/ssh/command.rb +10 -5
- data/lib/objects/ssh/command_exec.rb +13 -9
- data/lib/objects/ssh/connection_wrangler.rb +105 -0
- data/lib/objects/ssh/connector.rb +100 -0
- data/lib/objects/ssh/driver.rb +27 -230
- data/lib/objects/ssh/driver_concerns/command_strings.rb +17 -0
- data/lib/objects/ssh/driver_concerns/connection.rb +78 -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_data.rb → proxy_hop.rb} +52 -7
- data/lib/objects/ssh/script_exec.rb +4 -1
- 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 +52 -0
- data/lib/objects/system/local.rb +3 -0
- data/lib/objects/terraform/output.rb +41 -0
- data/lib/objects/workspace.rb +3 -14
- data/patches/irb.rb +27 -3
- data/patches/string-encrypt.rb +20 -23
- data/patches/string.rb +5 -1
- data/patches/string_stylesheet.rb +2 -0
- metadata +95 -18
- data/lib/objects/progress_bar.rb +0 -30
- data/lib/objects/ssh/connection_handler.rb +0 -101
- data/lib/objects/terraform/parser.rb +0 -23
- data/lib/objects/terraform/state.rb +0 -40
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bcome
|
4
|
+
module Node
|
5
|
+
module Inventory
|
6
|
+
class Merge < ::Bcome::Node::Inventory::Base
|
7
|
+
attr_reader :dynamic_nodes_loaded
|
8
|
+
|
9
|
+
def initialize(*params)
|
10
|
+
super
|
11
|
+
raise Bcome::Exception::MissingInventoryContributors, @views unless @views[:contributors]
|
12
|
+
end
|
13
|
+
|
14
|
+
def nodes_loaded?
|
15
|
+
true
|
16
|
+
end
|
17
|
+
|
18
|
+
def contributing_inventories
|
19
|
+
@inventories ||= @views[:contributors].collect { |inventory_key| load_inventory(inventory_key) }
|
20
|
+
end
|
21
|
+
|
22
|
+
def resources
|
23
|
+
@resources ||= do_set_resources
|
24
|
+
end
|
25
|
+
|
26
|
+
def update_nodes
|
27
|
+
resources.update_nodes(self)
|
28
|
+
end
|
29
|
+
|
30
|
+
def do_set_resources
|
31
|
+
::Bcome::Node::Resources::Merged.new(inventory: self)
|
32
|
+
end
|
33
|
+
|
34
|
+
def load_inventory(from_crumb)
|
35
|
+
inventory = ::Bcome::Node::Factory.instance.bucket[from_crumb]
|
36
|
+
raise Bcome::Exception::CannotFindInventory, "for key '#{from_crumb}'" unless inventory
|
37
|
+
|
38
|
+
inventory
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -1,60 +1,78 @@
|
|
1
|
-
|
2
|
-
class Subselect < ::Bcome::Node::Inventory::Base
|
3
|
-
def initialize(*params)
|
4
|
-
super
|
5
|
-
raise Bcome::Exception::MissingSubselectionKey, @views unless @views[:subselect_from]
|
6
|
-
update_nodes
|
7
|
-
end
|
1
|
+
# frozen_string_literal: true
|
8
2
|
|
9
|
-
|
10
|
-
|
11
|
-
|
3
|
+
module Bcome
|
4
|
+
module Node
|
5
|
+
module Inventory
|
6
|
+
class Subselect < ::Bcome::Node::Inventory::Base
|
7
|
+
def initialize(*params)
|
8
|
+
super
|
9
|
+
raise Bcome::Exception::MissingSubselectionKey, @views unless @views[:subselect_from]
|
12
10
|
|
13
|
-
|
14
|
-
|
15
|
-
end
|
11
|
+
update_nodes
|
12
|
+
end
|
16
13
|
|
17
|
-
|
18
|
-
|
19
|
-
|
14
|
+
def enabled_menu_items
|
15
|
+
super + %i[reload]
|
16
|
+
end
|
20
17
|
|
21
|
-
|
22
|
-
|
23
|
-
end
|
18
|
+
def menu_items
|
19
|
+
base_items = super.dup
|
24
20
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
21
|
+
base_items[:reload] = {
|
22
|
+
description: 'Restock this inventory from remote',
|
23
|
+
console_only: true
|
24
|
+
}
|
25
|
+
base_items
|
26
|
+
end
|
29
27
|
|
30
|
-
|
31
|
-
|
32
|
-
|
28
|
+
def resources
|
29
|
+
@resources ||= do_set_resources
|
30
|
+
end
|
33
31
|
|
34
|
-
|
35
|
-
|
36
|
-
|
32
|
+
def update_nodes
|
33
|
+
resources.update_nodes(self)
|
34
|
+
end
|
37
35
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
resources.run_subselect
|
42
|
-
update_nodes
|
43
|
-
return
|
44
|
-
end
|
36
|
+
def do_set_resources
|
37
|
+
::Bcome::Node::Resources::SubselectInventory.new(parent_inventory: parent_inventory, filters: filters)
|
38
|
+
end
|
45
39
|
|
46
|
-
|
40
|
+
def nodes_loaded?
|
41
|
+
true
|
42
|
+
end
|
47
43
|
|
48
|
-
|
49
|
-
|
50
|
-
|
44
|
+
def filters
|
45
|
+
# Flex point for filters, as obviously we need to support more than just ec2 filtering eventually
|
46
|
+
@views[:filters] || {}
|
47
|
+
end
|
48
|
+
|
49
|
+
def reload
|
50
|
+
do_reload
|
51
|
+
end
|
52
|
+
|
53
|
+
def do_reload
|
54
|
+
parent_inventory.resources.reset_duplicate_nodes!
|
55
|
+
parent_inventory.do_reload
|
56
|
+
resources.run_subselect
|
57
|
+
update_nodes
|
58
|
+
nil
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def parent_inventory
|
64
|
+
@parent_inventory ||= load_parent_inventory
|
65
|
+
end
|
66
|
+
|
67
|
+
def load_parent_inventory
|
68
|
+
parent_crumb = @views[:subselect_from]
|
69
|
+
parent = ::Bcome::Node::Factory.instance.bucket[parent_crumb]
|
70
|
+
raise Bcome::Exception::CannotFindSubselectionParent, "for key '#{parent_crumb}'" unless parent
|
71
|
+
raise Bcome::Exception::CanOnlySubselectOnInventory, "breadcrumb'#{parent_crumb}' represents a #{parent.class}'" unless parent.inventory?
|
51
72
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
raise Bcome::Exception::CannotFindSubselectionParent, "for key '#{parent_crumb}'" unless parent
|
56
|
-
raise Bcome::Exception::CanOnlySubselectOnInventory, "breadcrumb'#{parent_crumb}' represents a #{parent.class}'" unless parent.inventory?
|
57
|
-
parent
|
73
|
+
parent
|
74
|
+
end
|
75
|
+
end
|
58
76
|
end
|
59
77
|
end
|
60
78
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
## Bcome's kubernetes node namespaces
|
4
|
+
module Bcome::Node
|
5
|
+
module Kube
|
6
|
+
class Base
|
7
|
+
attr_reader :resources
|
8
|
+
|
9
|
+
def initialize(kube_wrap, config = {})
|
10
|
+
@kube_wrap = kube_wrap
|
11
|
+
@config = config
|
12
|
+
@resources = []
|
13
|
+
end
|
14
|
+
|
15
|
+
def parent
|
16
|
+
@config[:parent]
|
17
|
+
end
|
18
|
+
|
19
|
+
def run(command)
|
20
|
+
@kube_wrap.run(command)
|
21
|
+
end
|
22
|
+
|
23
|
+
def build
|
24
|
+
child_node_lookup_result = run(get_child_node_command)
|
25
|
+
parse(child_node_lookup_result)
|
26
|
+
end
|
27
|
+
|
28
|
+
def parse(child_node_lookup_result)
|
29
|
+
# Get the output
|
30
|
+
output = child_node_lookup_result.stdout
|
31
|
+
# Remove the title & form array
|
32
|
+
data = output.remove_lines(1).split("\n")
|
33
|
+
|
34
|
+
structured_data = {}
|
35
|
+
data.each do |raw_namespace_line|
|
36
|
+
child_config = get_child_config_from_line(raw_namespace_line)
|
37
|
+
child_config.merge!(parent: self)
|
38
|
+
@resources << child_node_klass.new(@kube_wrap, child_config)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def get_child_node_command
|
43
|
+
raise 'should be overriden'
|
44
|
+
end
|
45
|
+
|
46
|
+
def get_child_config_from_line(*_params)
|
47
|
+
raise 'should be overidden'
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bcome::Node::Kube
|
4
|
+
class Estate < Bcome::Node::Kube::Base
|
5
|
+
# CONTAINS NAMESPACES
|
6
|
+
def get_child_node_command
|
7
|
+
'get namespaces'
|
8
|
+
end
|
9
|
+
|
10
|
+
def child_node_klass
|
11
|
+
::Bcome::Kube::Node::Namespace
|
12
|
+
end
|
13
|
+
|
14
|
+
def get_child_config_from_line(raw_line)
|
15
|
+
name, active, age = raw_line.split("\s")
|
16
|
+
{ name: name, active: active, age: age }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bcome::Node::Kube
|
4
|
+
class Namespace < Bcome::Node::Kube::Base
|
5
|
+
# CONTAINS PODS
|
6
|
+
|
7
|
+
def get_child_node_command
|
8
|
+
"get pods -n #{name}"
|
9
|
+
end
|
10
|
+
|
11
|
+
def child_node_klass
|
12
|
+
::Bcome::Kube::Node::Pod
|
13
|
+
end
|
14
|
+
|
15
|
+
def get_child_config_from_line(raw_line)
|
16
|
+
name, ready, status, restarts, age = raw_line.split("\s")
|
17
|
+
{ name: name, ready: ready, status: status, reastarts: restarts, age: age }
|
18
|
+
end
|
19
|
+
|
20
|
+
def name
|
21
|
+
@config[:name]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bcome::Node::Kube
|
4
|
+
class Pod < Bcome::Node::Kube::Base
|
5
|
+
# CONTAINS CONTAINERS
|
6
|
+
|
7
|
+
def get_child_node_command
|
8
|
+
"get pods #{name} -n #{parent.name} -o jsonpath=‘{.spec.containers[*].name}’"
|
9
|
+
end
|
10
|
+
|
11
|
+
def child_node_klass
|
12
|
+
::Bcome::Kube::Node::Container
|
13
|
+
end
|
14
|
+
|
15
|
+
def name
|
16
|
+
@config[:name]
|
17
|
+
end
|
18
|
+
|
19
|
+
def get_child_config_from_line(raw_line)
|
20
|
+
name = raw_line.split("\s")
|
21
|
+
{ name: name }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
## Kubectl command wrapper. This will integrate directly with bcome's GCP authentication driver
|
4
|
+
class KubeWrap
|
5
|
+
KUBE_BIN = 'kubectl'
|
6
|
+
|
7
|
+
def initialize(access_token)
|
8
|
+
@access_token = access_token
|
9
|
+
end
|
10
|
+
|
11
|
+
def run(command_suffix)
|
12
|
+
full_command = create_command_for(command_suffix)
|
13
|
+
result = ::Bcome::Command::Local.run(full_command)
|
14
|
+
|
15
|
+
if result.failed?
|
16
|
+
puts "\n" + result.stderr.error + "\n"
|
17
|
+
raise
|
18
|
+
end
|
19
|
+
|
20
|
+
result
|
21
|
+
end
|
22
|
+
|
23
|
+
def create_command_for(suffix)
|
24
|
+
"#{KUBE_BIN} --token #{@access_token} #{suffix}"
|
25
|
+
end
|
26
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Bcome::Node::Meta
|
2
4
|
class Base
|
3
5
|
attr_reader :data
|
@@ -10,11 +12,16 @@ module Bcome::Node::Meta
|
|
10
12
|
matchers[:values] = [matchers[:values]] if matchers[:values] && !matchers[:values].is_a?(Array)
|
11
13
|
|
12
14
|
raise Bcome::Exception::InvalidMatcherQuery unless matchers[:key] && matchers[:values].is_a?(Array)
|
15
|
+
|
13
16
|
key = matchers[:key].to_sym
|
14
17
|
values = matchers[:values]
|
15
18
|
@data.key?(key) && values.include?(@data[key])
|
16
19
|
end
|
17
20
|
|
21
|
+
def keys
|
22
|
+
@data.keys
|
23
|
+
end
|
24
|
+
|
18
25
|
def dump
|
19
26
|
@data.each do |k, v|
|
20
27
|
puts "#{k} => #{v.resource_value}"
|
@@ -29,7 +36,7 @@ module Bcome::Node::Meta
|
|
29
36
|
if @data.key?(key)
|
30
37
|
@data[key]
|
31
38
|
elsif default
|
32
|
-
|
39
|
+
default
|
33
40
|
else
|
34
41
|
raise Bcome::Exception::CantFindKeyInMetadata, key unless @data.key?(key)
|
35
42
|
end
|
@@ -1,65 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Bcome::Node
|
2
4
|
class MetaDataLoader
|
3
5
|
include ::Singleton
|
4
6
|
|
5
|
-
META_DATA_FILE_PATH_PREFIX = 'bcome/metadata'
|
7
|
+
META_DATA_FILE_PATH_PREFIX = 'bcome/metadata'
|
6
8
|
|
7
9
|
def initialize
|
8
10
|
@all_metadata_filenames = Dir["#{META_DATA_FILE_PATH_PREFIX}/*"]
|
9
11
|
end
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
-
end
|
14
|
-
|
13
|
+
attr_accessor :decryption_key
|
14
|
+
|
15
15
|
def data
|
16
16
|
@data ||= do_load
|
17
17
|
end
|
18
18
|
|
19
19
|
def data_for_namespace(namespace)
|
20
|
-
static_data = data[namespace.to_sym]
|
20
|
+
static_data = data[namespace.to_sym] || {}
|
21
21
|
static_data.merge(terraform_data_for_namespace(namespace))
|
22
22
|
end
|
23
23
|
|
24
24
|
def terraform_data_for_namespace(namespace)
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
parser = Bcome::Terraform::Parser.new(namespace)
|
29
|
-
attributes = parser.attributes
|
30
|
-
|
25
|
+
# Radical departure II - all we care is the outputs. This will then work across any terraform backend, and any version
|
26
|
+
tf_state = ::Bcome::Terraform::Output.new(namespace)
|
31
27
|
terraform_data = {}
|
32
|
-
|
33
|
-
if attributes.keys.any?
|
34
|
-
## 1. Keep the old broken implementation
|
35
|
-
terraform_data["terraform_attributes"] = attributes if attributes.keys.any?
|
36
|
-
## 2. But make all the data accessible
|
37
|
-
terraform_data["tf_state"] = parser.state.config
|
38
|
-
end
|
39
|
-
|
28
|
+
terraform_data['terraform_outputs'] = tf_state.output
|
40
29
|
terraform_data
|
41
30
|
end
|
42
31
|
|
43
32
|
def prompt_for_decryption_key
|
44
|
-
|
33
|
+
decryption_key_prompt = 'Enter your metadata decryption key: '.informational
|
34
|
+
|
35
|
+
print "\n#{decryption_key_prompt}"
|
45
36
|
@decryption_key = STDIN.noecho(&:gets).chomp
|
37
|
+
print "\r#{decryption_key_prompt}" + "**********\n\n"
|
46
38
|
end
|
47
39
|
|
48
40
|
def load_file_data_for(filepath)
|
49
|
-
|
41
|
+
if filepath =~ /.enc/ # encrypted file contents
|
50
42
|
prompt_for_decryption_key unless decryption_key
|
51
|
-
encrypted_contents = File.read(filepath)
|
52
|
-
decrypted_contents = encrypted_contents.decrypt(decryption_key)
|
53
|
-
|
43
|
+
encrypted_contents = File.read(filepath)
|
44
|
+
decrypted_contents = encrypted_contents.decrypt(decryption_key)
|
45
|
+
|
46
|
+
begin
|
47
|
+
YAML.safe_load(decrypted_contents, [Symbol], [], true)
|
48
|
+
rescue Exception => e
|
49
|
+
@decryption_key = nil
|
50
|
+
raise ::Bcome::Exception::InvalidMetaDataConfig, "#{e.class} #{e.message} - " + decrypted_contents
|
51
|
+
end
|
52
|
+
|
54
53
|
else # unencrypted
|
55
|
-
|
54
|
+
YAML.load_file(filepath)
|
56
55
|
end
|
57
56
|
end
|
58
57
|
|
59
58
|
def do_load
|
60
59
|
all_meta_data = {}
|
61
60
|
@all_metadata_filenames.each do |filepath|
|
62
|
-
next if filepath =~ /-unenc/
|
61
|
+
next if filepath =~ /-unenc/ # we only read from the encrypted, packed files.
|
63
62
|
|
64
63
|
begin
|
65
64
|
filedata = load_file_data_for(filepath)
|
@@ -68,7 +67,7 @@ module Bcome::Node
|
|
68
67
|
raise Bcome::Exception::InvalidMetaDataConfig, "Error: #{e.message}"
|
69
68
|
end
|
70
69
|
end
|
71
|
-
|
70
|
+
all_meta_data
|
72
71
|
end
|
73
72
|
end
|
74
73
|
end
|