diff options
| author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-11-13 05:13:38 +0000 |
|---|---|---|
| committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-11-13 05:13:38 +0000 |
| commit | ff06a8d6865550c5bfe1a2960df82651fe5277eb (patch) | |
| tree | 515abfb544d89c0112d6628a5e2b7a70617423a7 /lib/puppet/provider/sshkey | |
| parent | 4e96031745a215b84f1ae45916050f35741f9201 (diff) | |
| download | puppet-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/puppet/provider/sshkey')
| -rwxr-xr-x | lib/puppet/provider/sshkey/parsed.rb | 80 |
1 files changed, 34 insertions, 46 deletions
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 |
