summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrancois Deppierraz <francois.deppierraz@camptocamp.com>2008-07-02 16:18:06 +0200
committerFrancois Deppierraz <francois.deppierraz@camptocamp.com>2008-07-02 16:18:06 +0200
commit5156230b434adbe6de6606f6bcd8843264b8dab4 (patch)
tree717ac7284c4014882151b24569ede191bcf06f67
parent8c5c949b37d3af4439c713e6c6e57e8f4b0415ac (diff)
downloadpuppet-5156230b434adbe6de6606f6bcd8843264b8dab4.tar.gz
puppet-5156230b434adbe6de6606f6bcd8843264b8dab4.tar.xz
puppet-5156230b434adbe6de6606f6bcd8843264b8dab4.zip
Use generate instead of autorequire in the ssh_authorized_key type based on Luke's comments
-rw-r--r--lib/puppet/type/ssh_authorized_key.rb6
-rwxr-xr-xspec/unit/type/ssh_authorized_key.rb27
2 files changed, 22 insertions, 11 deletions
diff --git a/lib/puppet/type/ssh_authorized_key.rb b/lib/puppet/type/ssh_authorized_key.rb
index 650ebd879..a95f316af 100644
--- a/lib/puppet/type/ssh_authorized_key.rb
+++ b/lib/puppet/type/ssh_authorized_key.rb
@@ -45,7 +45,7 @@ module Puppet
defaultto do :absent end
end
- autorequire(:file) do
+ def generate
atype = Puppet::Type.type(:file)
target = self.should(:target)
dir = File.dirname(target)
@@ -53,11 +53,11 @@ module Puppet
rels = []
- unless atype[dir]
+ unless catalog.resource(:file, dir)
rels << atype.create(:name => dir, :ensure => :directory, :mode => 0700, :owner => user)
end
- unless atype[target]
+ unless catalog.resource(:file, target)
rels << atype.create(:name => target, :ensure => :present, :mode => 0600, :owner => user)
end
diff --git a/spec/unit/type/ssh_authorized_key.rb b/spec/unit/type/ssh_authorized_key.rb
index 581420698..3c87decf1 100755
--- a/spec/unit/type/ssh_authorized_key.rb
+++ b/spec/unit/type/ssh_authorized_key.rb
@@ -14,6 +14,7 @@ describe ssh_authorized_key do
@provider = stub 'provider', :class => @provider_class, :file_path => "/tmp/whatever", :clear => nil
@provider_class.stubs(:new).returns(@provider)
+ @catalog = Puppet::Node::Catalog.new
end
it "should have a name parameter" do
@@ -77,38 +78,48 @@ describe ssh_authorized_key do
end
it "should autorequire parent directories when user is given" do
- key = @class.create(
+ @catalog.add_resource @class.create(
:name => "Test",
:key => "AAA",
:type => "ssh-rsa",
:ensure => :present,
:user => "root")
+ @catalog.apply
- key.autorequire.should_not == []
+ target = File.expand_path("~root/.ssh")
+ @catalog.resource(:file, target).should be_an_instance_of(Puppet::Type.type(:file))
end
it "should set target when user is given" do
- key = @class.create(
+ @catalog.add_resource @class.create(
:name => "Test",
:key => "AAA",
:type => "ssh-rsa",
:ensure => :present,
:user => "root")
+ @catalog.apply
- key.should(:target).should == File.expand_path("~root/.ssh/authorized_keys")
+ target = File.expand_path("~root/.ssh/authorized_keys")
+ @catalog.resource(:file, target).should be_an_instance_of(Puppet::Type.type(:file))
end
it "should autorequire parent directories when target is given" do
- key = @class.create(
+ target = "/tmp/home/foo/bar/.ssh/authorized_keys"
+
+ @catalog.add_resource @class.create(
:name => "Test",
:key => "AAA",
:type => "ssh-rsa",
:ensure => :present,
- :target => "/tmp/home/foo/bar/.ssh/authorized_keys")
+ :target => target)
+ @catalog.apply
- key.autorequire.should_not == []
+ @catalog.resource(:file, target).should be_an_instance_of(Puppet::Type.type(:file))
end
- after { @class.clear }
+ after do
+ @class.clear
+ @catalog.clear
+ end
end