Skip to content

Commit

Permalink
Made that the Remove and Update commands in the Cloud context can be …
Browse files Browse the repository at this point in the history
…used with several satellites in a single file
  • Loading branch information
sebprt committed Jan 22, 2024
1 parent 85aaa1f commit ea5204c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
20 changes: 12 additions & 8 deletions src/Cloud/Console/Command/RemoveCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,18 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O
}

$context = new Satellite\Cloud\Context($client, $auth, $url);
$instance = match (true) {
\array_key_exists('pipeline', $configuration) => new Satellite\Cloud\Pipeline($context),
\array_key_exists('workflow', $configuration) => new Satellite\Cloud\Workflow($context),
default => throw new \RuntimeException('Invalid runtime satellite configuration.'),
};

foreach ($instance->remove($instance::fromApiWithCode($client, array_key_first($configuration['satellites']))->id()) as $command) {
$bus->push($command);

foreach ($configuration['satellites'] as $code => $satellite) {
$satellite['code'] = $code;
$instance = match (true) {
\array_key_exists('pipeline', $satellite) => new Satellite\Cloud\Pipeline($context),
\array_key_exists('workflow', $satellite) => new Satellite\Cloud\Workflow($context),
default => throw new \RuntimeException('Invalid runtime satellite configuration.'),
};

foreach ($instance->remove($instance::fromApiWithCode($client, array_key_first($configuration['satellites']))->id()) as $command) {
$bus->push($command);
}
}

$bus->execute();
Expand Down
20 changes: 12 additions & 8 deletions src/Cloud/Console/Command/UpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,18 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O
}

$context = new Satellite\Cloud\Context($client, $auth, $url);
$instance = match (true) {
\array_key_exists('pipeline', $configuration) => new Satellite\Cloud\Pipeline($context),
\array_key_exists('workflow', $configuration) => new Satellite\Cloud\Workflow($context),
default => throw new \RuntimeException('Invalid runtime satellite configuration.'),
};

foreach ($instance->update($instance::fromApiWithCode($client, array_key_first($configuration['satellites'])), $instance::fromLegacyConfiguration($configuration['satellite'])) as $command) {
$bus->push($command);

foreach ($configuration['satellites'] as $code => $satellite) {
$satellite['code'] = $code;
$instance = match (true) {
\array_key_exists('pipeline', $satellite) => new Satellite\Cloud\Pipeline($context),
\array_key_exists('workflow', $satellite) => new Satellite\Cloud\Workflow($context),
default => throw new \RuntimeException('Invalid runtime satellite configuration.'),
};

foreach ($instance->update($instance::fromApiWithCode($client, array_key_first($configuration['satellites'])), $instance::fromLegacyConfiguration($configuration['satellite'])) as $command) {
$bus->push($command);
}
}

$bus->execute();
Expand Down

0 comments on commit ea5204c

Please sign in to comment.