Class: Ufo::DSL::Helper::Vars
- Inherits:
-
Object
- Object
- Ufo::DSL::Helper::Vars
- Extended by:
- Memoist
- Defined in:
- lib/ufo/dsl/helper/vars.rb
Instance Method Summary collapse
- #account ⇒ Object
- #aws_data ⇒ Object
- #content ⇒ Object
- #env ⇒ Object
- #expand_secret(value) ⇒ Object
- #filtered_lines(content) ⇒ Object
-
#initialize(options = {}) ⇒ Vars
constructor
A new instance of Vars.
- #read(path) ⇒ Object
- #region ⇒ Object
- #remove_surrounding_quotes(s) ⇒ Object
- #secrets ⇒ Object
- #substitute(value) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Vars
Returns a new instance of Vars.
7 8 9 10 11 |
# File 'lib/ufo/dsl/helper/vars.rb', line 7 def initialize(={}) # use either file or text. text takes higher precedence @file = [:file] @text = [:text] end |
Instance Method Details
#account ⇒ Object
93 94 95 |
# File 'lib/ufo/dsl/helper/vars.rb', line 93 def account aws_data.account end |
#aws_data ⇒ Object
84 85 86 |
# File 'lib/ufo/dsl/helper/vars.rb', line 84 def aws_data AwsData.new end |
#content ⇒ Object
13 14 15 |
# File 'lib/ufo/dsl/helper/vars.rb', line 13 def content @text || read(@file) end |
#env ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# 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) ⇒ Object
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/ufo/dsl/helper/vars.rb', line 49 def (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) ⇒ Object
74 75 76 77 78 79 80 81 82 |
# 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) ⇒ Object
17 18 19 20 21 22 23 24 |
# 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 ⇒ Object
89 90 91 |
# File 'lib/ufo/dsl/helper/vars.rb', line 89 def region aws_data.region end |
#remove_surrounding_quotes(s) ⇒ Object
64 65 66 67 68 69 70 71 72 |
# 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 ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/ufo/dsl/helper/vars.rb', line 40 def secrets secrets = env secrets.map do |item| value = item.delete(:value) item[:valueFrom] = substitute((value)) end secrets end |