summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-11-13 05:13:38 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-11-13 05:13:38 +0000
commitff06a8d6865550c5bfe1a2960df82651fe5277eb (patch)
tree515abfb544d89c0112d6628a5e2b7a70617423a7 /lib
parent4e96031745a215b84f1ae45916050f35741f9201 (diff)
downloadpuppet-ff06a8d6865550c5bfe1a2960df82651fe5277eb.tar.gz
puppet-ff06a8d6865550c5bfe1a2960df82651fe5277eb.tar.xz
puppet-ff06a8d6865550c5bfe1a2960df82651fe5277eb.zip
Ported sshkey over, yay.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1866 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/provider/mount/netinfo.rb2
-rwxr-xr-xlib/puppet/provider/sshkey/parsed.rb80
-rwxr-xr-xlib/puppet/type/host.rb9
-rwxr-xr-xlib/puppet/type/sshkey.rb20
-rw-r--r--lib/puppet/util/fileparsing.rb1
5 files changed, 64 insertions, 48 deletions
diff --git a/lib/puppet/provider/mount/netinfo.rb b/lib/puppet/provider/mount/netinfo.rb
index 9cd57fe06..738f8269d 100644
--- a/lib/puppet/provider/mount/netinfo.rb
+++ b/lib/puppet/provider/mount/netinfo.rb
@@ -3,7 +3,7 @@
require 'puppet/provider/nameservice/netinfo'
require 'puppet/provider/mount'
-Puppet::Type.type(:mount).provide :netinfo, :parent => Puppet::Provider::NetInfo do
+Puppet::Type.type(:mount).provide :netinfo, :parent => Puppet::Provider::NameService::NetInfo do
include Puppet::Provider::Mount
desc "Mount management in NetInfo. This provider is highly experimental and is known
not to work currently."
diff --git a/lib/puppet/provider/sshkey/parsed.rb b/lib/puppet/provider/sshkey/parsed.rb
index e1dbeaad6..e247502ff 100755
--- a/lib/puppet/provider/sshkey/parsed.rb
+++ b/lib/puppet/provider/sshkey/parsed.rb
@@ -1,55 +1,43 @@
require 'puppet/provider/parsedfile'
-Puppet::Type.type(:sshkey).provide :parsed, :parent => Puppet::Provider::ParsedFile do
- @filetype = Puppet::FileType.filetype(:flat)
- @path = "/etc/ssh/ssh_known_hosts"
- @fields = [:name, :type, :key]
- # Parse an sshknownhosts file
- #
- # This method also stores existing comments, and it stores all host
- # jobs in order, mostly so that comments are retained in the order
- # they were written and in proximity to the same jobs.
- def self.parse(text)
- count = 0
- instances = []
- text.chomp.split("\n").each { |line|
- hash = {}
- case line
- when /^#/, /^\s*$/:
- # add comments and blank lines to the list as they are
- instances << line
- else
- hash = {}
- fields().zip(line.split(" ")).each { |param, value|
- hash[param] = value
- }
-
- if hash[:name] =~ /,/
- names = hash[:name].split(",")
- hash[:name] = names.shift
- hash[:alias] = names
- end
-
- if hash[:alias] == ""
- hash.delete(:alias)
- end
-
- instances << hash
- count += 1
- end
- }
+known = nil
+case Facter.value(:operatingsystem)
+when "Darwin": known = "/etc/ssh_known_hosts"
+else
+ known = "/etc/ssh/ssh_known_hosts"
+end
- return instances
+Puppet::Type.type(:sshkey).provide(:parsed,
+ :parent => Puppet::Provider::ParsedFile,
+ :default_target => known,
+ :filetype => :flat
+) do
+ text_line :comment, :match => /^#/
+ text_line :blank, :match => /^\s+/
+ record_line :parsed, :fields => %w{name type key}
+
+ # Override the line parsing a bit, so we can split the aliases out.
+ def self.parse_line(line)
+ hash = super
+ if hash[:name] =~ /,/
+ names = hash[:name].split(",")
+ hash[:name] = names.shift
+ hash[:alias] = names
+ end
+ hash
end
-
- # Convert the current object into an entry for a known-hosts file.
- def self.to_record(hash)
- name = hash[:name]
- if hash.include?(:alias)
- name += "," + hash[:alias].join(",")
+
+
+ def self.to_line(hash)
+ if hash[:alias]
+ hash = hash.dup
+ names = [hash[:name], hash[:alias]].flatten
+
+ hash[:name] = [hash[:name], hash[:alias]].flatten.join(",")
+ hash.delete(:alias)
end
- [name, hash[:type], hash[:key]].join(" ")
+ super(hash)
end
end
diff --git a/lib/puppet/type/host.rb b/lib/puppet/type/host.rb
index 49a3144b8..abc0ad30c 100755
--- a/lib/puppet/type/host.rb
+++ b/lib/puppet/type/host.rb
@@ -15,6 +15,10 @@ module Puppet
make those aliases available in your Puppet scripts and also on
disk."
+ def insync?
+ @is == @should
+ end
+
# Make sure our "is" value is always an array.
def is
current = super
@@ -41,6 +45,11 @@ module Puppet
@is = value
end
end
+
+ def retrieve
+ super
+ @is = [@is] unless @is.is_a?(Array)
+ end
# We actually want to return the whole array here, not just the first
# value.
diff --git a/lib/puppet/type/sshkey.rb b/lib/puppet/type/sshkey.rb
index 102e792af..444b47d35 100755
--- a/lib/puppet/type/sshkey.rb
+++ b/lib/puppet/type/sshkey.rb
@@ -1,8 +1,10 @@
module Puppet
- newtype(:sshkey, Puppet::Type::ParsedType) do
+ newtype(:sshkey) do
@doc = "Installs and manages ssh host keys. At this point, this type
only knows how to install keys into /etc/ssh/ssh_known_hosts, and
it cannot manage user authorized keys yet."
+
+ ensurable
newstate(:type) do
desc "The encryption type used. Probably ssh-dss or ssh-rsa."
@@ -19,6 +21,10 @@ module Puppet
specified as an array. Note that this state has the same name
as one of the metaparams; using this state to set aliases will
make those aliases available in your Puppet scripts."
+
+ def insync?
+ @is == @should
+ end
# We actually want to return the whole array here, not just the first
# value.
@@ -54,6 +60,18 @@ module Puppet
isnamevar
end
+
+ newstate(:target) do
+ desc "The file in which to store the mount table. Only used by
+ those providers that write to disk (i.e., not NetInfo)."
+
+ defaultto { if @parent.class.defaultprovider.ancestors.include?(Puppet::Provider::ParsedFile)
+ @parent.class.defaultprovider.default_target
+ else
+ nil
+ end
+ }
+ end
end
end
diff --git a/lib/puppet/util/fileparsing.rb b/lib/puppet/util/fileparsing.rb
index 390648404..8d8d92df9 100644
--- a/lib/puppet/util/fileparsing.rb
+++ b/lib/puppet/util/fileparsing.rb
@@ -186,6 +186,7 @@ module Puppet::Util::FileParsing
unless options[:separator].is_a?(String) or options[:joiner]
options[:joiner] = " "
end
+
if block_given?
method = "handle_record_line_%s" % name