class Browsed::Proxies::Chrome::ProxyAuthentication::Packager

Public Class Methods

package_extension(proxy, path) click to toggle source
# File lib/browsed/proxies/chrome/proxy_authentication.rb, line 7
def self.package_extension(proxy, path)
  file_id         =   Digest::SHA1.hexdigest("#{proxy[:username]}:#{proxy[:password]}@#{proxy[:host]}:#{proxy[:port]}")
  plugin_path     =   "#{path}/chrome-proxy-authentication-plugin-#{file_id}"
  FileUtils.mkdir_p plugin_path
  
  manifest_file   =   "#{plugin_path}/manifest.json"
  File.open(manifest_file, 'w') { |file| file.write(::Browsed::Proxies::Chrome::ProxyAuthentication::MANIFEST_JSON_TEMPLATE) }
  
  script_file     =   "#{plugin_path}/background.js"
  script_result   =   Browsed::Proxies::Chrome::ProxyAuthentication::BACKGROUND_SCRIPT_TEMPLATE % [proxy[:host], proxy[:port], proxy[:username], proxy[:password]]
  File.open(script_file, 'w') { |file| file.write(script_result) }
  
  return plugin_path
end