Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #11351: plugin_install_from_secure_repository.4.diff

File plugin_install_from_secure_repository.4.diff, 1.5 kB (added by david.calavera, 4 months ago)

also fixes #10023

  • railties/lib/commands/plugin.rb

    old new  
    288288    end 
    289289     
    290290    def rails_env 
    291       @rails_env || RailsEnvironment.default 
     291      @rails_env ||= RailsEnvironment.default 
    292292    end 
    293293end 
    294294 
     
    893893      if url =~ /^svn:\/\/.*/ 
    894894        `svn ls #{url}`.split("\n").map {|entry| "/#{entry}"} rescue nil 
    895895      else 
    896         open(url) do |stream| 
     896        open(url, credentials(url)) do |stream| 
    897897          links("", stream.read) 
    898898        end rescue nil 
    899899      end 
     
    922922   
    923923  def download(link) 
    924924    puts "+ #{File.join(@cwd, File.basename(link))}" unless @quiet 
    925     open(link) do |stream| 
     925    open(link, credentials(link)) do |stream| 
    926926      File.open(File.join(@cwd, File.basename(link)), "wb") do |file| 
    927927        file.write(stream.read) 
    928928      end 
     
    938938  def fetch_dir(url) 
    939939    @level += 1 
    940940    push_d(File.basename(url)) if @level > 0 
    941     open(url) do |stream| 
     941    open(url, credentials(url)) do |stream| 
    942942      contents =  stream.read 
    943943      fetch(links(url, contents)) 
    944944    end 
    945945    pop_d if @level > 0 
    946946    @level -= 1 
    947947  end 
     948   
     949  def credentials(url) 
     950    uri = URI.parse(url) 
     951    raise ArgumentError, 'url is not an HTTP URI' unless uri.is_a?(URI::HTTP) 
     952 
     953    uri && uri.user ? 
     954      {:http_basic_authentication => [URI.unescape(uri.user), URI.unescape(uri.password)]} : {} 
     955  end 
    948956end 
    949957 
    950958Commands::Plugin.parse!