From d39f63f2df20c5536255d8302a752565cfec404d Mon Sep 17 00:00:00 2001 From: David Roetzel Date: Fri, 16 Feb 2024 09:58:36 +0100 Subject: [PATCH 1/2] Convert hash keys to strings #293 Rails automatically converts keys to symbols, but this is not standard behavior of the YAML parser, so we had a mismatch here. --- app/models/hiera_data/hierarchy.rb | 2 +- test/fixtures/files/puppet/environments/eyaml/hiera.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/hiera_data/hierarchy.rb b/app/models/hiera_data/hierarchy.rb index d532dc20..f67d3c48 100644 --- a/app/models/hiera_data/hierarchy.rb +++ b/app/models/hiera_data/hierarchy.rb @@ -99,7 +99,7 @@ def determine_backend value = raw_hash[lookup_function] backends = BACKENDS custom_mappings = Rails.configuration.hdm[:custom_lookup_function_mapping] - backends = backends.deep_merge({ "lookup_key" => custom_mappings }) if custom_mappings.present? + backends = backends.deep_merge({ "lookup_key" => custom_mappings.stringify_keys }) if custom_mappings.present? backends.fetch(key).fetch(value).to_sym rescue KeyError raise Hdm::Error, "unknown backend #{value}" diff --git a/test/fixtures/files/puppet/environments/eyaml/hiera.yaml b/test/fixtures/files/puppet/environments/eyaml/hiera.yaml index fdfaf392..8b40c084 100644 --- a/test/fixtures/files/puppet/environments/eyaml/hiera.yaml +++ b/test/fixtures/files/puppet/environments/eyaml/hiera.yaml @@ -1,7 +1,7 @@ version: 5 defaults: datadir: data - lookup_key: eyaml_lookup_key + lookup_key: custom_eyaml_function options: pkcs7_private_key: keys/private_key.pkcs7.pem pkcs7_public_key: keys/public_key.pkcs7.pem From 048e2081bb93cbd35cdf27ab7b5970c9edbd867d Mon Sep 17 00:00:00 2001 From: David Roetzel Date: Fri, 16 Feb 2024 10:07:12 +0100 Subject: [PATCH 2/2] Fix mixup #293 I wanted to revert my temporary changes to test data and accidentally reverted the adjusted test for the previous commit. This commit resolves that mixup. --- test/fixtures/files/puppet/environments/eyaml/hiera.yaml | 2 +- test/models/hiera_data/hierarchy_test.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/fixtures/files/puppet/environments/eyaml/hiera.yaml b/test/fixtures/files/puppet/environments/eyaml/hiera.yaml index 8b40c084..fdfaf392 100644 --- a/test/fixtures/files/puppet/environments/eyaml/hiera.yaml +++ b/test/fixtures/files/puppet/environments/eyaml/hiera.yaml @@ -1,7 +1,7 @@ version: 5 defaults: datadir: data - lookup_key: custom_eyaml_function + lookup_key: eyaml_lookup_key options: pkcs7_private_key: keys/private_key.pkcs7.pem pkcs7_public_key: keys/public_key.pkcs7.pem diff --git a/test/models/hiera_data/hierarchy_test.rb b/test/models/hiera_data/hierarchy_test.rb index 84ce0cd6..253c063f 100644 --- a/test/models/hiera_data/hierarchy_test.rb +++ b/test/models/hiera_data/hierarchy_test.rb @@ -234,7 +234,7 @@ class HierarchyForCustomBackend < ActiveSupport::TestCase test "custom lookup function mapped to eyaml" do Rails.configuration.hdm[:custom_lookup_function_mapping] = { - "custom_eyaml_function" => "eyaml" + custom_eyaml_function: "eyaml" } hierarchy = HieraData::Hierarchy.new(raw_hash:, base_path: ".") assert_equal :eyaml, hierarchy.backend