Class: Bcome::Node::MetaDataLoader
- Inherits:
-
Object
- Object
- Bcome::Node::MetaDataLoader
- Includes:
- Singleton
- Defined in:
- lib/objects/node/meta_data_loader.rb
Constant Summary collapse
- META_DATA_FILE_PATH_PREFIX =
'bcome/metadata'.freeze
Instance Method Summary collapse
- #data ⇒ Object
- #data_for_namespace(namespace) ⇒ Object
- #decryption_key ⇒ Object
- #do_load ⇒ Object
-
#initialize ⇒ MetaDataLoader
constructor
A new instance of MetaDataLoader.
- #load_file_data_for(filepath) ⇒ Object
- #prompt_for_decryption_key ⇒ Object
- #terraform_data_for_namespace(namespace) ⇒ Object
Constructor Details
#initialize ⇒ MetaDataLoader
Returns a new instance of MetaDataLoader.
7 8 9 |
# File 'lib/objects/node/meta_data_loader.rb', line 7 def initialize @all_metadata_filenames = Dir["#{META_DATA_FILE_PATH_PREFIX}/*"] end |
Instance Method Details
#data ⇒ Object
15 16 17 |
# File 'lib/objects/node/meta_data_loader.rb', line 15 def data @data ||= do_load end |
#data_for_namespace(namespace) ⇒ Object
19 20 21 22 |
# File 'lib/objects/node/meta_data_loader.rb', line 19 def data_for_namespace(namespace) static_data = data[namespace.to_sym] ? data[namespace.to_sym] : {} static_data.merge(terraform_data_for_namespace(namespace)) end |
#decryption_key ⇒ Object
11 12 13 |
# File 'lib/objects/node/meta_data_loader.rb', line 11 def decryption_key @decryption_key end |
#do_load ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/objects/node/meta_data_loader.rb', line 52 def do_load = {} @all_metadata_filenames.each do |filepath| next if filepath =~ /-unenc/ # we only read from the encrypted, packed files. begin filedata = load_file_data_for(filepath) .deep_merge!(filedata) rescue Psych::SyntaxError => e raise Bcome::Exception::InvalidMetaDataConfig, "Error: #{e.}" end end return end |
#load_file_data_for(filepath) ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/objects/node/meta_data_loader.rb', line 41 def load_file_data_for(filepath) if filepath =~ /.enc/ # encrypted file contents prompt_for_decryption_key unless decryption_key encrypted_contents = File.read(filepath) decrypted_contents = encrypted_contents.decrypt(decryption_key) return YAML.load(decrypted_contents) else # unencrypted return YAML.load_file(filepath) end end |
#prompt_for_decryption_key ⇒ Object
36 37 38 39 |
# File 'lib/objects/node/meta_data_loader.rb', line 36 def prompt_for_decryption_key print "\nEnter your decryption key: ".informational @decryption_key = STDIN.noecho(&:gets).chomp end |
#terraform_data_for_namespace(namespace) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/objects/node/meta_data_loader.rb', line 24 def terraform_data_for_namespace(namespace) parser = Bcome::Terraform::Parser.new(namespace) attributes = parser.attributes if attributes.keys.any? { "terraform_attributes" => attributes } else {} end end |