Skip to content

Commit

Permalink
(CONT-801) Deprecate parsepson.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasAud committed May 23, 2023
1 parent 55c4aea commit c0c7ccb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/puppet/functions/parsepson.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

# @summary
# **Deprecated:** Starting Puppet 8, we no longer natively support PSON usage. This function should be removed once we stop supporting Puppet 7.
#
# This function accepts PSON, a Puppet variant of JSON, as a string and converts
# it into the correct Puppet structure
#
Expand All @@ -20,7 +22,9 @@
end

def parsepson(pson_string, default = :no_default_provided)
PSON.load(pson_string)
call_function('deprecation', 'parsepson', 'This method is deprecated. From Puppet 8, PSON is no longer natively supported. Please use JSON.parse().')

PSON.load(pson_string) if Puppet::Util::Package.versioncmp(Puppet.version, '8').negative?
rescue StandardError => e
Puppet.debug("Parsing PSON failed with error: #{e.message}")
raise e if default == :no_default_provided
Expand Down
5 changes: 5 additions & 0 deletions spec/functions/parsepson_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,9 @@
end
end
end
if Puppet::Util::Package.versioncmp(Puppet.version, '8.0.0').positive?
it 'doesnt work on Puppet 8' do
expect(subject).to run.with_params('{"a":"1","b":"2"}').and_return(nil)
end
end
end

0 comments on commit c0c7ccb

Please sign in to comment.