diff --git a/.gitignore b/.gitignore index 20d9dbd..e7ce9df 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ /.vscode /.vagrant .phpunit.result.cache +ploi.yml diff --git a/app/Commands/SshCommand.php b/app/Commands/SshCommand.php new file mode 100644 index 0000000..b7939d0 --- /dev/null +++ b/app/Commands/SshCommand.php @@ -0,0 +1,39 @@ +ensureHasToken(); + $this->ensureHasPloiConfiguration(); + + $server = $ploi->getServer($configuration->get('server')); + $site = $ploi->getSite($configuration->get('server'), $configuration->get('site')); + $user = $this->argument('user') ?? 'ploi'; + + $this->info('Establishing SSH connection...'); + + passthru($this->buildCommand($server, $site, $user)); + } + + protected function buildCommand($server, $site, $user) + { + return sprintf('ssh -t %s@%s "cd %s; bash --login"', $user, $server['ip_address'], $site['domain'] . $site['project_root']); + } +} diff --git a/app/Support/Ploi.php b/app/Support/Ploi.php index ee7b6c8..e73ec44 100644 --- a/app/Support/Ploi.php +++ b/app/Support/Ploi.php @@ -27,6 +27,11 @@ public function getServers() return $response['data']; } + public function getServer($server) + { + return Http::withToken($this->token)->get(self::$BASE_URL . "servers/{$server}")['data']; + } + public function getServerProviders() { return Http::withToken($this->token)->get(self::$BASE_URL . "user/server-providers")['data']; @@ -37,6 +42,11 @@ public function getSites($server) return Http::withToken($this->token)->get(self::$BASE_URL . "servers/{$server}/sites?per_page=50")['data']; } + public function getSite($server, $site) + { + return Http::withToken($this->token)->get(self::$BASE_URL . "servers/{$server}/sites/{$site}")['data']; + } + public function createSite($server, $rootDomain, $webDir, $systemUser): int { $response = Http::withToken($this->token)->post(self::$BASE_URL . "servers/{$server}/sites", [