mirror of
https://github.com/shlinkio/shlink.git
synced 2026-02-28 04:03:12 +08:00
Simplify ApiKey entity by exposing key as a readonly prop
This commit is contained in:
@@ -109,7 +109,7 @@ class GenerateKeyCommand extends Command
|
||||
));
|
||||
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
$io->success(sprintf('Generated API key: "%s"', $apiKey->toString()));
|
||||
$io->success(sprintf('Generated API key: "%s"', $apiKey->key));
|
||||
|
||||
if (! ApiKey::isAdmin($apiKey)) {
|
||||
ShlinkTable::default($io)->render(
|
||||
|
||||
@@ -54,7 +54,7 @@ class ListKeysCommand extends Command
|
||||
$messagePattern = $this->determineMessagePattern($apiKey);
|
||||
|
||||
// Set columns for this row
|
||||
$rowData = [sprintf($messagePattern, $apiKey), sprintf($messagePattern, $apiKey->name ?? '-')];
|
||||
$rowData = [sprintf($messagePattern, $apiKey->key), sprintf($messagePattern, $apiKey->name ?? '-')];
|
||||
if (! $enabledOnly) {
|
||||
$rowData[] = sprintf($messagePattern, $this->getEnabledSymbol($apiKey));
|
||||
}
|
||||
|
||||
@@ -244,7 +244,7 @@ class ListShortUrlsCommand extends Command
|
||||
}
|
||||
if ($input->getOption('show-api-key')) {
|
||||
$columnsMap['API Key'] = static fn (array $_, ShortUrl $shortUrl): string =>
|
||||
$shortUrl->authorApiKey?->__toString() ?? '';
|
||||
$shortUrl->authorApiKey?->key ?? '';
|
||||
}
|
||||
if ($input->getOption('show-api-key-name')) {
|
||||
$columnsMap['API Key Name'] = static fn (array $_, ShortUrl $shortUrl): string|null =>
|
||||
|
||||
@@ -55,11 +55,11 @@ class ListKeysCommandTest extends TestCase
|
||||
+--------------------------------------+------+------------+---------------------------+-------+
|
||||
| Key | Name | Is enabled | Expiration date | Roles |
|
||||
+--------------------------------------+------+------------+---------------------------+-------+
|
||||
| {$apiKey1} | - | --- | - | Admin |
|
||||
| {$apiKey1->key} | - | --- | - | Admin |
|
||||
+--------------------------------------+------+------------+---------------------------+-------+
|
||||
| {$apiKey2} | - | --- | 2020-01-01T00:00:00+00:00 | Admin |
|
||||
| {$apiKey2->key} | - | --- | 2020-01-01T00:00:00+00:00 | Admin |
|
||||
+--------------------------------------+------+------------+---------------------------+-------+
|
||||
| {$apiKey3} | - | +++ | - | Admin |
|
||||
| {$apiKey3->key} | - | +++ | - | Admin |
|
||||
+--------------------------------------+------+------------+---------------------------+-------+
|
||||
|
||||
OUTPUT,
|
||||
@@ -71,9 +71,9 @@ class ListKeysCommandTest extends TestCase
|
||||
+--------------------------------------+------+-----------------+-------+
|
||||
| Key | Name | Expiration date | Roles |
|
||||
+--------------------------------------+------+-----------------+-------+
|
||||
| {$apiKey1} | - | - | Admin |
|
||||
| {$apiKey1->key} | - | - | Admin |
|
||||
+--------------------------------------+------+-----------------+-------+
|
||||
| {$apiKey2} | - | - | Admin |
|
||||
| {$apiKey2->key} | - | - | Admin |
|
||||
+--------------------------------------+------+-----------------+-------+
|
||||
|
||||
OUTPUT,
|
||||
@@ -97,18 +97,18 @@ class ListKeysCommandTest extends TestCase
|
||||
+--------------------------------------+------+-----------------+--------------------------+
|
||||
| Key | Name | Expiration date | Roles |
|
||||
+--------------------------------------+------+-----------------+--------------------------+
|
||||
| {$apiKey1} | - | - | Admin |
|
||||
| {$apiKey1->key} | - | - | Admin |
|
||||
+--------------------------------------+------+-----------------+--------------------------+
|
||||
| {$apiKey2} | - | - | Author only |
|
||||
| {$apiKey2->key} | - | - | Author only |
|
||||
+--------------------------------------+------+-----------------+--------------------------+
|
||||
| {$apiKey3} | - | - | Domain only: example.com |
|
||||
| {$apiKey3->key} | - | - | Domain only: example.com |
|
||||
+--------------------------------------+------+-----------------+--------------------------+
|
||||
| {$apiKey4} | - | - | Admin |
|
||||
| {$apiKey4->key} | - | - | Admin |
|
||||
+--------------------------------------+------+-----------------+--------------------------+
|
||||
| {$apiKey5} | - | - | Author only |
|
||||
| {$apiKey5->key} | - | - | Author only |
|
||||
| | | | Domain only: example.com |
|
||||
+--------------------------------------+------+-----------------+--------------------------+
|
||||
| {$apiKey6} | - | - | Admin |
|
||||
| {$apiKey6->key} | - | - | Admin |
|
||||
+--------------------------------------+------+-----------------+--------------------------+
|
||||
|
||||
OUTPUT,
|
||||
@@ -125,13 +125,13 @@ class ListKeysCommandTest extends TestCase
|
||||
+--------------------------------------+---------------+-----------------+-------+
|
||||
| Key | Name | Expiration date | Roles |
|
||||
+--------------------------------------+---------------+-----------------+-------+
|
||||
| {$apiKey1} | Alice | - | Admin |
|
||||
| {$apiKey1->key} | Alice | - | Admin |
|
||||
+--------------------------------------+---------------+-----------------+-------+
|
||||
| {$apiKey2} | Alice and Bob | - | Admin |
|
||||
| {$apiKey2->key} | Alice and Bob | - | Admin |
|
||||
+--------------------------------------+---------------+-----------------+-------+
|
||||
| {$apiKey3} | | - | Admin |
|
||||
| {$apiKey3->key} | | - | Admin |
|
||||
+--------------------------------------+---------------+-----------------+-------+
|
||||
| {$apiKey4} | - | - | Admin |
|
||||
| {$apiKey4->key} | - | - | Admin |
|
||||
+--------------------------------------+---------------+-----------------+-------+
|
||||
|
||||
OUTPUT,
|
||||
|
||||
@@ -140,7 +140,7 @@ class ListShortUrlsCommandTest extends TestCase
|
||||
public static function provideOptionalFlags(): iterable
|
||||
{
|
||||
$apiKey = ApiKey::fromMeta(ApiKeyMeta::fromParams(name: 'my api key'));
|
||||
$key = $apiKey->toString();
|
||||
$key = $apiKey->key;
|
||||
|
||||
yield 'tags only' => [
|
||||
['--show-tags' => true],
|
||||
|
||||
Reference in New Issue
Block a user