diff options
author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-10-17 21:53:40 +0000 |
---|---|---|
committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-10-17 21:53:40 +0000 |
commit | ada77773591f5e17ddcdb4af6c20ded3715ecda9 (patch) | |
tree | 224c19078469abe60d4212b81bc3d16913d69d62 /lib/puppet | |
parent | 95f2fe70bf63791fb691d539281f5cfbfd1fb664 (diff) | |
download | puppet-ada77773591f5e17ddcdb4af6c20ded3715ecda9.tar.gz puppet-ada77773591f5e17ddcdb4af6c20ded3715ecda9.tar.xz puppet-ada77773591f5e17ddcdb4af6c20ded3715ecda9.zip |
sshkey now uses a provider
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1802 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet')
-rwxr-xr-x | lib/puppet/provider/sshkey/parsed.rb | 56 | ||||
-rwxr-xr-x | lib/puppet/type/parsedtype/sshkey.rb | 129 | ||||
-rwxr-xr-x | lib/puppet/type/sshkey.rb | 60 |
3 files changed, 116 insertions, 129 deletions
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/sshkey.rb b/lib/puppet/type/parsedtype/sshkey.rb deleted file mode 100755 index d8fb6cda3..000000000 --- a/lib/puppet/type/parsedtype/sshkey.rb +++ /dev/null @@ -1,129 +0,0 @@ -require 'etc' -require 'facter' -require 'puppet/type/parsedtype' -require 'puppet/type/state' - -module Puppet - newtype(:sshkey, Puppet::Type::ParsedType) do - newstate(:type) do - desc "The encryption type used. Probably ssh-dss or ssh-rsa." - end - - newstate(:key) do - desc "The key itself; generally a long string of hex digits." - end - - # FIXME This should automagically check for aliases to the hosts, just - # to see if we can automatically glean any aliases. - 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." - - # We actually want to return the whole array here, not just the first - # value. - def should - if defined? @should - return @should - else - return nil - end - end - - validate do |value| - if value =~ /\s/ - raise Puppet::Error, "Aliases cannot include whitespace" - end - if value =~ /,/ - raise Puppet::Error, "Aliases cannot include whitespace" - end - end - - # Make a puppet alias in addition. - munge do |value| - # Add the :alias metaparam in addition to the state - @parent.newmetaparam(@parent.class.metaparamclass(:alias), value) - value - end - end - - newparam(:name) do - desc "The host name." - - 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. - # Adding at least hard-coded alternative placement for Darwin - ajax - case Facter.value("operatingsystem") - when "Darwin": - @path = "/etc/ssh_known_hosts" - else - @path = "/etc/ssh/ssh_known_hosts" - end - @fields = [:name, :type, :key] - - @filetype = Puppet::FileType.filetype(:flat) -# case Facter["operatingsystem"].value -# when "Solaris": -# @filetype = Puppet::FileType::SunOS -# else -# @filetype = Puppet::CronType::Default -# end - - # 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 - 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 - -# $Id$ diff --git a/lib/puppet/type/sshkey.rb b/lib/puppet/type/sshkey.rb new file mode 100755 index 000000000..102e792af --- /dev/null +++ b/lib/puppet/type/sshkey.rb @@ -0,0 +1,60 @@ +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 + + newstate(:key) do + desc "The key itself; generally a long string of hex digits." + end + + # FIXME This should automagically check for aliases to the hosts, just + # to see if we can automatically glean any aliases. + 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." + + # We actually want to return the whole array here, not just the first + # value. + def should + if defined? @should + return @should + else + return nil + end + end + + validate do |value| + if value =~ /\s/ + raise Puppet::Error, "Aliases cannot include whitespace" + end + if value =~ /,/ + raise Puppet::Error, "Aliases cannot include whitespace" + end + end + + # Make a puppet alias in addition. + munge do |value| + unless value == :absent + # Add the :alias metaparam in addition to the state + @parent.newmetaparam(@parent.class.metaparamclass(:alias), value) + end + value + end + end + + newparam(:name) do + desc "The host name." + + isnamevar + end + end +end + +# $Id$ |