1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
Puppet::Type.type(:mysql_user).provide(:mysql) do
desc "Use mysql as database."
commands :mysql => '/usr/bin/mysql'
def create
mysql "mysql", "-e", "create user '%s@%s' identified by '%s'" % [ @resource[:name], @resource[:host], @resource[:password] ]
end
def destroy
mysql "mysql", "-e", "drop user '%s@%s'" % [ @resource[:name], @resource[:host] ]
end
def exists?
if /^#{@resource[:name]}@#{@resource[:host]}$/.match( mysql( "mysql", "-Be", 'SELECT CONCAT(user, "@", host) FROM user' ) )
true
else
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
|