mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-12 01:54:41 +08:00
Ensure auto-generated name API keys do not throw duplicated name
This commit is contained in:
@@ -18,12 +18,13 @@ final readonly class ApiKeyMeta
|
||||
private function __construct(
|
||||
public string $key,
|
||||
public string $name,
|
||||
public bool $isNameAutoGenerated,
|
||||
public Chronos|null $expirationDate,
|
||||
public iterable $roleDefinitions,
|
||||
) {
|
||||
}
|
||||
|
||||
public static function empty(): self
|
||||
public static function create(): self
|
||||
{
|
||||
return self::fromParams();
|
||||
}
|
||||
@@ -38,9 +39,10 @@ final readonly class ApiKeyMeta
|
||||
iterable $roleDefinitions = [],
|
||||
): self {
|
||||
$resolvedKey = $key ?? Uuid::uuid4()->toString();
|
||||
$isNameAutoGenerated = empty($name);
|
||||
|
||||
// If a name was not provided, fall back to the key
|
||||
if (empty($name)) {
|
||||
if ($isNameAutoGenerated) {
|
||||
// If the key was auto-generated, fall back to a redacted version of the UUID, otherwise simply use the
|
||||
// plain key as fallback name
|
||||
$name = $key === null
|
||||
@@ -51,6 +53,7 @@ final readonly class ApiKeyMeta
|
||||
return new self(
|
||||
key: $resolvedKey,
|
||||
name: $name,
|
||||
isNameAutoGenerated: $isNameAutoGenerated,
|
||||
expirationDate: $expirationDate,
|
||||
roleDefinitions: $roleDefinitions,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user