basic authentication ook laten werken

This commit is contained in:
Ward Wouts 2011-06-17 11:57:31 +00:00
parent dd33751ebc
commit 19040f3a9c

View file

@ -274,6 +274,8 @@ Usage: #{$0.sub(/.*\//, "")} [options] -u <baseurl>
-m <svn|cvs|git|ds> check for one of subversion, CVS, git or .DS_Store (default: all) -m <svn|cvs|git|ds> check for one of subversion, CVS, git or .DS_Store (default: all)
-u <baseurl> set baseurl -u <baseurl> set baseurl
-s use ssl -s use ssl
--user <user> basic authentiction user
--pass <password> basic authentication password
EOT EOT
exit exit
end end
@ -286,7 +288,9 @@ def cmdline
[ "-H", GetoptLong::NO_ARGUMENT ], [ "-H", GetoptLong::NO_ARGUMENT ],
[ "-m", GetoptLong::REQUIRED_ARGUMENT ], [ "-m", GetoptLong::REQUIRED_ARGUMENT ],
[ "-u", GetoptLong::REQUIRED_ARGUMENT ], [ "-u", GetoptLong::REQUIRED_ARGUMENT ],
[ "-s", GetoptLong::NO_ARGUMENT ] [ "-s", GetoptLong::NO_ARGUMENT ],
[ "--user", GetoptLong::REQUIRED_ARGUMENT ],
[ "--pass", GetoptLong::REQUIRED_ARGUMENT ]
) )
opts.quiet=true opts.quiet=true
@ -323,6 +327,16 @@ def fetch(uri_str, limit = 10)
port = URI.parse(uri_str).port port = URI.parse(uri_str).port
path = URI.parse(uri_str).path path = URI.parse(uri_str).path
query = URI.parse(uri_str).query query = URI.parse(uri_str).query
userinfo = URI.parse(uri_str).userinfo
user = ""
pass = ""
if userinfo
user, pass = userinfo.split(/:/)
end
user = @user if @user
pass = @pass if @pass
http = Net::HTTP.new(host, port) http = Net::HTTP.new(host, port)
http.use_ssl = @use_ssl http.use_ssl = @use_ssl
@ -331,7 +345,8 @@ def fetch(uri_str, limit = 10)
else else
req = Net::HTTP::Get.new("#{URI.escape(path)}") req = Net::HTTP::Get.new("#{URI.escape(path)}")
end end
req.basic_auth @user, @pass
req.basic_auth user, pass
response = http.request(req) response = http.request(req)
case response case response
when Net::HTTPSuccess then response.body when Net::HTTPSuccess then response.body
@ -638,6 +653,14 @@ else
@use_ssl = false @use_ssl = false
end end
if options["--user"]
@user = options["--user"]
end
if options["--pass"]
@pass = options["--pass"]
end
# lelijke hack, wanneer andere formaten ook geharvest gaan kunnen worden moet dit # lelijke hack, wanneer andere formaten ook geharvest gaan kunnen worden moet dit
# anders. Nu, ach, dit werkt. # anders. Nu, ach, dit werkt.
if options["-H"] if options["-H"]