Update interface to begin change to seperate account API keys and application keys
Main difference is permissions, cleaner UI for normal users, and account keys use permissions assigned to servers and subusers while application keys use R/W ACLs stored in the key table.
This commit is contained in:
parent
28ebd18f57
commit
f9fc3f4370
18 changed files with 312 additions and 298 deletions
|
@ -13,6 +13,11 @@ class KeyCreationService
|
|||
*/
|
||||
private $encrypter;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $keyType = ApiKey::TYPE_NONE;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\ApiKeyRepositoryInterface
|
||||
*/
|
||||
|
@ -30,23 +35,43 @@ class KeyCreationService
|
|||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the type of key that should be created. By default an orphaned key will be
|
||||
* created. These keys cannot be used for anything, and will not render in the UI.
|
||||
*
|
||||
* @param int $type
|
||||
* @return \Pterodactyl\Services\Api\KeyCreationService
|
||||
*/
|
||||
public function setKeyType(int $type)
|
||||
{
|
||||
$this->keyType = $type;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new API key for the Panel using the permissions passed in the data request.
|
||||
* This will automatically generate an identifer and an encrypted token that are
|
||||
* stored in the database.
|
||||
*
|
||||
* @param array $data
|
||||
* @param array $permissions
|
||||
* @return \Pterodactyl\Models\ApiKey
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
*/
|
||||
public function handle(array $data): ApiKey
|
||||
public function handle(array $data, array $permissions = []): ApiKey
|
||||
{
|
||||
$data = array_merge($data, [
|
||||
'key_type' => $this->keyType,
|
||||
'identifier' => str_random(ApiKey::IDENTIFIER_LENGTH),
|
||||
'token' => $this->encrypter->encrypt(str_random(ApiKey::KEY_LENGTH)),
|
||||
]);
|
||||
|
||||
if ($this->keyType === ApiKey::TYPE_APPLICATION) {
|
||||
$data = array_merge($data, $permissions);
|
||||
}
|
||||
|
||||
$instance = $this->repository->create($data, true, true);
|
||||
|
||||
return $instance;
|
||||
|
|
Reference in a new issue