From 19040f3a9cfeac447566448f699491ffa1a2365d Mon Sep 17 00:00:00 2001 From: Ward Wouts Date: Fri, 17 Jun 2011 11:57:31 +0000 Subject: [PATCH] basic authentication ook laten werken --- listversioned/listversioned.rb | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/listversioned/listversioned.rb b/listversioned/listversioned.rb index 01c722a..fa1cd52 100755 --- a/listversioned/listversioned.rb +++ b/listversioned/listversioned.rb @@ -274,6 +274,8 @@ Usage: #{$0.sub(/.*\//, "")} [options] -u -m check for one of subversion, CVS, git or .DS_Store (default: all) -u set baseurl -s use ssl +--user basic authentiction user +--pass basic authentication password EOT exit end @@ -286,7 +288,9 @@ def cmdline [ "-H", GetoptLong::NO_ARGUMENT ], [ "-m", 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 @@ -323,6 +327,16 @@ def fetch(uri_str, limit = 10) port = URI.parse(uri_str).port path = URI.parse(uri_str).path 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.use_ssl = @use_ssl @@ -331,7 +345,8 @@ def fetch(uri_str, limit = 10) else req = Net::HTTP::Get.new("#{URI.escape(path)}") end - req.basic_auth @user, @pass + + req.basic_auth user, pass response = http.request(req) case response when Net::HTTPSuccess then response.body @@ -638,6 +653,14 @@ else @use_ssl = false 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 # anders. Nu, ach, dit werkt. if options["-H"]