Permalink
Browse files

Renamed type to httpauth.

Added support for Digest authentication.

Added TODO
  • Loading branch information...
1 parent 543d5d3 commit fe51cbcc617a3ead13630b408aed99f16e83bccc @jamtur01 jamtur01 committed Apr 25, 2010
Showing with 90 additions and 61 deletions.
  1. +7 −5 README.markdown
  2. +6 −0 TODO
  3. +0 −34 provider/htpasswd/htpasswd.rb
  4. +38 −0 provider/httpauth/httpauth.rb
  5. +0 −22 type/htpasswd.rb
  6. +39 −0 type/httpauth.rb
View
@@ -1,7 +1,7 @@
-Puppet htpasswd type
-====================
+Puppet HTTP Authentication type
+===============================
-This type provides a htpasswd type for Puppet.
+This provides a HTTP Authentication type for Puppet that support Basic and Digest authentication.
Copyright - James Turnbull <james@lovedthanlost.net>
@@ -15,8 +15,10 @@ Requirements
Usage
-----
- htpasswd { 'user':
- file => '/path/to/htpassword/file',
+ httpauth { 'user':
+ file => '/path/to/password/file',
password => 'password',
+ realm => 'realm',
+ mechanism => basic,
ensure => present,
}
View
6 TODO
@@ -0,0 +1,6 @@
+TODO
+====
+
+* Add digest support - rename to httpaut - DONEh
+* Add password validation
+
@@ -1,34 +0,0 @@
-begin
- require 'webrick'
-rescue
-
-end
-
-Puppet::Type.type(:htpasswd).provide(:htpasswd) do
- desc "Manage HTTP Basic authentication files"
-
- def create
- htpd = WEBrick::HTTPAuth::Htpasswd.new(resource[:file])
- realm = nil
- htpd.set_passwd(realm, resource[:name], resource[:password])
- htpd.flush
- end
-
- def destroy
- htpd = WEBrick::HTTPAuth::Htpasswd.new(resource[:file])
- realm = nil
- htpd.delete_passwd(realm, resource[:name])
- htpd.flush
- end
-
- def exists?
- if File.exists?(resource[:file])
- htpd = WEBrick::HTTPAuth::Htpasswd.new(resource[:file])
- realm = nil
- htpd.get_passwd(realm, resource[:name], false)
- else
- File.new(resource[:file], "w")
- false
- end
- end
-end
@@ -0,0 +1,38 @@
+begin
+ require 'webrick'
+rescue
+ Puppet.warning "You need WEBrick installed to manage HTTP Authentication files."
+end
+
+Puppet::Type.type(:httpauth).provide(:httpauth) do
+ desc "Manage HTTP Basic and Digest authentication files"
+
+ def create
+ @htauth.set_passwd(resource[:realm], resource[:name], resource[:password])
+ @htauth.flush
+ end
+
+ def destroy
+ @htauth.delete_passwd(resource[:realm], resource[:name])
+ @htauth.flush
+ end
+
+ def exists?
+ if File.exists?(resource[:file])
+ mech(resource[:file])
+ @htauth.get_passwd(resource[:realm], resource[:name], false)
+ else
+ File.new(resource[:file], "w")
+ mech(resource[:file])
+ false
+ end
+ end
+
+ def mech(file)
+ if resource[:mechanism] == :digest
+ @htauth = WEBrick::HTTPAuth::Htdigest.new(file)
+ elsif resource[:mechanism] == :basic
+ @htauth = WEBrick::HTTPAuth::Htpasswd.new(file)
+ end
+ end
+end
View
@@ -1,22 +0,0 @@
-Puppet::Type.newtype(:htpasswd) do
- @doc = "Manage HTTP basic password files"
-
- ensurable
-
- newparam(:name) do
- desc "The name of the user to be managed"
-
- isnamevar
-
- end
-
- newparam(:file) do
- desc "The HTTP Basic password file to be managed"
-
- end
-
- newparam(:password) do
- desc "The password"
-
- end
-end
View
@@ -0,0 +1,39 @@
+Puppet::Type.newtype(:httpauth) do
+ @doc = "Manage HTTP Basic or Digest password files." +
+ " httpauth { 'user': " +
+ " file => '/path/to/password/file', " +
+ " password => 'password', " +
+ " mechanism => basic, " +
+ " ensure => present, " +
+ " } "
+
+ ensurable
+
+ newparam(:name) do
+ desc "The name of the user to be managed."
+
+ isnamevar
+ end
+
+ newparam(:file) do
+ desc "The HTTP password file to be managed. If it doesn't exist it is created."
+ end
+
+ newparam(:password) do
+ desc "The password in plaintext."
+ end
+
+ newparam(:realm) do
+ desc "The realm - defaults to nil and mainly used for Digest authentication."
+
+ defaultto "nil"
+ end
+
+ newparam(:mechanism) do
+ desc "The authentication mechanism to use - either basic or digest. Default to basic."
+
+ newvalues(:basic, :digest)
+
+ defaultto :basic
+ end
+end

0 comments on commit fe51cbc

Please sign in to comment.