Permalink
Browse files

Merge pull request #51 from rtyler/pull/34-basic-auth-cli

Rework pull #34 for basic auth in the CLI
  • Loading branch information...
2 parents ed3f6e5 + 5ddfe40 commit 611803b6599f52fe013b0fbc30a0364040f53c89 @rtyler rtyler committed Jul 30, 2012
Showing with 17 additions and 1 deletion.
  1. +2 −0 README.md
  2. +5 −1 ruby-tools/cli/lib/jenkins/api.rb
  3. +10 −0 ruby-tools/cli/spec/api_spec.rb
View
@@ -1,5 +1,7 @@
# Jenkins.rb - Ruby tools and SDK for Jenkins
+[![Build Status](https://buildhive.cloudbees.com/job/jenkinsci/job/jenkins.rb/badge/icon)](https://buildhive.cloudbees.com/job/jenkinsci/job/jenkins.rb/)
+
This is the Jenkins Ruby toolkit. You can use it to build, test and release Jenkins
plugins written in Ruby.
@@ -26,6 +26,8 @@ def self.setup_base_url(options = {})
# Thor's HashWithIndifferentAccess is based on string keys which URI::HTTP.build ignores
options = options.inject({}) { |mem, (key, val)| mem[key.to_sym] = val; mem }
+ options = setup_authentication(options)
+
# Handle URL style hosts by parsing the URL
if options.keys.length == 1 && options.key?(:host)
parsed_uri = URI::parse(options[:host])
@@ -35,9 +37,11 @@ def self.setup_base_url(options = {})
:path => parsed_uri.path,
:ssl => parsed_uri.scheme == 'https'
}
+ if parsed_uri.user && parsed_uri.password
+ basic_auth parsed_uri.user, parsed_uri.password
+ end
end
- options = setup_authentication(options)
options[:host] ||= ENV['JENKINS_HOST']
options[:port] ||= ENV['JENKINS_PORT']
options[:port] &&= options[:port].to_i
@@ -23,6 +23,16 @@
uri.path.should == ''
end
+ it "should accept basic auth parameters in the :host argument" do
+ uri = Jenkins::Api.setup_base_url :host => 'http://foo:bar@string.example.com:2'
+ uri.host.should == 'string.example.com'
+ uri.port.should == 2
+ uri.path.should == ''
+ auth = Jenkins::Api.default_options[:basic_auth]
+ auth[:username].should == 'foo'
+ auth[:password].should == 'bar'
+ end
+
context "with environment variables" do
after :each do
ENV.delete 'JENKINS_HOST'

0 comments on commit 611803b

Please sign in to comment.