Update api-key:disable command to allow passing a name

This commit is contained in:
Alejandro Celaya
2024-11-06 20:10:06 +01:00
parent f6d70c599e
commit bd73362c94
6 changed files with 188 additions and 37 deletions

View File

@@ -40,11 +40,25 @@ readonly class ApiKeyService implements ApiKeyServiceInterface
}
/**
* @throws InvalidArgumentException
* @inheritDoc
*/
public function disable(string $key): ApiKey
public function disableByName(string $apiKeyName): ApiKey
{
return $this->disableApiKey($this->em->getRepository(ApiKey::class)->findOneBy([
'name' => $apiKeyName,
]));
}
/**
* @inheritDoc
*/
public function disableByKey(string $key): ApiKey
{
return $this->disableApiKey($this->getByKey($key));
}
private function disableApiKey(ApiKey|null $apiKey): ApiKey
{
$apiKey = $this->getByKey($key);
if ($apiKey === null) {
throw new InvalidArgumentException('Provided API key does not exist and can\'t be disabled');
}