Final adjustments to Daemon <-> Panel communication change

This commit is contained in:
Dane Everitt 2017-09-24 21:12:30 -05:00
parent 8e2b77dc1e
commit 7d1c233c49
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
32 changed files with 528 additions and 538 deletions

View file

@ -25,21 +25,19 @@
namespace Pterodactyl\Services\DaemonKeys;
use Carbon\Carbon;
use Pterodactyl\Models\DaemonKey;
use Webmozart\Assert\Assert;
use Illuminate\Contracts\Config\Repository as ConfigRepository;
use Pterodactyl\Contracts\Repository\DaemonKeyRepositoryInterface;
class DaemonKeyUpdateService
{
const INTERNAL_TOKEN_IDENTIFIER = 'i_';
/**
* @var \Carbon\Carbon
*/
protected $carbon;
/**
* @var
* @var \Illuminate\Contracts\Config\Repository
*/
protected $config;
@ -68,7 +66,7 @@ class DaemonKeyUpdateService
/**
* Update a daemon key to expire the previous one.
*
* @param \Pterodactyl\Models\DaemonKey|int $key
* @param int $key
* @return string
*
* @throws \RuntimeException
@ -77,15 +75,12 @@ class DaemonKeyUpdateService
*/
public function handle($key)
{
if ($key instanceof DaemonKey) {
$key = $key->id;
}
$secret = self::INTERNAL_TOKEN_IDENTIFIER . str_random(40);
Assert::integerish($key, 'First argument passed to handle must be an integer, received %s.');
$secret = DaemonKeyRepositoryInterface::INTERNAL_KEY_IDENTIFIER . str_random(40);
$this->repository->withoutFresh()->update($key, [
'secret' => $secret,
'expires_at' => $this->carbon->now()->addMinutes($this->config->get('pterodactyl.api.key_expire_time')),
'expires_at' => $this->carbon->now()->addMinutes($this->config->get('pterodactyl.api.key_expire_time'))->toDateTimeString(),
]);
return $secret;