diff options
| author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-09-03 21:40:30 +0000 |
|---|---|---|
| committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-09-03 21:40:30 +0000 |
| commit | b657850bf5cc02b25200720a57d5e3e381a98b62 (patch) | |
| tree | 5b73457c946506ced86996dda99209761a6b95a3 /lib/puppet/provider | |
| parent | 270f4448e26a45d213f8aa35c9ecf53843382358 (diff) | |
| download | puppet-b657850bf5cc02b25200720a57d5e3e381a98b62.tar.gz puppet-b657850bf5cc02b25200720a57d5e3e381a98b62.tar.xz puppet-b657850bf5cc02b25200720a57d5e3e381a98b62.zip | |
Fixing SSHKey support.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1548 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet/provider')
| -rwxr-xr-x | lib/puppet/provider/parsedfile.rb | 4 | ||||
| -rwxr-xr-x | lib/puppet/provider/sshkey/parsed.rb | 56 |
2 files changed, 58 insertions, 2 deletions
diff --git a/lib/puppet/provider/parsedfile.rb b/lib/puppet/provider/parsedfile.rb index 2527edfeb..53c49ef5e 100755 --- a/lib/puppet/provider/parsedfile.rb +++ b/lib/puppet/provider/parsedfile.rb @@ -120,7 +120,6 @@ class Puppet::Provider::ParsedFile < Puppet::Provider o.is_a? Hash and o[:name] == @model[:name] end @me = h - return h else @me = {} if @instances.empty? @@ -128,8 +127,9 @@ class Puppet::Provider::ParsedFile < Puppet::Provider else @instances << @me end - return @me end + + return @me end def initialize(model) diff --git a/lib/puppet/provider/sshkey/parsed.rb b/lib/puppet/provider/sshkey/parsed.rb new file mode 100755 index 000000000..e1dbeaad6 --- /dev/null +++ b/lib/puppet/provider/sshkey/parsed.rb @@ -0,0 +1,56 @@ +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 + } + + return instances + 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(",") + end + [name, hash[:type], hash[:key]].join(" ") + end +end + +# $Id$ |
