From 5c724dbdb5baab4983c6161aeae667e7b3cb7191 Mon Sep 17 00:00:00 2001 From: sebprt Date: Thu, 26 Oct 2023 14:40:51 +0200 Subject: [PATCH] Check the version used in the file configuration --- src/Cloud/Console/Command/CreateCommand.php | 14 +++++++------- src/Cloud/Console/Command/RemoveCommand.php | 14 +++++++------- src/Cloud/Console/Command/UpdateCommand.php | 14 +++++++------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/Cloud/Console/Command/CreateCommand.php b/src/Cloud/Console/Command/CreateCommand.php index 38c624b0..1c2071ba 100644 --- a/src/Cloud/Console/Command/CreateCommand.php +++ b/src/Cloud/Console/Command/CreateCommand.php @@ -96,6 +96,12 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O return self::FAILURE; } + if (!\array_key_exists('version', $configuration)) { + $style->warning('The current version of your configuration does not allow you to use Cloud commands. Please update your configuration to version 0.3.'); + + return self::INVALID; + } + $auth = new Satellite\Cloud\Auth(); try { @@ -130,19 +136,13 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O $context = new Satellite\Cloud\Context($client, $auth, $url); - match ($type) { - ArgumentType::PIPELINE->value => $satellites = !\array_key_exists('version', $configuration) ? $configuration['satellite']['pipeline'] : $configuration['satellites'], - ArgumentType::WORKFLOW->value => $satellites = !\array_key_exists('version', $configuration) ? $configuration['satellite']['workflow'] : $configuration['satellites'], - default => throw new \InvalidArgumentException('Invalid type provided.'), - }; - $instance = match ($type) { ArgumentType::PIPELINE->value => new Satellite\Cloud\Pipeline($context), ArgumentType::WORKFLOW->value => new Satellite\Cloud\Workflow($context), default => throw new \InvalidArgumentException('Invalid type provided.'), }; - foreach ($satellites as $satellite) { + foreach ($configuration['satellites'] as $satellite) { foreach ($instance->create($instance::fromLegacyConfiguration($satellite)) as $command) { $bus->push($command); } diff --git a/src/Cloud/Console/Command/RemoveCommand.php b/src/Cloud/Console/Command/RemoveCommand.php index 4637705a..8e9ad494 100644 --- a/src/Cloud/Console/Command/RemoveCommand.php +++ b/src/Cloud/Console/Command/RemoveCommand.php @@ -93,6 +93,12 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O return self::FAILURE; } + if (!\array_key_exists('version', $configuration)) { + $style->warning('The current version of your configuration does not allow you to use Cloud commands. Please update your configuration to version 0.3.'); + + return self::INVALID; + } + $auth = new Satellite\Cloud\Auth(); try { $token = $auth->token($url); @@ -125,19 +131,13 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O } $context = new Satellite\Cloud\Context($client, $auth, $url); - match ($type) { - ArgumentType::PIPELINE->value => $model = Satellite\Cloud\Pipeline::fromApiWithCode($client, array_key_first($configuration['satellites']), $configuration['satellites']), - ArgumentType::WORKFLOW->value => $model = Satellite\Cloud\Workflow::fromApiWithCode($client, array_key_first($configuration['satellites'])), - default => throw new \InvalidArgumentException('Invalid type provided.'), - }; - $instance = match ($type) { ArgumentType::PIPELINE->value => new Satellite\Cloud\Pipeline($context), ArgumentType::WORKFLOW->value => new Satellite\Cloud\Workflow($context), default => throw new \InvalidArgumentException('Invalid type provided.'), }; - foreach ($instance->remove($model->id()) as $command) { + foreach ($instance->remove($instance::fromApiWithCode($client, array_key_first($configuration['satellites']))->id()) as $command) { $bus->push($command); } diff --git a/src/Cloud/Console/Command/UpdateCommand.php b/src/Cloud/Console/Command/UpdateCommand.php index 5035681c..669d4a2f 100644 --- a/src/Cloud/Console/Command/UpdateCommand.php +++ b/src/Cloud/Console/Command/UpdateCommand.php @@ -96,6 +96,12 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O return self::FAILURE; } + if (!\array_key_exists('version', $configuration)) { + $style->warning('The current version of your configuration does not allow you to use Cloud commands. Please update your configuration to version 0.3.'); + + return self::INVALID; + } + $auth = new Satellite\Cloud\Auth(); try { $token = $auth->token($url); @@ -128,19 +134,13 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O } $context = new Satellite\Cloud\Context($client, $auth, $url); - match ($type) { - ArgumentType::PIPELINE->value => $model = Satellite\Cloud\Pipeline::fromApiWithCode($client, array_key_first($configuration['satellites']), $configuration['satellite']['pipeline']), - ArgumentType::WORKFLOW->value => $model = Satellite\Cloud\Workflow::fromApiWithCode($client, array_key_first($configuration['satellites'])), - default => throw new \InvalidArgumentException('Invalid type provided.'), - }; - $instance = match ($type) { ArgumentType::PIPELINE->value => new Satellite\Cloud\Pipeline($context), ArgumentType::WORKFLOW->value => new Satellite\Cloud\Workflow($context), default => throw new \InvalidArgumentException('Invalid type provided.'), }; - foreach ($instance->update($model, $instance::fromLegacyConfiguration($configuration['satellite'])) as $command) { + foreach ($instance->update($instance::fromApiWithCode($client, array_key_first($configuration['satellites'])), $instance::fromLegacyConfiguration($configuration['satellite'])) as $command) { $bus->push($command); }