mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-08 16:23:12 +08:00
Created new env var to programatically provide an initial API key
This commit is contained in:
@@ -23,16 +23,14 @@ class ApiKey extends AbstractEntity
|
||||
private bool $enabled;
|
||||
/** @var Collection|ApiKeyRole[] */
|
||||
private Collection $roles;
|
||||
private ?string $name;
|
||||
private ?string $name = null;
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
private function __construct(?string $name = null, ?Chronos $expirationDate = null)
|
||||
private function __construct(?string $key = null)
|
||||
{
|
||||
$this->key = Uuid::uuid4()->toString();
|
||||
$this->expirationDate = $expirationDate;
|
||||
$this->name = $name;
|
||||
$this->key = $key ?? Uuid::uuid4()->toString();
|
||||
$this->enabled = true;
|
||||
$this->roles = new ArrayCollection();
|
||||
}
|
||||
@@ -44,7 +42,10 @@ class ApiKey extends AbstractEntity
|
||||
|
||||
public static function fromMeta(ApiKeyMeta $meta): self
|
||||
{
|
||||
$apiKey = new self($meta->name, $meta->expirationDate);
|
||||
$apiKey = self::create();
|
||||
$apiKey->name = $meta->name;
|
||||
$apiKey->expirationDate = $meta->expirationDate;
|
||||
|
||||
foreach ($meta->roleDefinitions as $roleDefinition) {
|
||||
$apiKey->registerRole($roleDefinition);
|
||||
}
|
||||
@@ -52,6 +53,11 @@ class ApiKey extends AbstractEntity
|
||||
return $apiKey;
|
||||
}
|
||||
|
||||
public static function fromKey(string $key): self
|
||||
{
|
||||
return new self($key);
|
||||
}
|
||||
|
||||
public function getExpirationDate(): ?Chronos
|
||||
{
|
||||
return $this->expirationDate;
|
||||
|
||||
Reference in New Issue
Block a user