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 | |
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')
-rwxr-xr-x | lib/puppet/provider/parsedfile.rb | 4 | ||||
-rwxr-xr-x | lib/puppet/provider/sshkey/parsed.rb | 56 | ||||
-rwxr-xr-x | lib/puppet/type/parsedtype.rb | 6 | ||||
-rwxr-xr-x | lib/puppet/type/parsedtype/host.rb | 156 | ||||
-rwxr-xr-x | lib/puppet/type/sshkey.rb (renamed from lib/puppet/type/parsedtype/sshkey.rb) | 67 |
5 files changed, 65 insertions, 224 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$ diff --git a/lib/puppet/type/parsedtype.rb b/lib/puppet/type/parsedtype.rb index 1b958db4d..58ea44d62 100755 --- a/lib/puppet/type/parsedtype.rb +++ b/lib/puppet/type/parsedtype.rb @@ -59,7 +59,7 @@ module Puppet # first, so I don't need to worry about that. def sync(value) # Just copy the value to our 'is' state; it'll get flushed later - self.is = value + #self.is = value return nil end @@ -152,7 +152,7 @@ module Puppet end def exists? - h = provider.hash + h = self.retrieve if h[:ensure] == :absent return false @@ -187,6 +187,6 @@ end #require 'puppet/type/parsedtype/host' require 'puppet/type/parsedtype/port' require 'puppet/type/parsedtype/mount' -require 'puppet/type/parsedtype/sshkey' +#require 'puppet/type/parsedtype/sshkey' # $Id$ diff --git a/lib/puppet/type/parsedtype/host.rb b/lib/puppet/type/parsedtype/host.rb deleted file mode 100755 index df8ed3df7..000000000 --- a/lib/puppet/type/parsedtype/host.rb +++ /dev/null @@ -1,156 +0,0 @@ -require 'etc' -require 'facter' -require 'puppet/type/parsedtype' -require 'puppet/type/state' - -module Puppet - newtype(:host, Puppet::Type::ParsedType) do - newstate(:ip) do - desc "The host's IP address." - end - - newstate(:alias) do - desc "Any alias the host might have. Multiple values must be - 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 and also on - disk." - - # Make sure our "is" value is always an array. - def is - current = super - unless current.is_a? Array - current = [current] - end - current - end - - def is_to_s - self.is.join(" ") - end - - # We have to override the feeding mechanism; it might be nil or - # white-space separated - def is=(value) - # If it's just whitespace, ignore it - case value - when /^\s+$/ - @is = nil - when String - @is = value.split(/\s+/) - else - @is = value - end - end - - # We actually want to return the whole array here, not just the first - # value. - def should - if defined? @should - if @should == [:absent] - return :absent - else - return @should - end - else - return nil - end - end - - def should_to_s - @should.join(" ") - end - - validate do |value| - if value =~ /\s/ - raise Puppet::Error, "Aliases cannot include whitespace" - end - end - - munge do |value| - if value == :absent or value == "absent" - :absent - else - # Add the :alias metaparam in addition to the state - @parent.newmetaparam(@parent.class.metaparamclass(:alias), value) - value - end - end - end - - newparam(:name) do - desc "The host name." - - isnamevar - end - - @doc = "Installs and manages host entries. For most systems, these - entries will just be in /etc/hosts, but some systems (notably OS X) - will have different solutions." - - @instances = [] - - @path = "/etc/hosts" - @fields = [:ip, :name, :alias] - - @filetype = Puppet::FileType.filetype(:flat) - - # Parse a host 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 - hash = {} - text.chomp.split("\n").each { |line| - case line - when /^#/, /^\s*$/: - # add comments and blank lines to the list as they are - @instances << line - else - if line.sub!(/^(\S+)\s+(\S+)\s*/, '') - hash[:ip] = $1 - hash[:name] = $2 - - unless line == "" - line.sub!(/\s*/, '') - line.sub!(/^([^#]+)\s*/) do |value| - aliases = $1 - unless aliases =~ /^\s*$/ - hash[:alias] = aliases - end - - "" - end - end - else - raise Puppet::Error, "Could not match '%s'" % line - end - - if hash[:alias] == "" - hash.delete(:alias) - end - - hash2obj(hash) - - hash.clear - count += 1 - end - } - end - - # Convert the current object into a host-style string. - def to_record - str = "%s\t%s" % [self.state(:ip).value, self[:name]] - - if value = self.value(:alias) - str += "\t%s" % value.join("\t") - end - - str - end - end -end - -# $Id$ diff --git a/lib/puppet/type/parsedtype/sshkey.rb b/lib/puppet/type/sshkey.rb index 26c9b4f30..e769199bf 100755 --- a/lib/puppet/type/parsedtype/sshkey.rb +++ b/lib/puppet/type/sshkey.rb @@ -1,10 +1,9 @@ -require 'etc' -require 'facter' -require 'puppet/type/parsedtype' -require 'puppet/type/state' - module Puppet newtype(:sshkey, Puppet::Type::ParsedType) 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." + newstate(:type) do desc "The encryption type used. Probably ssh-dss or ssh-rsa." end @@ -53,64 +52,6 @@ module Puppet isnamevar end - - @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." - - @instances = [] - - # FIXME This should be configurable. - @path = "/etc/ssh/ssh_known_hosts" - @fields = [:name, :type, :key] - - @filetype = Puppet::FileType.filetype(:flat) - - # 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 - hash = {} - text.chomp.split("\n").each { |line| - 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 - - hash2obj(hash) - - hash.clear - count += 1 - end - } - end - - # Convert the current object into a host-style string. - def to_record - name = self[:name] - if @states.include?(:alias) - name += "," + @states[:alias].value.join(",") - end - [name, @states[:type].value, @states[:key].value].join(" ") - end end end |