Skip to content
This repository has been archived by the owner on Apr 7, 2018. It is now read-only.

[COOK-1709] Add 'grant_option' parameter. #14

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -202,6 +202,8 @@ resource depending on your RDBMS: `mysql_database_user` or
:port, :username, :password :port, :username, :password
- privileges: array of database privileges to grant user. used by the - privileges: array of database privileges to grant user. used by the
:grant action. default is :all :grant action. default is :all
- grant_option: appends 'WITH GRANT OPTION' to grant statement. used by MySQL
provider only. default is 'false'
- host: host where user connections are allowed from. used by MySQL - host: host where user connections are allowed from. used by MySQL
provider only. default is 'localhost' provider only. default is 'localhost'
- table: table to grant privileges on. used by :grant action and MySQL - table: table to grant privileges on. used by :grant action and MySQL
Expand Down
3 changes: 2 additions & 1 deletion libraries/provider_database_mysql_user.rb
Expand Up @@ -57,6 +57,7 @@ def action_drop
def action_grant def action_grant
begin begin
grant_statement = "GRANT #{@new_resource.privileges.join(', ')} ON #{@new_resource.database_name || "*"}.#{@new_resource.table || "*"} TO '#{@new_resource.username}'@'#{@new_resource.host}' IDENTIFIED BY '#{@new_resource.password}'" grant_statement = "GRANT #{@new_resource.privileges.join(', ')} ON #{@new_resource.database_name || "*"}.#{@new_resource.table || "*"} TO '#{@new_resource.username}'@'#{@new_resource.host}' IDENTIFIED BY '#{@new_resource.password}'"
grant_statement += " WITH GRANT OPTION" if @new_resource.grant_option == true
Chef::Log.info("#{@new_resource}: granting access with statement [#{grant_statement}]") Chef::Log.info("#{@new_resource}: granting access with statement [#{grant_statement}]")
db.query(grant_statement) db.query(grant_statement)
@new_resource.updated_by_last_action(true) @new_resource.updated_by_last_action(true)
Expand All @@ -73,4 +74,4 @@ def exists?
end end
end end
end end
end end
8 changes: 8 additions & 0 deletions libraries/resource_database_user.rb
Expand Up @@ -85,6 +85,14 @@ def privileges(arg=nil)
) )
end end


def grant_option(arg=nil)
set_or_return(
:grant_option,
arg,
:kind_of => [ TrueClass, FalseClass ], :default => false
)
end

end end
end end
end end