From 3bd03d18effa4e52bddb52d74fb5eabb7d1f1a06 Mon Sep 17 00:00:00 2001 From: Adam Scott Date: Thu, 2 May 2013 16:52:46 +1000 Subject: [PATCH] Added support for basic http authentication. Helpful for passworded hudson/jenkins instances. --- lib/greenscreen/app.rb | 8 +++++--- sample/greenscreen.yml | 7 +++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/greenscreen/app.rb b/lib/greenscreen/app.rb index 21563ce..bac5cac 100644 --- a/lib/greenscreen/app.rb +++ b/lib/greenscreen/app.rb @@ -30,7 +30,7 @@ class App < Sinatra::Base private def load_source(source) - jobs = load_cc_xml(source.url) + jobs = load_cc_xml(source) if included_jobs = source.jobs jobs = jobs.select { |j| included_jobs.member?(j.name) } end @@ -39,8 +39,10 @@ def load_source(source) $stderr.puts "ERROR loading #{source.url.inspect}: #{e}" end - def load_cc_xml(url) - xml = REXML::Document.new(open(url)) + def load_cc_xml(source) + opts = {} + opts[:http_basic_authentication] = [source.username, source.password] if source.respond_to?(:username) + xml = REXML::Document.new(open(source.url, opts)) xml.elements["//Projects"].map do |project_element| data = project_element.attributes Job.new.tap do |job| diff --git a/sample/greenscreen.yml b/sample/greenscreen.yml index da9c359..6c109cd 100644 --- a/sample/greenscreen.yml +++ b/sample/greenscreen.yml @@ -11,3 +11,10 @@ sources: jobs: - roodi - runway + + - + url: http://yet.another.build.server:8080/cc.xml + username: 'batman' + password: 'wayne' + jobs: + - batmobile