Skip to content
This repository was archived by the owner on Dec 2, 2020. It is now read-only.

Commit 67b6209

Browse files
committed
Add support for better ssh repo handling
1 parent 230a86b commit 67b6209

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

lib/puppet/provider/repository/git.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ def self.default_protocol
1313
'https'
1414
end
1515

16+
def self.validate(v)
17+
unless %w(git ssh https).member? v.to_s
18+
raise Puppet::Error, \
19+
"Protocol can only be git, https, or ssh for now!"
20+
end
21+
end
22+
1623
def query
1724
h = { :name => @resource[:name], :provider => :git }
1825

@@ -70,7 +77,14 @@ def destroy
7077

7178
def expand_source(source)
7279
if source =~ /\A[^@\/\s]+\/[^\/\s]+\z/
73-
"#{@resource[:protocol]}://github.com/#{source}"
80+
case @resource[:protocol]
81+
when "git", "https"
82+
"#{@resource[:protocol]}://github.com/#{source}"
83+
when "ssh"
84+
"git@github.com:#{source}.git"
85+
else
86+
raise "failtown"
87+
end
7488
else
7589
source
7690
end

lib/puppet/type/repository.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,17 @@ def insync?(is)
6060
provider.class.default_protocol
6161
end
6262
end
63+
64+
validate do |v|
65+
provider.class.validate v
66+
end
6367
end
6468

6569
newparam :user do
6670
desc "User to run this operation as."
6771

6872
defaultto do
69-
Facter[:boxen_user].value
73+
Facter.value(:boxen_user) || Facter.value(:id) || "root"
7074
end
7175
end
7276

spec/unit/puppet/type/repository_spec.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
let(:default_opts) do
55
{
66
:source => 'boxen/boxen',
7-
:path => '/tmp/boxen'
7+
:path => '/tmp/boxen',
88
}
99
end
1010

@@ -82,15 +82,16 @@
8282
end
8383

8484
it "should default to boxen_user if it exists" do
85-
Facter[:boxen_user].stubs(:value).returns(nil)
86-
factory.call(default_opts)[:user].should == nil
85+
Facter.stubs(:value).with(:boxen_user).returns(nil)
86+
Facter.stubs(:value).with(:id).returns(nil)
87+
factory.call(default_opts)[:user].should == "root"
8788

88-
Facter[:boxen_user].stubs(:value).returns('testuser')
89+
Facter.stubs(:value).with(:boxen_user).returns('testuser')
8990
factory.call(default_opts)[:user].should == 'testuser'
9091
end
9192

9293
it "should override boxen_user if both exist" do
93-
Facter[:boxen_user].stubs(:value).returns('testuser')
94+
Facter.stubs(:value).with(:boxen_user).returns('testuser')
9495

9596
opts = default_opts.merge(:user => "otheruser")
9697
factory.call(opts)[:user].should == 'otheruser'

0 commit comments

Comments
 (0)