summaryrefslogtreecommitdiffstats
path: root/lib/puppet
diff options
context:
space:
mode:
Diffstat (limited to 'lib/puppet')
-rwxr-xr-xlib/puppet/provider/sshkey/parsed.rb56
-rwxr-xr-xlib/puppet/type/parsedtype/sshkey.rb129
-rwxr-xr-xlib/puppet/type/sshkey.rb60
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$