Skip to content

/dbname in hostname #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: feature/master/use_mysql_gem_for_provider
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions lib/puppet/provider/database_user/mysql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@

def create
dbh = Puppet::Type.type(:database_user).provider(:mysql).connect
dbh.select_db('mysql').query("create user '%s' identified by PASSWORD '%s'" % [ @resource[:name].sub("@", "'@'"), @resource[:password_hash] ])
user = @resource[:name].sub(/^([^@]*)@([^\/]*)(\/(.*))?$/,'\1\'@\'\2')
dbh.select_db('mysql').query("create user '%s' identified by PASSWORD '%s'" % [ user, @resource[:password_hash] ])
dbh.reload
@property_hash[:ensure] = :present
@property_hash[:password_hash] = @resource[:password_hash]
end

def destroy
dbh = Puppet::Type.type(:database_user).provider(:mysql).connect
dbh.select_db('mysql').query("drop user '%s'" % @resource[:name].sub("@", "'@'"))
user = @resource[:name].sub(/^([^@]*)@([^\/]*)(\/(.*))?$/,'\1\'@\'\2')
dbh.select_db('mysql').query("drop user '%s'" % user)
dbh.reload
@property_hash[:ensure] = :absent
end
Expand All @@ -36,7 +38,8 @@ def password_hash

def password_hash=(string)
dbh = Puppet::Type.type(:database_user).provider(:mysql).connect
dbh.select_db('mysql').query("SET PASSWORD FOR '%s' = '%s'" % [ @resource[:name].sub("@", "'@'"), string ])
user = @resource[:name].sub(/^([^@]*)@([^\/]*)(\/(.*))?$/,'\1\'@\'\2')
dbh.select_db('mysql').query("SET PASSWORD FOR '%s' = '%s'" % [ user, string ])
dbh.reload
@property_hash[:password_hash] = string
end
Expand Down