Browse files

Added code to the RazorMkHardwareFacter class to remove any "offendin…

…g keys" from the key-value pairs that are passed back to Razor. We use the phrase "offending keys" here to refer to any keys that include characters from the following character set: [!@#\$%\^&*()=+\[\]\{\}]

Any "offending key" will be replace by a "cleansed key" (one with the offending characters removed) before the facts_map is passed back to the caller of the "RazorMicrokernel::RzMkHardwareFacter::add_facts_to_map!()" method, and the value that was stored under the old (offending) key will be stored under a new (cleansed) key instead (the old key-value pair will be removed as part of this operation).  With this change in place, we shouldn't have to worry about passing a facts_map with any offending keys to the Razor server (since none of the facts we gather using Facter have "offending keys", just those we've added using this RzMkHardwareFacter class).
  • Loading branch information...
Tom McSweeney
Tom McSweeney committed May 2, 2012
1 parent b6945e9 commit 8b2e41ce679d071c7f4fea7206a7a330d7b453f4
Showing with 24 additions and 0 deletions.
  1. +24 −0 razor_microkernel/rz_mk_hardware_facter.rb
@@ -115,7 +115,13 @@ def add_facts_to_map!(facts_map, mk_fct_excl_pattern)
rescue => e
# finally, sweep through the facts_map and remove any offending keys
# (remapping those values to new keys that don't contain any offending
# characters)
@@ -429,5 +435,23 @@ def parse_array_value_set(parse_array, start_idx)
[current_idx, output_array]
# this method cleans up the keys in the input fact_map so that they don't include
# any characters that could cause problems later on...i.e. any characters from following
# string: "!@#\$%\^&*()=+\[\]\{\}"
def clean_fact_map_keys!(facts_map)
facts_map.each { |key|
# search each key to see if there any offending characters
# (if so, we'll refer to the key as an "offending key", below)
if /[!@#\$%\^&*()=+\[\]\{\}]/ =~ key
# if there is a match, then we'll create a new entry in the map using a
# "cleansed" key (i.e. a key with all of the offending characters removed),
# store the old value under the new key, and and remove the old key-value pair
# that stored the same data under the offending key
facts_map[key.gsub(/[!@#\$%\^&*()=+\[\]\{\}]/,"")] = facts_map[key]

0 comments on commit 8b2e41c

Please sign in to comment.