diff --git a/src/API/Apps/AppsClient.php b/src/API/Apps/AppsClient.php index bb938c4..a020b7e 100644 --- a/src/API/Apps/AppsClient.php +++ b/src/API/Apps/AppsClient.php @@ -2,6 +2,7 @@ namespace Pagely\AtomicClient\API\Apps; use Pagely\AtomicClient\API\BaseApiClient; +use Psr\Http\Message\ResponseInterface; class AppsClient extends BaseApiClient { @@ -190,10 +191,28 @@ public function remove($accessToken, $appId) ->delete("apps/{$appId}"); } + protected function setWebserverType(string $accessToken, $appId, string $type): ResponseInterface + { + return $this->guzzle($this->getBearerTokenMiddleware($accessToken)) + ->post("apps/{$appId}/server-type", [ + 'json' => ['serverType' => $type], + ]); + } + + public function setWebserverTypeNginx(string $accessToken, int $appId) + { + return $this->setWebserverType($accessToken, $appId, 'nginx'); + } + + public function setWebserverTypeApache(string $accessToken, int $appId) + { + return $this->setWebserverType($accessToken, $appId, 'nginx-apache'); + } + // // Git integration methods // - public function createGitIntegration(string $accessToken, int $appId, string $remoteProvider, string $branch): \Psr\Http\Message\ResponseInterface + public function createGitIntegration(string $accessToken, int $appId, string $remoteProvider, string $branch): ResponseInterface { return $this->guzzle($this->getBearerTokenMiddleware($accessToken)) ->post( @@ -207,13 +226,13 @@ public function createGitIntegration(string $accessToken, int $appId, string $re ); } - public function deleteGitIntegration(string $accessToken, int $appId): \Psr\Http\Message\ResponseInterface + public function deleteGitIntegration(string $accessToken, int $appId): ResponseInterface { return $this->guzzle($this->getBearerTokenMiddleware($accessToken)) ->delete("/apps/{$appId}/git-integration"); } - public function getGitIntegration(string $accessToken, int $appId): \Psr\Http\Message\ResponseInterface + public function getGitIntegration(string $accessToken, int $appId): ResponseInterface { return $this->guzzle($this->getBearerTokenMiddleware($accessToken)) ->get("/apps/{$appId}/git-integration"); diff --git a/src/Command/Apps/AppWebserverCommand.php b/src/Command/Apps/AppWebserverCommand.php new file mode 100644 index 0000000..96835f0 --- /dev/null +++ b/src/Command/Apps/AppWebserverCommand.php @@ -0,0 +1,75 @@ +authClient = $authApi; + $this->api = $apps; + parent::__construct($name); + } + + public function configure() + { + parent::configure(); + $this + ->setDescription('Set webserver type for app') + ->addArgument('appId', InputArgument::REQUIRED, 'App ID') + ->addArgument('type', InputArgument::REQUIRED, 'nginx or apache') + ; + $this->addOauthOptions(); + } + + public function execute(InputInterface $input, OutputInterface $output) + { + $appId = $input->getArgument('appId'); + $serverType = $input->getArgument('type'); + $token = $this->token->token; + + try { + switch ($serverType) { + case 'apache': + $result = $this->api->setWebserverTypeApache($token, $appId); + break; + case 'nginx': + $result = $this->api->setWebserverTypeNginx($token, $appId); + break; + default: + $output->writeln("Unknown server type: {$serverType} - must be apache or nginx"); + return 1; + } + } catch (ClientException $e) { + $output->writeln("{$e->getMessage()}"); + $output->writeln($e->getResponse()->getBody()->getContents()); + return 1; + } + + $output->writeln( + json_encode( + json_decode( + $result->getBody()->getContents() + ), + JSON_PRETTY_PRINT + ) + ); + return 0; + } +}