Created
November 25, 2009 15:26
-
-
Save ohadlevy/242786 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Puppet::Parser::Functions | |
newfunction(:sshkeyfromdb, :type => :rvalue) do |args| | |
#local cache file on each puppetmaster | |
ssh_keys_file = "/tmp/sshkeys" | |
#URL to query | |
host = "puppet" | |
url = "/setting/ssh_keys?script=true" | |
#Time to keep cache - e.g. 1 hours. | |
ttl = (60 * 60) | |
# create a cache file | |
if not File.exist?(ssh_keys_file) or File.mtime(ssh_keys_file) < (Time.now - ttl) | |
# cache miss, refreshing | |
keys = Net::HTTP.get host,url | |
File.new(ssh_keys_file,"w", 0600).write(keys) | |
else | |
keys = File.open(ssh_keys_file).read | |
end | |
return keys | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment