summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorroot <root@puppetmaster.black.co.at>2007-10-11 14:49:24 +0200
committerroot <root@puppetmaster.black.co.at>2007-10-11 14:49:24 +0200
commit887629c8a185d802a156b01c09a807ec76f04e70 (patch)
tree86e2e45162bf20d7d2d6ea25d1fa38eccb5aa522
parentd33c7aa10e3a4bd9e97e947c471ee3ed36e9d1e2 (diff)
downloadpuppet-mysql-887629c8a185d802a156b01c09a807ec76f04e70.tar.gz
puppet-mysql-887629c8a185d802a156b01c09a807ec76f04e70.tar.xz
puppet-mysql-887629c8a185d802a156b01c09a807ec76f04e70.zip
mysql: manage password of a user
-rw-r--r--plugins/puppet/parser/functions/mysql_password.rb9
-rw-r--r--plugins/puppet/provider/mysql_user/mysql.rb8
-rw-r--r--plugins/puppet/type/mysql_user.rb4
3 files changed, 19 insertions, 2 deletions
diff --git a/plugins/puppet/parser/functions/mysql_password.rb b/plugins/puppet/parser/functions/mysql_password.rb
new file mode 100644
index 0000000..6443d95
--- /dev/null
+++ b/plugins/puppet/parser/functions/mysql_password.rb
@@ -0,0 +1,9 @@
+# hash a string as mysql's "PASSWORD()" function would do it
+require 'digest/sha1'
+
+module Puppet::Parser::Functions
+ newfunction(:mysql_password, :type => :rvalue) do |args|
+ '*' + Digest::SHA1.hexdigest(Digest::SHA1.digest(args[0])).upcase
+ end
+end
+
diff --git a/plugins/puppet/provider/mysql_user/mysql.rb b/plugins/puppet/provider/mysql_user/mysql.rb
index a1c2896..93024c5 100644
--- a/plugins/puppet/provider/mysql_user/mysql.rb
+++ b/plugins/puppet/provider/mysql_user/mysql.rb
@@ -15,5 +15,13 @@ Puppet::Type.type(:mysql_user).provide(:mysql) do
false
end
end
+
+ def password_hash
+ mysql("mysql", "-NBe", "select password from user where user='#{@resource[:name]}' and host='#{@resource[:host]}'").chomp
+ end
+
+ def password_hash=(string)
+ mysql "mysql", "-e", "SET PASSWORD FOR '#{@resource[:name]}'@'#{@resource[:host]}' = PASSWORD('#{string}')"
+ end
end
diff --git a/plugins/puppet/type/mysql_user.rb b/plugins/puppet/type/mysql_user.rb
index 0005aed..d0756de 100644
--- a/plugins/puppet/type/mysql_user.rb
+++ b/plugins/puppet/type/mysql_user.rb
@@ -8,8 +8,8 @@ Puppet::Type.newtype(:mysql_user) do
newparam(:host) do
desc "The host from where to connect."
end
- newparam(:password) do
- desc "The password of the user."
+ newproperty(:password_hash) do
+ desc "The password hash of the user. Use mysql_password() for creating such a hash."
end
end