__mysql_privileges: fix quoting

This commit is contained in:
ander 2020-02-13 17:29:44 +02:00
parent bcefeb240c
commit 710e99f240
2 changed files with 8 additions and 3 deletions

View file

@ -30,7 +30,7 @@ host="$( cat "$__object/parameter/host" )"
check_privileges="$(
mysql -B -N -e "show grants for '$user'@'$host'" \
| grep -Ei "^grant $privileges on .$database.\..$table. to " || true )"
| grep -Ei "^grant $privileges on .$database.\..?$table.? to " || true )"
if [ -n "$check_privileges" ]
then

View file

@ -37,13 +37,18 @@ user="$( cat "$__object/parameter/user" )"
host="$( cat "$__object/parameter/host" )"
if [ "$table" != '*' ]
then
table="$( printf '`%s`' "$table" )"
fi
case "$state_should" in
present)
echo "mysql -e 'grant $privileges on \`$database\`.\`$table\` to \`$user\`@\`$host\`'"
echo "mysql -e 'grant $privileges on \`$database\`.$table to \`$user\`@\`$host\`'"
echo "grant $privileges on $database.$table to $user@$host" >> "$__messages_out"
;;
absent)
echo "mysql -e 'revoke $privileges on \`$database\`.\`$table\` from \`$user\`@\`$host\`'"
echo "mysql -e 'revoke $privileges on \`$database\`.$table from \`$user\`@\`$host\`'"
echo "revoke $privileges on $database.$table from $user@$host" >> "$__messages_out"
;;
esac