mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-10 01:03:13 +08:00
Update api-key:disable command to allow passing a name
This commit is contained in:
@@ -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');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user