Commit 646b4938 authored by Rich's avatar Rich
Browse files

Seperate variables from identifiers

parent 039861a7
......@@ -3,7 +3,7 @@
_gemname=terraform-wrapper
pkgname=ruby-${_gemname}
pkgver=1.1.0
pkgver=1.2.0
pkgrel=1
pkgdesc="A ruby wrapper for managing Terraform binaries and remote state."
arch=(any)
......
......@@ -36,11 +36,11 @@ module TerraformWrapper
@core[:config] = config
@core[:service] = service
user = cleanse(variables: identifiers, reserved: @core.keys)
user = cleanse(variables: identifiers, reserved: @core.keys, downcase: true)
merged = @core.merge(user)
@identifiers = sort ? merged.sort.to_h : merged
@values = @identifiers
@values = Hash.new
@files = Array.new
end
......@@ -89,7 +89,7 @@ module TerraformWrapper
###############################################################################
def clear_variables()
@values = @identifers
@values = Hash.new
end
###############################################################################
......@@ -98,17 +98,20 @@ module TerraformWrapper
###############################################################################
def cleanse(variables:, reserved:)
def cleanse(variables:, reserved:, downcase: false)
result = Hash.new
variables.keys.each do |key|
logger.fatal("Could not clean variables hash. All keys MUST be strings!") unless key.kind_of?(String)
logger.fatal("Could not clean variables hash, key: #{key.downcase} is reserved or already in use and cannot be used!") if reserved.include?(key.downcase.to_sym)
logger.fatal("Could not clean variables hash, duplicate key found: #{key.downcase}!") if result.key?(key.downcase.to_sym)
logger.fatal("Could not clean variables hash, value for: #{key.downcase} is not a string!") unless variables[key].kind_of?(String)
logger.fatal("Could not clean variables hash, value for: #{key.downcase} is empty!") if variables[key].strip.empty?
result[key.downcase.to_sym] = variables[key].strip
sym = downcase ? key.downcase.to_sym : key.to_sym
logger.fatal("Could not clean variables hash, key: #{sym.to_s} is reserved or already in use and cannot be used!") if reserved.include?(sym)
logger.fatal("Could not clean variables hash, duplicate key found: #{sym.to_s}!") if result.key?(sym)
logger.fatal("Could not clean variables hash, value for: #{sym.to_s} is not a string!") unless variables[key].kind_of?(String)
logger.fatal("Could not clean variables hash, value for: #{sym.to_s} is empty!") if variables[key].strip.empty?
result[sym] = variables[key].strip
end
return result
......
......@@ -4,7 +4,7 @@ module TerraformWrapper
###############################################################################
VERSION = "1.1.0"
VERSION = "1.2.0"
###############################################################################
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment