Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ However, you can also later configure the access credentils with:
Pulp::Connection::Handler.hostname = 'localhost'
Pulp::Connection::Handler.username = 'admin'
Pulp::Connection::Handler.password = 'admin'
Pulp::Connection::Handler.enable_v2 = false

== Examples

Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ end

task :default => :spec

require 'rake/rdoctask'
require 'rdoc/task'
Rake::RDocTask.new do |rdoc|
version = File.exist?('VERSION') ? File.read('VERSION') : ""

Expand Down
1 change: 1 addition & 0 deletions examples/test_pulp.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
hostname: localhost
username: admin
password: admin
enable_v2: false
debug: false
1 change: 1 addition & 0 deletions lib/pulp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@
Pulp::Connection::Handler.username = global_options['username']
Pulp::Connection::Handler.password = global_options['password']
Pulp::Connection::Handler.debug_enabled = global_options['debug']||false
Pulp::Connection::Handler.enable_v2 = global_options['enable_v2']||false
end
6 changes: 3 additions & 3 deletions lib/pulp/connection/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def set_fields(field_data)
end

class << self
attr_accessor :hostname, :username, :password, :https
attr_accessor :hostname, :username, :password, :https, :enable_v2

def reset
Pulp::Connection::Handler.reset_instance(self.identifier)
Expand Down Expand Up @@ -71,11 +71,11 @@ def base_put(cmd,item=nil,params=nil)
end

def base
Pulp::Connection::Handler.instance_for(self.identifier, hostname, username, password, (https.nil? ? true : https))
Pulp::Connection::Handler.instance_for(self.identifier, hostname, username, password, (https.nil? ? true : https), enable_v2)
end

def plain_base
Pulp::Connection::Handler.instance_for('', hostname, username, password, (https.nil? ? true : https))
Pulp::Connection::Handler.instance_for('', hostname, username, password, (https.nil? ? true : https), enable_v2)
end

def parse_item_cmd(item,cmd)
Expand Down
12 changes: 7 additions & 5 deletions lib/pulp/connection/handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ class Handler
include Pulp::Common::Debug

class << self
attr_accessor :hostname,:username, :password
attr_accessor :hostname,:username, :password, :enable_v2

def instance_for(identifier,h=nil,u=nil,p=nil,https=true)
def instance_for(identifier,h=nil,u=nil,p=nil,https=true,v2=nil)
instances[identifier] ||= Handler.new(identifier,
h||hostname||'localhost',
u||username||'admin',
p||password||'admin',
https
https,
v2||enable_v2||false
)
end

Expand All @@ -30,12 +31,13 @@ def instances
end
end

def initialize(identifier,hostname,username=nil,password=nil,https=true)
def initialize(identifier,hostname,username=nil,password=nil,https=true,enable_v2=nil)
@identifier = identifier
@hostname = hostname
@username = username
@password = password
@https = https
@enable_v2 = enable_v2
end

def parsed
Expand All @@ -47,7 +49,7 @@ def connection
end

def api_path
"/pulp/api"
@enable_v2 ? "/pulp/api/v2" : "/pulp/api"
end

def url
Expand Down
59 changes: 58 additions & 1 deletion spec/pulp/connection/handler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,18 @@
it "defaults https to true" do
Pulp::Connection::Handler.instance_for(:default_https,'bla','user','secret2').instance_variable_get('@https').should eql(true)
end

it "takes passed https setting" do
Pulp::Connection::Handler.instance_for(:default_https2,'bla','user2','secret2',false).instance_variable_get('@https').should eql(false)
end

it "defaults enable_v2 to false" do
Pulp::Connection::Handler.instance_for(:default_enable_v2,'bla','user','secret2').instance_variable_get('@enable_v2').should eql(false)
end

it "takes passed enable_v2 setting" do
Pulp::Connection::Handler.instance_for(:default_enable_v2_2,'bla','user2','secret2',false, true).instance_variable_get('@enable_v2').should eql(true)
end
end

describe ".reset" do
Expand Down Expand Up @@ -104,7 +113,7 @@
end

describe "#api_path" do
it "is a fixed apth" do
it "default v1 path" do
instance.api_path.should eql("/pulp/api")
end
end
Expand All @@ -119,4 +128,52 @@
end
end
end

describe "a v2 instance" do
let(:instance) do
Pulp::Connection::Handler.hostname = 'localhost'
Pulp::Connection::Handler.username = 'admin'
Pulp::Connection::Handler.password = 'admin'
Pulp::Connection::Handler.enable_v2 = true
Pulp::Connection::Handler.instance_for(:instance)
end
before(:each) { Pulp::Connection::Handler.reset_all }
describe "#parsed" do
it "gets the connection passed" do
instance.parsed{|conn| conn.should eql(instance.connection); DummyResult }
end

it "parses the result" do
instance.parsed{|conn| DummyResult }['a'].should eql(1)
end
end

describe "#connection" do
it "'s url should match our url" do
instance.connection.url.should eql(instance.url)
end
it "'s user should match our username" do
instance.connection.user.should eql(Pulp::Connection::Handler.username)
end
it "'s passowrd should match our password" do
instance.connection.password.should eql(Pulp::Connection::Handler.password)
end
end

describe "#api_path" do
it "should be v2 path" do
instance.api_path.should eql("/pulp/api/v2")
end
end

describe "#url" do
it "should be a full url depending on the identifier" do
instance.url.should eql("https://localhost/pulp/api/v2/instances")
end
it "should depend on the https flag" do
i = Pulp::Connection::Handler.instance_for(:second_instance,'localhost','user','password',false)
i.url.should eql("http://localhost/pulp/api/v2/second_instances")
end
end
end
end