Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions legacy/src/Command/Environment/EnvironmentDeployTypeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

namespace Platformsh\Cli\Command\Environment;

use GuzzleHttp\Utils;
use Platformsh\Cli\Selector\SelectorConfig;
use Symfony\Component\Console\Attribute\AsCommand;
use Platformsh\Cli\Service\ActivityMonitor;
use Platformsh\Cli\Service\Api;
use Platformsh\Cli\Service\QuestionHelper;
use Platformsh\Cli\Selector\Selector;
use Platformsh\Cli\Command\CommandBase;
use Platformsh\Client\Model\Activity;
use Platformsh\Client\Model\Result;
use Platformsh\Client\Model\Settings;
use Symfony\Component\Console\Exception\InvalidArgumentException;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -18,7 +22,7 @@
#[AsCommand(name: 'environment:deploy:type', description: 'Show or set the environment deployment type')]
class EnvironmentDeployTypeCommand extends CommandBase
{
public function __construct(private readonly ActivityMonitor $activityMonitor, private readonly QuestionHelper $questionHelper, private readonly Selector $selector)
public function __construct(private readonly ActivityMonitor $activityMonitor, private readonly Api $api, private readonly QuestionHelper $questionHelper, private readonly Selector $selector)
{
parent::__construct();
}
Expand Down Expand Up @@ -89,7 +93,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}
}

$result = $settings->update(['enable_manual_deployments' => $newType === 'manual']);
// Update the setting with a direct PATCH request. The settings API
// resource does not advertise an "edit" operation link, so the client's
// update() method (which relies on that operation) cannot be used.
$httpClient = $this->api->getHttpClient();
$response = $httpClient->request('PATCH', $settings->getUri(), [
'json' => ['enable_manual_deployments' => $newType === 'manual'],
]);
$result = new Result((array) Utils::jsonDecode((string) $response->getBody(), true), $settings->getUri(), $httpClient, Settings::class);

if ($result->getActivities() && $this->activityMonitor->shouldWait($input)) {
$success = $this->activityMonitor->waitMultiple($result->getActivities(), $selection->getProject());
Expand Down
9 changes: 5 additions & 4 deletions pkg/mockapi/environments.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,11 @@ func (h *Handler) handleGetEnvironmentSettings(w http.ResponseWriter, req *http.
if env.settings != nil {
settings = env.settings
}
// The real API only exposes a "self" link on the settings resource; it does
// not advertise an "#edit" operation, so the client cannot run an "edit"
// operation against it.
settings["_links"] = MakeHALLinks(
"self=/projects/"+env.Project+"/environments/"+env.ID+"/settings",
"#edit=/projects/"+env.Project+"/environments/"+env.ID+"/settings",
"self=/projects/" + env.Project + "/environments/" + env.ID + "/settings",
)

_ = json.NewEncoder(w).Encode(settings)
Expand All @@ -101,8 +103,7 @@ func (h *Handler) handleSetEnvironmentSettings(w http.ResponseWriter, req *http.
env.settings[k] = v
}
settings["_links"] = MakeHALLinks(
"self=/projects/"+env.Project+"/environments/"+env.ID+"/settings",
"#edit=/projects/"+env.Project+"/environments/"+env.ID+"/settings",
"self=/projects/" + env.Project + "/environments/" + env.ID + "/settings",
)

h.environments[env.ID] = env
Expand Down
Loading