Class: Ipecache::Plugins::Local
- Defined in:
- lib/ipecache/plugins/local.rb
Instance Method Summary collapse
Methods inherited from Plugin
#continue_on_error, #enabled?, hook, hooks, #initialize, #log_file, name, #name, #plugin_puts, #plugin_puts_error, #quiet_mode, #urls
Constructor Details
This class inherits a constructor from Ipecache::Plugins::Plugin
Instance Method Details
#perform ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/ipecache/plugins/local.rb', line 9 def perform safe_require 'uri' hosts = config.hosts use_ssh = config.use_ssh if !hosts plugin_puts "No hosts in config file specified. Exiting..." exit 1 end with = (use_ssh) ? "ssh curl" : "curl"; urls.each do |u| url = u.chomp plugin_puts ("Purging #{url} through #{with}") hosts.each do |local| hostname = URI.parse(url).host path = URI.parse(url).path if use_ssh result = `ssh #{local} 'curl -X PURGE -s -o /dev/null -w \"%{http_code}\" --header \"Host: #{hostname}\" \"http://localhost#{path}\"'` else result = `curl -X PURGE -s -o /dev/null -w "%{http_code}" --header "Host: #{hostname}" "http://#{local}#{path}"` end if result.include?("200") plugin_puts "--Purged from #{local} sucessfully" elsif result.include?("404") plugin_puts "--Purge from #{local} not needed, asset not found" else plugin_puts_error(url,"--Purge from #{local} failed with http_code = #{result}") end end end end |