New CLI command to create the initial API key idempotently

This commit is contained in:
Alejandro Celaya
2023-09-21 09:29:59 +02:00
parent 6db46b50e9
commit 637d8334f4
14 changed files with 84 additions and 129 deletions

View File

@@ -7,6 +7,7 @@ namespace Shlinkio\Shlink\Rest\Service;
use Doctrine\ORM\EntityManagerInterface;
use Shlinkio\Shlink\Common\Exception\InvalidArgumentException;
use Shlinkio\Shlink\Rest\ApiKey\Model\ApiKeyMeta;
use Shlinkio\Shlink\Rest\ApiKey\Repository\ApiKeyRepositoryInterface;
use Shlinkio\Shlink\Rest\Entity\ApiKey;
use function sprintf;
@@ -27,6 +28,13 @@ class ApiKeyService implements ApiKeyServiceInterface
return $apiKey;
}
public function createInitial(string $key): ?ApiKey
{
/** @var ApiKeyRepositoryInterface $repo */
$repo = $this->em->getRepository(ApiKey::class);
return $repo->createInitialApiKey($key);
}
public function check(string $key): ApiKeyCheckResult
{
$apiKey = $this->getByKey($key);

View File

@@ -12,6 +12,8 @@ interface ApiKeyServiceInterface
{
public function create(ApiKeyMeta $apiKeyMeta): ApiKey;
public function createInitial(string $key): ?ApiKey;
public function check(string $key): ApiKeyCheckResult;
/**