class Ufo::DSL::Helper::Vars
Public Class Methods
new(options={})
click to toggle source
# File lib/ufo/dsl/helper/vars.rb, line 7 def initialize(options={}) # use either file or text. text takes higher precedence @file = options[:file] @text = options[:text] end
Public Instance Methods
account()
click to toggle source
# File lib/ufo/dsl/helper/vars.rb, line 93 def account aws_data.account end
aws_data()
click to toggle source
# File lib/ufo/dsl/helper/vars.rb, line 84 def aws_data AwsData.new end
content()
click to toggle source
# File lib/ufo/dsl/helper/vars.rb, line 13 def content @text || read(@file) end
env()
click to toggle source
# File lib/ufo/dsl/helper/vars.rb, line 26 def env lines = filtered_lines(content) lines.map do |line| key,*value = line.strip.split("=").map do |x| remove_surrounding_quotes(x.strip) end value = value.join('=') { name: key, value: value, } end end
expand_secret(value)
click to toggle source
# File lib/ufo/dsl/helper/vars.rb, line 49 def expand_secret(value) case value when /^ssm:/i value.sub(/^ssm:/i, "arn:aws:ssm:#{region}:#{account}:parameter/") when /^secretsmanager:/i value.sub(/^secretsmanager:/i, "arn:aws:secretsmanager:#{region}:#{account}:secret:") else value # assume full arn has been passed end end
filtered_lines(content)
click to toggle source
# File lib/ufo/dsl/helper/vars.rb, line 74 def filtered_lines(content) lines = content.split("\n") # remove comment at the end of the line lines.map! { |l| l.sub(/\s+#.*/,'').strip } # filter out commented lines lines = lines.reject { |l| l =~ /(^|\s)#/i } # filter out empty lines lines = lines.reject { |l| l.strip.empty? } end
read(path)
click to toggle source
# File lib/ufo/dsl/helper/vars.rb, line 17 def read(path) full_path = "#{Ufo.root}/#{path}" unless File.exist?(full_path) puts "The #{full_path} env file could not be found. Are you sure it exists?" exit 1 end IO.read(full_path) end
region()
click to toggle source
# File lib/ufo/dsl/helper/vars.rb, line 89 def region aws_data.region end
remove_surrounding_quotes(s)
click to toggle source
# File lib/ufo/dsl/helper/vars.rb, line 64 def remove_surrounding_quotes(s) if s =~ /^"/ && s =~ /"$/ s.sub(/^["]/, '').gsub(/["]$/,'') # remove surrounding double quotes elsif s =~ /^'/ && s =~ /'$/ s.sub(/^[']/, '').gsub(/[']$/,'') # remove surrounding single quotes else s end end
secrets()
click to toggle source
# File lib/ufo/dsl/helper/vars.rb, line 40 def secrets secrets = env secrets.map do |item| value = item.delete(:value) item[:valueFrom] = substitute(expand_secret(value)) end secrets end
substitute(value)
click to toggle source
# File lib/ufo/dsl/helper/vars.rb, line 60 def substitute(value) value.gsub(":UFO_ENV", Ufo.env) end