Created
October 11, 2009 09:59
-
-
Save ohadlevy/207576 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
require 'net/http' | |
# Query external DB to fetch latest ssh known hosts, and store locally for 1 hour. | |
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" | |
#Time to keep cache - e.g. 1 hours. | |
ttl = (60 * 60) | |
# create a cache file | |
unless 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