Add list permissions command

This commit is contained in:
Tim
2024-09-24 00:04:40 +02:00
parent 62e8f87ec8
commit bb31bb34b8
6 changed files with 77 additions and 16 deletions

View File

@ -2,8 +2,6 @@
namespace App\Service;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Process\InputStream;
use Symfony\Component\Process\Process;
class BackupService

View File

@ -5,12 +5,10 @@ namespace App\Service;
class DatabaseCredentials
{
public function __construct(
private string $hostname,
private string $user,
private string $password,
)
{
}
private readonly string $hostname,
private readonly string $user,
private readonly string $password,
) {}
public function getHostname(): string
{

View File

@ -110,4 +110,16 @@ class DatabaseService
throw new Exception(sprintf('User delete error: %s', $this->conn->error));
}
}
public function listPermissions(string $user, ?string $host = 'localhost'): array
{
$results = $this->conn->query(sprintf("SHOW GRANTS FOR '%s'@'%s'", $user, $host), );
$permissions = [];
while ($result = $results->fetch_array()) {
$permissions[] = $result[0];
}
return $permissions;
}
}