class Yamload::Loading::Yaml
Public Class Methods
new(file, dir)
click to toggle source
# File lib/yamload/loading/yaml.rb, line 7 def initialize(file, dir) @file = file @dir = dir end
Public Instance Methods
content()
click to toggle source
# File lib/yamload/loading/yaml.rb, line 16 def content @content ||= IceNine.deep_freeze(load) end
exist?()
click to toggle source
# File lib/yamload/loading/yaml.rb, line 12 def exist? File.exist?(filepath) end
reload()
click to toggle source
# File lib/yamload/loading/yaml.rb, line 20 def reload @content = @immutable_obj = nil content end
Private Instance Methods
erb_parsed_content()
click to toggle source
# File lib/yamload/loading/yaml.rb, line 34 def erb_parsed_content raw_content = File.read(filepath, encoding: 'bom|utf-8', mode: 'r') ERB.new(raw_content).result(binding) end
filepath()
click to toggle source
# File lib/yamload/loading/yaml.rb, line 39 def filepath fail IOError, 'No yml files directory specified' if @dir.nil? fail IOError, "#{@dir} is not a valid directory" unless File.directory?(@dir) File.join(@dir, "#{@file}.yml") end
get_parameter(key, encrypted: true)
click to toggle source
# File lib/yamload/loading/yaml.rb, line 61 def get_parameter(key, encrypted: true) ssm_client.get_parameter( name: key, with_decryption: encrypted ).parameter.value rescue Aws::SSM::Errors::ParameterNotFound => e puts "Parameter #{key} not found" raise e end
get_secret(key)
click to toggle source
# File lib/yamload/loading/yaml.rb, line 51 def get_secret(key) secrets_client.get_secret_value(secret_id: key).secret_string end
load()
click to toggle source
# File lib/yamload/loading/yaml.rb, line 27 def load fail IOError, "#{@file}.yml could not be found" unless exist? YAML.load(erb_parsed_content).tap do |content| fail IOError, "#{@file}.yml is blank" if content.blank? end end
secrets_client()
click to toggle source
# File lib/yamload/loading/yaml.rb, line 45 def secrets_client options = {} options[:endpoint] = ENV['AWS_SECRETS_MANAGER_ENDPOINT'] if ENV.has_key?('AWS_SECRETS_MANAGER_ENDPOINT') @secrets_client ||= Aws::SecretsManager::Client.new(options) end
ssm_client()
click to toggle source
# File lib/yamload/loading/yaml.rb, line 55 def ssm_client options = {} options[:endpoint] = ENV['AWS_SSM_ENDPOINT'] if ENV.has_key?('AWS_SSM_ENDPOINT') @ssm_client ||= Aws::SSM::Client.new(options) end