Update logic for server transfer controller
This commit is contained in:
parent
6c61577699
commit
2ee08a1a3d
6 changed files with 178 additions and 131 deletions
|
@ -102,7 +102,7 @@ class EggConfigurationService
|
|||
{
|
||||
// Get the legacy configuration structure for the server so that we
|
||||
// can property map the egg placeholders to values.
|
||||
$structure = $this->configurationStructureService->handle($server, true);
|
||||
$structure = $this->configurationStructureService->handle($server, [], true);
|
||||
|
||||
$response = [];
|
||||
// Normalize the output of the configuration for the new Wings Daemon to more
|
||||
|
|
|
@ -22,6 +22,11 @@ class NodeJWTService
|
|||
*/
|
||||
private $expiresAt;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
private $subject;
|
||||
|
||||
/**
|
||||
* Set the claims to include in this JWT.
|
||||
*
|
||||
|
@ -35,6 +40,10 @@ class NodeJWTService
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \DateTimeInterface $date
|
||||
* @return $this
|
||||
*/
|
||||
public function setExpiresAt(DateTimeInterface $date)
|
||||
{
|
||||
$this->expiresAt = $date->getTimestamp();
|
||||
|
@ -42,20 +51,32 @@ class NodeJWTService
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $subject
|
||||
* @return $this
|
||||
*/
|
||||
public function setSubject(string $subject)
|
||||
{
|
||||
$this->subject = $subject;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a new JWT for a given node.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Node $node
|
||||
* @param string|null $identifiedBy
|
||||
* @param string $algo
|
||||
* @return \Lcobucci\JWT\Token
|
||||
*/
|
||||
public function handle(Node $node, string $identifiedBy)
|
||||
public function handle(Node $node, string $identifiedBy, string $algo = 'md5')
|
||||
{
|
||||
$signer = new Sha256;
|
||||
|
||||
$builder = (new Builder)->issuedBy(config('app.url'))
|
||||
->permittedFor($node->getConnectionAddress())
|
||||
->identifiedBy(md5($identifiedBy), true)
|
||||
->identifiedBy(hash($algo, $identifiedBy), true)
|
||||
->issuedAt(CarbonImmutable::now()->getTimestamp())
|
||||
->canOnlyBeUsedAfter(CarbonImmutable::now()->subMinutes(5)->getTimestamp());
|
||||
|
||||
|
@ -63,6 +84,10 @@ class NodeJWTService
|
|||
$builder = $builder->expiresAt($this->expiresAt);
|
||||
}
|
||||
|
||||
if (!empty($this->subject)) {
|
||||
$builder = $builder->relatedTo($this->subject, true);
|
||||
}
|
||||
|
||||
foreach ($this->claims as $key => $value) {
|
||||
$builder = $builder->withClaim($key, $value);
|
||||
}
|
||||
|
|
|
@ -29,14 +29,25 @@ class ServerConfigurationStructureService
|
|||
* daemon, if you modify the structure eggs will break unexpectedly.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Server $server
|
||||
* @param array $override
|
||||
* @param bool $legacy deprecated
|
||||
* @return array
|
||||
*/
|
||||
public function handle(Server $server, bool $legacy = false): array
|
||||
public function handle(Server $server, array $override = [], bool $legacy = false): array
|
||||
{
|
||||
return $legacy ?
|
||||
$this->returnLegacyFormat($server)
|
||||
: $this->returnCurrentFormat($server);
|
||||
$clone = $server;
|
||||
// If any overrides have been set on this call make sure to update them on the
|
||||
// cloned instance so that the configuration generated uses them.
|
||||
if (!empty($override)) {
|
||||
$clone = $server->fresh();
|
||||
foreach ($override as $key => $value) {
|
||||
$clone->setAttribute($key, $value);
|
||||
}
|
||||
}
|
||||
|
||||
return $legacy
|
||||
? $this->returnLegacyFormat($clone)
|
||||
: $this->returnCurrentFormat($clone);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -105,12 +116,12 @@ class ServerConfigurationStructureService
|
|||
})->toArray(),
|
||||
'env' => $this->environment->handle($server),
|
||||
'oom_disabled' => $server->oom_disabled,
|
||||
'memory' => (int) $server->memory,
|
||||
'swap' => (int) $server->swap,
|
||||
'io' => (int) $server->io,
|
||||
'cpu' => (int) $server->cpu,
|
||||
'memory' => (int)$server->memory,
|
||||
'swap' => (int)$server->swap,
|
||||
'io' => (int)$server->io,
|
||||
'cpu' => (int)$server->cpu,
|
||||
'threads' => $server->threads,
|
||||
'disk' => (int) $server->disk,
|
||||
'disk' => (int)$server->disk,
|
||||
'image' => $server->image,
|
||||
],
|
||||
'service' => [
|
||||
|
@ -118,7 +129,7 @@ class ServerConfigurationStructureService
|
|||
'skip_scripts' => $server->skip_scripts,
|
||||
],
|
||||
'rebuild' => false,
|
||||
'suspended' => (int) $server->suspended,
|
||||
'suspended' => (int)$server->suspended,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue