diff options
author | drebs <drebs@riseup.net> | 2011-03-27 17:15:43 -0300 |
---|---|---|
committer | drebs <drebs@riseup.net> | 2011-03-27 17:15:43 -0300 |
commit | b436e0428e8efc2addbfe0866eb255a6700fb011 (patch) | |
tree | 8b9543c471d79ebfca43bb09b96c18ef26234dec /lib/puppet/provider/mysql_user/mysql.rb | |
parent | 14dbafc286141d62ed70d4e171f7a5aeac62482b (diff) | |
download | puppet-mysql-b436e0428e8efc2addbfe0866eb255a6700fb011.tar.gz puppet-mysql-b436e0428e8efc2addbfe0866eb255a6700fb011.tar.bz2 |
fixing providers' path
Diffstat (limited to 'lib/puppet/provider/mysql_user/mysql.rb')
-rw-r--r-- | lib/puppet/provider/mysql_user/mysql.rb | 76 |
1 files changed, 0 insertions, 76 deletions
diff --git a/lib/puppet/provider/mysql_user/mysql.rb b/lib/puppet/provider/mysql_user/mysql.rb deleted file mode 100644 index a19b353..0000000 --- a/lib/puppet/provider/mysql_user/mysql.rb +++ /dev/null @@ -1,76 +0,0 @@ -require 'puppet/provider/package' - -Puppet::Type.type(:mysql_user).provide(:mysql, - # T'is funny business, this code is quite generic - :parent => Puppet::Provider::Package) do - - desc "Use mysql as database." - commands :mysql => '/usr/bin/mysql' - commands :mysqladmin => '/usr/bin/mysqladmin' - - # retrieve the current set of mysql users - def self.instances - users = [] - - cmd = "#{command(:mysql)} mysql -NBe 'select concat(user, \"@\", host), password from user'" - execpipe(cmd) do |process| - process.each do |line| - users << new( query_line_to_hash(line) ) - end - end - return users - end - - def self.query_line_to_hash(line) - fields = line.chomp.split(/\t/) - { - :name => fields[0], - :password_hash => fields[1], - :ensure => :present - } - end - - def mysql_flush - mysqladmin "flush-privileges" - end - - def query - result = {} - - cmd = "#{command(:mysql)} mysql -NBe 'select concat(user, \"@\", host), password from user where concat(user, \"@\", host) = \"%s\"'" % @resource[:name] - execpipe(cmd) do |process| - process.each do |line| - unless result.empty? - raise Puppet::Error, - "Got multiple results for user '%s'" % @resource[:name] - end - result = query_line_to_hash(line) - end - end - result - end - - def create - mysql "mysql", "-e", "create user '%s' identified by PASSWORD '%s'" % [ @resource[:name].sub("@", "'@'"), @resource.should(:password_hash) ] - mysql_flush - end - - def destroy - mysql "mysql", "-e", "drop user '%s'" % @resource[:name].sub("@", "'@'") - mysql_flush - end - - def exists? - not mysql("mysql", "-NBe", "select '1' from user where CONCAT(user, '@', host) = '%s'" % @resource[:name]).empty? - end - - def password_hash - @property_hash[:password_hash] - end - - def password_hash=(string) - mysql "mysql", "-e", "SET PASSWORD FOR '%s' = '%s'" % [ @resource[:name].sub("@", "'@'"), string ] - mysql_flush - end -end - |