Skip to content

Commit 709ab7c

Browse files
committed
Revert "(PUP-11067) Prioritize user type ensure before purge_ssh_keys"
This reverts commit 5c8472c.
1 parent 15a57ef commit 709ab7c

File tree

3 files changed

+20
-169
lines changed

3 files changed

+20
-169
lines changed

acceptance/tests/resource/user/should_manage_purge_ssh_keys_for_new_user.rb

Lines changed: 0 additions & 86 deletions
This file was deleted.

lib/puppet/type/user.rb

Lines changed: 20 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ module Puppet
6666
newproperty(:ensure, :parent => Puppet::Property::Ensure) do
6767
newvalue(:present, :event => :user_created) do
6868
provider.create
69-
@resource.generate
7069
end
7170

7271
newvalue(:absent, :event => :user_removed) do
@@ -695,7 +694,6 @@ def delimiter
695694

696695
def generate
697696
if !self[:purge_ssh_keys].empty?
698-
return [] if self[:ensure] == :present && !provider.exists?
699697
if Puppet::Type.type(:ssh_authorized_key).nil?
700698
warning _("Ssh_authorized_key type is not available. Cannot purge SSH keys.")
701699
else
@@ -744,6 +742,25 @@ def generate
744742
end
745743
raise ArgumentError, _("purge_ssh_keys must be true, false, or an array of file names, not %{value}") % { value: value.inspect }
746744
end
745+
746+
munge do |value|
747+
# Resolve string, boolean and symbol forms of true and false to a
748+
# single representation.
749+
test_sym = value.to_s.intern
750+
value = test_sym if [:true, :false].include? test_sym
751+
752+
return [] if value == :false
753+
home = resource[:home] || Dir.home(resource[:name])
754+
755+
return [ "#{home}/.ssh/authorized_keys" ] if value == :true
756+
# value is an array - munge each value
757+
[ value ].flatten.map do |entry|
758+
# make sure frozen value is duplicated by using a gsub, second mutating gsub! is then ok
759+
entry = entry.gsub(/^~\//, "#{home}/")
760+
entry.gsub!(/^%h\//, "#{home}/")
761+
entry
762+
end
763+
end
747764
end
748765

749766
newproperty(:loginclass, :required_features => :manages_loginclass) do
@@ -765,7 +782,7 @@ def generate
765782
# @see generate
766783
# @api private
767784
def find_unmanaged_keys
768-
munged_unmanaged_keys.
785+
self[:purge_ssh_keys].
769786
select { |f| File.readable?(f) }.
770787
map { |f| unknown_keys_in_file(f) }.
771788
flatten.each do |res|
@@ -777,41 +794,6 @@ def find_unmanaged_keys
777794
end
778795
end
779796

780-
def munged_unmanaged_keys
781-
value = self[:purge_ssh_keys]
782-
783-
# Resolve string, boolean and symbol forms of true and false to a
784-
# single representation.
785-
test_sym = value.to_s.intern
786-
value = test_sym if [:true, :false].include? test_sym
787-
788-
return [] if value == :false
789-
790-
home = self[:home]
791-
begin
792-
home ||= provider.home
793-
rescue
794-
Puppet.debug("User '#{self[:name]}' does not exist")
795-
end
796-
797-
if home.to_s.empty? || !Dir.exist?(home.to_s)
798-
if value == :true || [ value ].flatten.any? { |v| v.start_with?('~/', '%h/') }
799-
Puppet.debug("User '#{self[:name]}' has no home directory set to purge ssh keys from.")
800-
return []
801-
end
802-
end
803-
804-
return [ "#{home}/.ssh/authorized_keys" ] if value == :true
805-
806-
# value is an array - munge each value
807-
[ value ].flatten.map do |entry|
808-
# make sure frozen value is duplicated by using a gsub, second mutating gsub! is then ok
809-
entry = entry.gsub(/^~\//, "#{home}/")
810-
entry.gsub!(/^%h\//, "#{home}/")
811-
entry
812-
end
813-
end
814-
815797
# Parse an ssh authorized keys file superficially, extract the comments
816798
# on the keys. These are considered names of possible ssh_authorized_keys
817799
# resources. Keys that are managed by the present catalog are ignored.

spec/unit/type/user_spec.rb

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -174,51 +174,6 @@ def self.instances; []; end
174174
end
175175
end
176176

177-
describe "when managing the purge_ssh_keys property" do
178-
context "with valid input" do
179-
it "should support a :true value" do
180-
expect { described_class.new(:name => 'foo', :purge_ssh_keys => :true) }.to_not raise_error
181-
end
182-
183-
it "should support a :false value" do
184-
expect { described_class.new(:name => 'foo', :purge_ssh_keys => :false) }.to_not raise_error
185-
end
186-
187-
it "should support a String value" do
188-
expect { described_class.new(:name => 'foo', :purge_ssh_keys => File.expand_path('home/foo/.ssh/authorized_keys')) }.to_not raise_error
189-
end
190-
191-
it "should support an Array value" do
192-
expect { described_class.new(:name => 'foo', :purge_ssh_keys => [File.expand_path('home/foo/.ssh/authorized_keys'),
193-
File.expand_path('custom/authorized_keys')]) }.to_not raise_error
194-
end
195-
end
196-
197-
context "with faulty input" do
198-
it "should raise error for relative path" do
199-
expect { described_class.new(:name => 'foo', :purge_ssh_keys => 'home/foo/.ssh/authorized_keys') }.to raise_error(Puppet::ResourceError,
200-
/Paths to keyfiles must be absolute/ )
201-
end
202-
203-
it "should raise error for invalid type" do
204-
expect { described_class.new(:name => 'foo', :purge_ssh_keys => :invalid) }.to raise_error(Puppet::ResourceError,
205-
/purge_ssh_keys must be true, false, or an array of file names/ )
206-
end
207-
208-
it "should raise error for array with relative path" do
209-
expect { described_class.new(:name => 'foo', :purge_ssh_keys => ['home/foo/.ssh/authorized_keys',
210-
File.expand_path('custom/authorized_keys')]) }.to raise_error(Puppet::ResourceError,
211-
/Paths to keyfiles must be absolute/ )
212-
end
213-
214-
it "should raise error for array with invalid type" do
215-
expect { described_class.new(:name => 'foo', :purge_ssh_keys => [:invalid,
216-
File.expand_path('custom/authorized_keys')]) }.to raise_error(Puppet::ResourceError,
217-
/Each entry for purge_ssh_keys must be a string/ )
218-
end
219-
end
220-
end
221-
222177
describe "when managing the uid property" do
223178
it "should convert number-looking strings into actual numbers" do
224179
expect(described_class.new(:name => 'foo', :uid => '50')[:uid]).to eq(50)

0 commit comments

Comments
 (0)