diff options
| author | Luke Kanies <luke@madstop.com> | 2007-09-25 12:10:38 -0500 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2007-09-25 12:10:38 -0500 |
| commit | ab1b0344da8faf8d94a363ba4a64e0238845828a (patch) | |
| tree | 7049c7acd514320139949f3ca649af5bd6244257 /lib | |
| parent | c8d02bd329743ea0a66528d65d8d05c9c015f259 (diff) | |
| parent | f8ab62b212788a4591276c95b5f67217f7517e4e (diff) | |
| download | puppet-ab1b0344da8faf8d94a363ba4a64e0238845828a.tar.gz puppet-ab1b0344da8faf8d94a363ba4a64e0238845828a.tar.xz puppet-ab1b0344da8faf8d94a363ba4a64e0238845828a.zip | |
Merge branch 'master' of git://michaelobrien.info/puppet
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/puppet.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/type/k5login.rb | 87 |
2 files changed, 88 insertions, 1 deletions
diff --git a/lib/puppet.rb b/lib/puppet.rb index 949922459..c1f31e467 100644 --- a/lib/puppet.rb +++ b/lib/puppet.rb @@ -242,7 +242,7 @@ module Puppet # Handle restarting. trap(:HUP) do - if client = @services.find { |s| s.is_a? Puppet::Network::Client::Master } and client.running? + if client = @services.find { |s| s.is_a? Puppet::Network::Client.master } and client.running? client.restart else Puppet.restart diff --git a/lib/puppet/type/k5login.rb b/lib/puppet/type/k5login.rb new file mode 100644 index 000000000..2372f658a --- /dev/null +++ b/lib/puppet/type/k5login.rb @@ -0,0 +1,87 @@ +# $Id: k5login.rb 2468 2007-08-07 23:30:20Z digant $ +# +# Plug-in type for handling k5login files + +Puppet::Type.newtype(:k5login) do + @doc = "Manage the .k5login file for a user. Specify the full path to + the .k5login file as the name and an array of principals as the + property principals." + + ensurable + + # Principals that should exist in the file + newproperty(:principals, :array_matching => :all) do + desc "The principals present in the .k5login file." + end + + # The path/name of the k5login file + newparam(:path) do + isnamevar + desc "The path to the file to manage. Must be fully qualified." + + validate do |value| + unless value =~ /^#{File::SEPARATOR}/ + raise Puppet::Error, "File paths must be fully qualified" + end + end + end + + # To manage the mode of the file + newproperty(:mode) do + desc "Manage the k5login file's mode" + defaultto { "644" } + end + + provide(:k5login) do + desc "The k5login provider is the only provider for the k5login + type." + + # Does this file exist? + def exists? + File.exists?(@resource[:name]) + end + + # create the file + def create + write(@resource.should(:principals)) + should_mode = @resource.should(:mode) + unless self.mode == should_mode + self.mode should_mode + end + end + + # remove the file + def destroy + File.unlink(@resource[:name]) + end + + # Return the principals + def principals + if File.exists?(@resource[:name]) + File.readlines(@resource[:name]).collect { |line| line.chomp } + else + :absent + end + end + + # Write the principals out to the k5login file + def principals=(value) + write(value) + end + + # Return the mode as an octal string, not as an integer + def mode + "%o" % (File.stat(@resource[:name]).mode & 007777) + end + + # Set the file mode, converting from a string to an integer. + def mode=(value) + File.chmod(Integer("0" + value), @resource[:name]) + end + + private + def write(value) + File.open(@resource[:name], "w") { |f| f.puts value.join("\n") } + end + end +end |
