Skip to content

Commit

Permalink
Check the version used in the file configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
sebprt committed Oct 26, 2023
1 parent 14c37c5 commit 5c724db
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
14 changes: 7 additions & 7 deletions src/Cloud/Console/Command/CreateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
Expand Down
14 changes: 7 additions & 7 deletions src/Cloud/Console/Command/RemoveCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

Expand Down
14 changes: 7 additions & 7 deletions src/Cloud/Console/Command/UpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 5c724db

Please sign in to comment.