lib/hiera/backend/mysql2_backend.rb in hiera-mysql-backend-0.0.1 vs lib/hiera/backend/mysql2_backend.rb in hiera-mysql-backend-0.0.2
- old
+ new
@@ -15,12 +15,13 @@
Hiera.debug("Hiera MySQL2 initialized")
end
def lookup(key, scope, order_override, resolution_type)
# default answer just to make it easier on ourselves
+ results = nil
- Hiera.debug("looking up %{key} in MySQL Backend")
+ Hiera.debug("looking up #{key} in MySQL2 Backend")
Hiera.debug("resolution type is #{resolution_type}")
Backend.datasources(scope, order_override) do |source|
Hiera.debug("Looking for data source #{source}")
sqlfile = Backend.datafile(:mysql2, scope, source, "sql") || next
@@ -28,25 +29,27 @@
next unless File.exist?(sqlfile)
data = @cache.read(sqlfile, Hash, {}) do |datafile|
YAML.load(datafile)
end
+ Hiera.debug("data #{data.inspect}")
next if data.empty?
next unless data.include?(key)
Hiera.debug("Found #{key} in #{source}")
new_answer = Backend.parse_answer(data[key], scope)
results = query(new_answer)
- return results
+
end
+ return results
end
def query(query)
Hiera.debug("Executing SQL Query: #{query}")
- data=[]
+ data=nil
mysql_host = Config[:mysql2][:host]
mysql_user = Config[:mysql2][:user]
mysql_pass = Config[:mysql2][:pass]
mysql_database = Config[:mysql2][:database]
client = Mysql2::Client.new(:host => mysql_host,