diff --git a/.gitignore b/.gitignore index 3f1551212..766ada3a7 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,7 @@ /spec/fixtures/modules/* /tmp/ /vendor/ +/.vendor/ /convert_report.txt /update_report.txt .DS_Store diff --git a/lib/puppet/functions/stdlib/parsehocon.rb b/lib/puppet/functions/stdlib/parsehocon.rb index 159028f99..84d48ef12 100644 --- a/lib/puppet/functions/stdlib/parsehocon.rb +++ b/lib/puppet/functions/stdlib/parsehocon.rb @@ -4,6 +4,10 @@ # This function accepts HOCON as a string and converts it into the correct # Puppet structure # +# @param hocon_string can be an actual string of data or a path to a Hocon config file +# +# @param default content that will be returned in case the string isn't parseable +# # @example How to parse hocon # $data = stdlib::parsehocon("{any valid hocon: string}") # @@ -17,16 +21,18 @@ end def parsehocon(hocon_string, default = :no_default_provided) - require 'hocon/config_factory' - - begin + if File.exist? hocon_string + require 'hocon' + Hocon.load(hocon_string) + else + require 'hocon/config_factory' data = Hocon::ConfigFactory.parse_string(hocon_string) data.resolve.root.unwrapped - rescue Hocon::ConfigError::ConfigParseError => e - Puppet.debug("Parsing hocon failed with error: #{e.message}") - raise e if default == :no_default_provided - - default end + rescue Hocon::ConfigError::ConfigParseError => e + Puppet.debug("Parsing hocon failed with error: #{e.message}") + raise e if default == :no_default_provided + + default end end