Added support for basic authentication to hg provider
authorStuart Whelan <stuart@somepointinthefuture.co.nz>
Sat, 21 Jun 2014 05:26:14 +0000 (17:26 +1200)
committerAaron Stone <aaron@serendipity.cx>
Mon, 23 Jun 2014 21:57:46 +0000 (14:57 -0700)
Updated unit tests
Updated hg readme and added examples

README.markdown
examples/hg/clone_basic_auth.pp [new file with mode: 0644]
lib/puppet/provider/vcsrepo/hg.rb
spec/unit/puppet/provider/vcsrepo/hg_spec.rb

index 39cd249..99c5ac9 100644 (file)
@@ -306,6 +306,16 @@ To specify an SSH identity key,
       identity => "/home/user/.ssh/id_dsa,
     }
 
+To specify a username and password for HTTP Basic authentication,
+
+    vcsrepo { "/path/to/repo":
+      ensure   => latest,
+      provider => hg,
+      source   => 'http://hg.example.com/myrepo',
+      basic_auth_username => 'hgusername',
+      basic_auth_password => 'hgpassword',
+    }
+
 #####Sources that use SSH 
 
 When your source uses SSH, such as 'ssh://...', you can manage your SSH keys with Puppet using the [require](http://docs.puppetlabs.com/references/stable/metaparameter.html#require) metaparameter in `vcsrepo` to ensure they are present.
@@ -470,4 +480,4 @@ Puppet Labs modules on the Puppet Forge are open projects, and community contrib
 
 We want to keep it as easy as possible to contribute changes so that our modules work in your environment. There are a few guidelines that we need contributors to follow so that we can have a chance of keeping on top of things.
 
-You can read the complete module contribution guide on the Puppet Labs wiki.
\ No newline at end of file
+You can read the complete module contribution guide on the Puppet Labs wiki.
diff --git a/examples/hg/clone_basic_auth.pp b/examples/hg/clone_basic_auth.pp
new file mode 100644 (file)
index 0000000..1931e1f
--- /dev/null
@@ -0,0 +1,7 @@
+vcsrepo { '/path/to/repo':
+  ensure   => latest,
+  provider => hg,
+  source   => 'http://hg.example.com/myrepo',
+  basic_auth_username => 'hgusername',
+  basic_auth_password => 'hgpassword',
+}
index 56ca527..090f019 100644 (file)
@@ -6,7 +6,7 @@ Puppet::Type.type(:vcsrepo).provide(:hg, :parent => Puppet::Provider::Vcsrepo) d
   commands :hg => 'hg'
   optional_commands :su => 'su'
 
-  has_features :reference_tracking, :ssh_identity, :user
+  has_features :reference_tracking, :ssh_identity, :user, :basic_auth
 
   def create
     if !@resource.value(:source)
@@ -108,6 +108,16 @@ Puppet::Type.type(:vcsrepo).provide(:hg, :parent => Puppet::Provider::Vcsrepo) d
     if args.length > 0 and args[-1].is_a? Hash
       options.merge!(args.pop)
     end
+
+    if @resource.value(:basic_auth_username) && @resource.value(:basic_auth_password)
+      args += [
+        "--config", "\"auth.x.prefix=#{@resource.value(:source)}\"",
+        "--config", "\"auth.x.username=#{@resource.value(:basic_auth_username)}\"",
+        "--config", "\"auth.x.password=#{@resource.value(:basic_auth_password)}\"",
+        "--config", "\"auth.x.schemes=http https\""
+      ]
+    end
+
     if options[:remote] and @resource.value(:identity)
       args += ["--ssh", "ssh -oStrictHostKeyChecking=no -oPasswordAuthentication=no -oKbdInteractiveAuthentication=no -oChallengeResponseAuthentication=no -i #{@resource.value(:identity)}"]
     end
index 7fd5348..6b21c1c 100644 (file)
@@ -42,6 +42,22 @@ describe Puppet::Type.type(:vcsrepo).provider(:hg) do
         provider.create
       end
     end
+
+    context "when basic auth is used" do
+      it "should execute 'hg clone'" do
+        resource[:source] = 'something'
+        resource[:basic_auth_username] = 'user'
+        resource[:basic_auth_password] = 'pass'
+        provider.expects(:hg).with('clone',
+          resource.value(:source),
+          resource.value(:path),
+            "--config","\"auth.x.prefix=" + resource.value(:source) + "\"",
+            "--config","\"auth.x.username=" + resource.value(:basic_auth_username) + "\"",
+            "--config","\"auth.x.password=" + resource.value(:basic_auth_password) + "\"",
+            "--config","\"auth.x.schemes=http https" + "\"")
+        provider.create
+      end
+    end
   end
 
   describe 'destroying' do