From affa07017c264277eddd7b6dc38b20ecfb863fae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Pinson?= Date: Fri, 29 May 2020 15:02:51 +0200 Subject: [PATCH] Remove regexpi logic, Augeas 1.0.0 was released 8 years ago (#60) --- lib/puppet/provider/ssh_config/augeas.rb | 7 +----- lib/puppet/provider/sshd_config/augeas.rb | 10 ++------ .../provider/sshd_config_match/augeas.rb | 24 ++++--------------- .../provider/sshd_config_subsystem/augeas.rb | 12 ++-------- .../puppet/provider/ssh_config/augeas_spec.rb | 20 +--------------- .../provider/sshd_config/augeas_spec.rb | 22 ++--------------- 6 files changed, 13 insertions(+), 82 deletions(-) diff --git a/lib/puppet/provider/ssh_config/augeas.rb b/lib/puppet/provider/ssh_config/augeas.rb index 4936a5c..d41a88c 100644 --- a/lib/puppet/provider/ssh_config/augeas.rb +++ b/lib/puppet/provider/ssh_config/augeas.rb @@ -18,12 +18,7 @@ resource_path do |resource| base = self.base_path(resource) key = resource[:key] ? resource[:key] : resource[:name] - if supported?(:regexpi) - "#{base}/*[label()=~regexp('#{key}', 'i')]" - else - debug "Warning: Augeas >= 1.0.0 is required for case-insensitive support in ssh_config resources" - "#{base}/#{key}" - end + "#{base}/*[label()=~regexp('#{key}', 'i')]" end def self.base_path(resource) diff --git a/lib/puppet/provider/sshd_config/augeas.rb b/lib/puppet/provider/sshd_config/augeas.rb index a5651d0..5c3be82 100644 --- a/lib/puppet/provider/sshd_config/augeas.rb +++ b/lib/puppet/provider/sshd_config/augeas.rb @@ -17,12 +17,7 @@ resource_path do |resource| base = self.base_path(resource) key = resource[:key] ? resource[:key] : resource[:name] - if supported?(:regexpi) - "#{base}/*[label()=~regexp('#{key}', 'i')]" - else - debug "Warning: Augeas >= 1.0.0 is required for case-insensitive support in sshd_config resources" - "#{base}/#{key}" - end + "#{base}/*[label()=~regexp('#{key}', 'i')]" end def self.base_path(resource) @@ -90,8 +85,7 @@ def self.set_value(aug, base, path, label, value) aug.set("#{path}[last()]", v) else # Prefer to create the node next to a commented out entry - reg_flag = supported?(:regexpi) ? ", 'i'" : '' - commented = aug.match("#{base}/#comment[.=~regexp('#{label}([^a-z\.].*)?'#{reg_flag})]") + commented = aug.match("#{base}/#comment[.=~regexp('#{label}([^a-z\.].*)?', 'i')]") if commented.empty? if aug.match("#{base}/Match").empty? # insert as the last line diff --git a/lib/puppet/provider/sshd_config_match/augeas.rb b/lib/puppet/provider/sshd_config_match/augeas.rb index ce49ec1..e772269 100644 --- a/lib/puppet/provider/sshd_config_match/augeas.rb +++ b/lib/puppet/provider/sshd_config_match/augeas.rb @@ -14,14 +14,6 @@ confine :feature => :augeas - def self.regexpi_path(resource) - path = "$target/*[label()=~regexp('match', 'i') and *[label()=~regexp('condition', 'i') and count(*)=#{resource[:condition].keys.size}]" - resource[:condition].each do |c, v| - path += "[*[label()=~regexp('#{c}', 'i')]='#{v}']" - end - path += "]" - end - def self.static_path(resource) path = "$target/Match[count(Condition/*)=#{resource[:condition].keys.size}]" resource[:condition].each do |c, v| @@ -31,13 +23,11 @@ def self.static_path(resource) end def self.path(resource) - if supported?(:regexpi) - self.regexpi_path(resource) - else - debug "Warning: Augeas >= 1.0.0 is required for case-insensitive support in ssh_config resources" - # TODO: test this? - self.static_path(resource) + path = "$target/*[label()=~regexp('match', 'i') and *[label()=~regexp('condition', 'i') and count(*)=#{resource[:condition].keys.size}]" + resource[:condition].each do |c, v| + path += "[*[label()=~regexp('#{c}', 'i')]='#{v}']" end + path += "]" end resource_path do |resource| @@ -47,11 +37,7 @@ def self.path(resource) def self.instances augopen do |aug,path| resources = [] - if supported?(:regexpi) - search_path = "$target/*[label()=~regexp('match', 'i')]/*[label()=~regexp('condition', 'i')]" - else - search_path = "$target/Match/Condition" - end + search_path = "$target/*[label()=~regexp('match', 'i')]/*[label()=~regexp('condition', 'i')]" aug.match("#{search_path}").each do |hpath| conditions = [] diff --git a/lib/puppet/provider/sshd_config_subsystem/augeas.rb b/lib/puppet/provider/sshd_config_subsystem/augeas.rb index 844cc1a..2b4825d 100644 --- a/lib/puppet/provider/sshd_config_subsystem/augeas.rb +++ b/lib/puppet/provider/sshd_config_subsystem/augeas.rb @@ -15,11 +15,7 @@ confine :feature => :augeas resource_path do |resource| - if supported?(:regexpi) - "$target/*[label()=~regexp('Subsystem', 'i')]/#{resource[:name]}" - else - "$target/Subsystem/#{resource[:name]}" - end + "$target/*[label()=~regexp('Subsystem', 'i')]/#{resource[:name]}" end def self.instances @@ -46,11 +42,7 @@ def self.instances define_aug_method!(:destroy) do |aug, resource| key = resource[:name] - if supported?(:regexpi) - aug.rm("$target/*[label()=~regexp('Subsystem', 'i') and #{key}]") - else - aug.rm("$target/Subsystem[#{key}]") - end + aug.rm("$target/*[label()=~regexp('Subsystem', 'i') and #{key}]") end attr_aug_accessor(:command, :label => :resource) diff --git a/spec/unit/puppet/provider/ssh_config/augeas_spec.rb b/spec/unit/puppet/provider/ssh_config/augeas_spec.rb index de21e5d..a455dcc 100755 --- a/spec/unit/puppet/provider/ssh_config/augeas_spec.rb +++ b/spec/unit/puppet/provider/ssh_config/augeas_spec.rb @@ -235,7 +235,7 @@ end end - it "should replace settings case insensitively when on Augeas >= 1.0.0", :if => provider_class.supported?(:regexpi) do + it "should replace settings case insensitively" do apply!(Puppet::Type.type(:ssh_config).new( :name => "GssaPiaUthentication", :value => "yes", @@ -248,24 +248,6 @@ expect(aug.get("Host[.='*']/GSSAPIAuthentication")).to eq("yes") end end - - it "should not replace settings case insensitively when on Augeas < 1.0.0" do - provider_class.stubs(:supported?).with(:post_resource_eval) - provider_class.stubs(:supported?).with(:regexpi).returns(false) - apply!(Puppet::Type.type(:ssh_config).new( - :name => "GSSAPIDeLeGateCreDentials", - :value => "yes", - :target => target, - :provider => "augeas" - )) - - aug_open(target, "Ssh.lns") do |aug| - expect(aug.match("Host[.='*']/GSSAPIDelegateCredentials").size).to eq(1) - expect(aug.match("Host[.='*']/GSSAPIDeLeGateCreDentials").size).to eq(1) - expect(aug.get("Host[.='*']/GSSAPIDelegateCredentials")).to eq("no") - expect(aug.get("Host[.='*']/GSSAPIDeLeGateCreDentials")).to eq("yes") - end - end end end diff --git a/spec/unit/puppet/provider/sshd_config/augeas_spec.rb b/spec/unit/puppet/provider/sshd_config/augeas_spec.rb index cf0ff6a..e03cc8c 100755 --- a/spec/unit/puppet/provider/sshd_config/augeas_spec.rb +++ b/spec/unit/puppet/provider/sshd_config/augeas_spec.rb @@ -207,7 +207,7 @@ ') end - it "should add it next to commented out entry with different case when on Augeas >= 1.0.0", :if => provider_class.supported?(:regexpi) do + it "should add it next to commented out entry with different case" do apply!(Puppet::Type.type(:sshd_config).new( :name => "usedns", :value => "no", @@ -392,7 +392,7 @@ end end - it "should replace settings case insensitively when on Augeas >= 1.0.0", :if => provider_class.supported?(:regexpi) do + it "should replace settings case insensitively" do apply!(Puppet::Type.type(:sshd_config).new( :name => "PaSswordaUtheNticAtion", :value => "no", @@ -406,24 +406,6 @@ end end - it "should not replace settings case insensitively when on Augeas < 1.0.0" do - provider_class.stubs(:supported?).with(:post_resource_eval) - provider_class.stubs(:supported?).with(:regexpi).returns(false) - apply!(Puppet::Type.type(:sshd_config).new( - :name => "GSSAPIauthentIcAtion", - :value => "no", - :target => target, - :provider => "augeas" - )) - - aug_open(target, "Sshd.lns") do |aug| - expect(aug.match("GSSAPIAuthentication").size).to eq(1) - expect(aug.match("GSSAPIauthentIcAtion").size).to eq(1) - expect(aug.get("GSSAPIAuthentication")).to eq("yes") - expect(aug.get("GSSAPIauthentIcAtion")).to eq("no") - end - end - context "when using array_append" do it "should not remove existing values" do apply!(Puppet::Type.type(:sshd_config).new(