Skip to content

Commit

Permalink
correctly transform eggs that use inheritance
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy132 committed Jan 4, 2024
1 parent f0489f6 commit 9d2f426
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions app/Transformers/Api/Application/EggTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,15 @@ public function getResourceName(): string
*/
public function transform(Egg $model): array
{
$files = json_decode($model->config_files, true, 512, JSON_THROW_ON_ERROR);
$model->loadMissing('configFrom');

$files = json_decode($model->inherit_config_files, true, 512, JSON_THROW_ON_ERROR);
if (empty($files)) {
$files = new \stdClass();
}

$model->loadMissing('scriptFrom');

return [
'id' => $model->id,
'uuid' => $model->uuid,
Expand All @@ -60,18 +64,18 @@ public function transform(Egg $model): array
'docker_images' => $model->docker_images,
'config' => [
'files' => $files,
'startup' => json_decode($model->config_startup, true),
'stop' => $model->config_stop,
'logs' => json_decode($model->config_logs, true),
'startup' => json_decode($model->inherit_config_startup, true),
'stop' => $model->inherit_config_stop,
'logs' => json_decode($model->inherit_config_logs, true),
'file_denylist' => $model->file_denylist,
'extends' => $model->config_from,
],
'startup' => $model->startup,
'script' => [
'privileged' => $model->script_is_privileged,
'install' => $model->script_install,
'entry' => $model->script_entry,
'container' => $model->script_container,
'install' => $model->copy_script_install,
'entry' => $model->copy_script_entry,
'container' => $model->copy_script_container,
'extends' => $model->copy_script_from,
],
$model->getCreatedAtColumn() => $this->formatTimestamp($model->created_at),
Expand Down Expand Up @@ -114,6 +118,8 @@ public function includeServers(Egg $model): Collection|NullResource
/**
* Include more detailed information about the configuration if this Egg is
* extending another.
*
* TODO: since the config info is already in the base response this include could be removed (in v2?)
*/
public function includeConfig(Egg $model): Item|NullResource
{
Expand All @@ -136,6 +142,8 @@ public function includeConfig(Egg $model): Item|NullResource
/**
* Include more detailed information about the script configuration if the
* Egg is extending another.
*
* TODO: since the script info is already in the base response this include could be removed (in v2?)
*/
public function includeScript(Egg $model): Item|NullResource
{
Expand Down

0 comments on commit 9d2f426

Please sign in to comment.