Compatibility with Http-facade instead of Guzzle
This commit is contained in:
@@ -2,15 +2,15 @@
|
||||
|
||||
namespace App\Jobs\Sites;
|
||||
|
||||
use Throwable;
|
||||
use App\Models\Site;
|
||||
use App\Traits\HasPloi;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Arr;
|
||||
use Throwable;
|
||||
|
||||
class CreateSite implements ShouldQueue
|
||||
{
|
||||
|
||||
@@ -89,6 +89,14 @@ class Ploi
|
||||
throw new Exception('Invalid method type');
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a temporary method that was necessary for the switch from the Guzzle client to the Http facade.
|
||||
* We _should not_ need this, but it feels safer to keep this fallback code around for now.
|
||||
*/
|
||||
if (count($options) === 1 && array_key_exists('body', $options)) {
|
||||
$options = is_string($options['body']) ? json_decode($options['body']) : $options['body'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Because we're calling the method dynamically PHPStorm doesn't
|
||||
* know that we're getting a response back, so we manually
|
||||
|
||||
@@ -29,9 +29,7 @@ class Alias extends Resource
|
||||
public function create(array $aliases)
|
||||
{
|
||||
$options = [
|
||||
'body' => json_encode([
|
||||
'aliases' => $aliases,
|
||||
]),
|
||||
'aliases' => $aliases,
|
||||
];
|
||||
|
||||
return $this->getPloi()->makeAPICall($this->getEndpoint(), 'post', $options);
|
||||
@@ -39,6 +37,6 @@ class Alias extends Resource
|
||||
|
||||
public function delete(string $alias)
|
||||
{
|
||||
return $this->getPloi()->makeAPICall($this->getEndpoint() . '/' . $alias , 'delete');
|
||||
return $this->getPloi()->makeAPICall($this->getEndpoint() . '/' . $alias, 'delete');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ use App\Services\Ploi\Exceptions\Http\NotValid;
|
||||
class App extends Resource
|
||||
{
|
||||
private $server;
|
||||
|
||||
private $site;
|
||||
|
||||
public function __construct(Server $server, Site $site, int $id = null)
|
||||
@@ -51,9 +52,7 @@ class App extends Resource
|
||||
|
||||
// Set the options
|
||||
$options = [
|
||||
'body' => json_encode([
|
||||
'create_database' => Arr::get($options, 'create_database', false)
|
||||
]),
|
||||
'create_database' => Arr::get($options, 'create_database', false),
|
||||
];
|
||||
|
||||
try {
|
||||
|
||||
@@ -8,6 +8,7 @@ use App\Services\Ploi\Exceptions\Http\NotValid;
|
||||
class Certificate extends Resource
|
||||
{
|
||||
private $server;
|
||||
|
||||
private $site;
|
||||
|
||||
public function __construct(Server $server, Site $site, int $id = null)
|
||||
@@ -50,11 +51,9 @@ class Certificate extends Resource
|
||||
|
||||
// Set the options
|
||||
$options = [
|
||||
'body' => json_encode([
|
||||
'type' => $type,
|
||||
'certificate' => $certificate,
|
||||
'private' => $private,
|
||||
]),
|
||||
'type' => $type,
|
||||
'certificate' => $certificate,
|
||||
'private' => $private,
|
||||
];
|
||||
|
||||
// Build the endpoint
|
||||
|
||||
@@ -48,11 +48,9 @@ class Cronjob extends Resource
|
||||
|
||||
// Set the options
|
||||
$options = [
|
||||
'body' => json_encode([
|
||||
'command' => $command,
|
||||
'frequency' => $frequency,
|
||||
'user' => $user,
|
||||
]),
|
||||
'command' => $command,
|
||||
'frequency' => $frequency,
|
||||
'user' => $user,
|
||||
];
|
||||
|
||||
// Build the endpoint
|
||||
|
||||
@@ -48,11 +48,9 @@ class Daemon extends Resource
|
||||
|
||||
// Set the options
|
||||
$options = [
|
||||
'body' => json_encode([
|
||||
'command' => $command,
|
||||
'system_user' => $systemUser,
|
||||
'processes' => $processes
|
||||
]),
|
||||
'command' => $command,
|
||||
'system_user' => $systemUser,
|
||||
'processes' => $processes,
|
||||
];
|
||||
|
||||
// Build the endpoint
|
||||
|
||||
@@ -48,11 +48,9 @@ class Database extends Resource
|
||||
|
||||
// Set the options
|
||||
$options = [
|
||||
'body' => json_encode([
|
||||
'name' => $name,
|
||||
'user' => $user,
|
||||
'password' => $password,
|
||||
]),
|
||||
'name' => $name,
|
||||
'user' => $user,
|
||||
'password' => $password,
|
||||
];
|
||||
|
||||
// Build the endpoint
|
||||
|
||||
@@ -54,9 +54,7 @@ class Deployment extends Resource
|
||||
}
|
||||
|
||||
$options = [
|
||||
'body' => json_encode([
|
||||
'deploy_script' => $script
|
||||
]),
|
||||
'deploy_script' => $script,
|
||||
];
|
||||
|
||||
$this->setEndpoint($this->getEndpoint() . '/deploy/script');
|
||||
|
||||
@@ -48,12 +48,10 @@ class NetworkRule extends Resource
|
||||
|
||||
// Set the options
|
||||
$options = [
|
||||
'body' => json_encode([
|
||||
'name' => $name,
|
||||
'port' => $port,
|
||||
'type' => $type,
|
||||
'from_ip_address' => $fromIpAddress,
|
||||
]),
|
||||
'name' => $name,
|
||||
'port' => $port,
|
||||
'type' => $type,
|
||||
'from_ip_address' => $fromIpAddress,
|
||||
];
|
||||
|
||||
// Build the endpoint
|
||||
|
||||
@@ -56,14 +56,12 @@ class Queue extends Resource
|
||||
|
||||
// Set the options
|
||||
$options = [
|
||||
'body' => json_encode([
|
||||
'connection' => $connection,
|
||||
'queue' => $queue,
|
||||
'maximum_seconds' => $maximumSeconds,
|
||||
'sleep' => $sleep,
|
||||
'processes' => $processes,
|
||||
'maximum_tries' => $maximumTries
|
||||
]),
|
||||
'connection' => $connection,
|
||||
'queue' => $queue,
|
||||
'maximum_seconds' => $maximumSeconds,
|
||||
'sleep' => $sleep,
|
||||
'processes' => $processes,
|
||||
'maximum_tries' => $maximumTries
|
||||
];
|
||||
|
||||
// Build the endpoint
|
||||
|
||||
@@ -8,6 +8,7 @@ use App\Services\Ploi\Exceptions\Http\NotValid;
|
||||
class Redirect extends Resource
|
||||
{
|
||||
private $server;
|
||||
|
||||
private $site;
|
||||
|
||||
public function __construct(Server $server, Site $site, int $id = null)
|
||||
@@ -50,11 +51,9 @@ class Redirect extends Resource
|
||||
|
||||
// Set the options
|
||||
$options = [
|
||||
'body' => json_encode([
|
||||
'redirect_from' => $redirectFrom,
|
||||
'redirect_to' => $redirectTo,
|
||||
'type' => $type,
|
||||
]),
|
||||
'redirect_from' => $redirectFrom,
|
||||
'redirect_to' => $redirectTo,
|
||||
'type' => $type,
|
||||
];
|
||||
|
||||
// Build the endpoint
|
||||
|
||||
@@ -50,7 +50,7 @@ class Server extends Resource
|
||||
$this->setId($id);
|
||||
}
|
||||
|
||||
if (!$this->getId()) {
|
||||
if (! $this->getId()) {
|
||||
throw new RequiresId('No server ID set');
|
||||
}
|
||||
|
||||
@@ -75,16 +75,14 @@ class Server extends Resource
|
||||
|
||||
// Set the options
|
||||
$options = [
|
||||
'body' => json_encode([
|
||||
'name' => $name,
|
||||
'plan' => $plan,
|
||||
'region' => $region,
|
||||
'credential' => $provider,
|
||||
'type' => $type,
|
||||
'database_type' => $databaseType,
|
||||
'webserver_type' => $webserverType,
|
||||
'php_version' => $phpVersion
|
||||
]),
|
||||
'name' => $name,
|
||||
'plan' => $plan,
|
||||
'region' => $region,
|
||||
'credential' => $provider,
|
||||
'type' => $type,
|
||||
'database_type' => $databaseType,
|
||||
'webserver_type' => $webserverType,
|
||||
'php_version' => $phpVersion,
|
||||
];
|
||||
|
||||
// Make the request
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
namespace App\Services\Ploi\Resources;
|
||||
|
||||
use App\Services\Ploi\Exceptions\Http\NotValid;
|
||||
use stdClass;
|
||||
use Exception;
|
||||
use App\Services\Ploi\Exceptions\Http\NotValid;
|
||||
use Services\Ploi\Exceptions\Resource\RequiresId;
|
||||
use Services\Ploi\Exceptions\Resource\Server\Site\DomainAlreadyExists;
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
* Class Site
|
||||
@@ -75,13 +75,11 @@ class Site extends Resource
|
||||
|
||||
// Set the options
|
||||
$options = [
|
||||
'body' => json_encode([
|
||||
'root_domain' => $domain,
|
||||
'web_directory' => $webDirectory,
|
||||
'project_root' => $projectRoot,
|
||||
'system_user' => $systemUser,
|
||||
'system_user_password' => $systemUserPassword
|
||||
]),
|
||||
'root_domain' => $domain,
|
||||
'web_directory' => $webDirectory,
|
||||
'project_root' => $projectRoot,
|
||||
'system_user' => $systemUser,
|
||||
'system_user_password' => $systemUserPassword,
|
||||
];
|
||||
|
||||
// Build the endpoint
|
||||
@@ -93,7 +91,7 @@ class Site extends Resource
|
||||
} catch (NotValid $exception) {
|
||||
$errors = json_decode($exception->getMessage())->errors;
|
||||
|
||||
if (!empty($errors->root_domain)
|
||||
if (! empty($errors->root_domain)
|
||||
&& $errors->root_domain[0] === 'The root domain has already been taken.') {
|
||||
throw new DomainAlreadyExists($domain . ' already exists!');
|
||||
}
|
||||
@@ -104,7 +102,7 @@ class Site extends Resource
|
||||
}
|
||||
|
||||
// TODO: Debugging purposes
|
||||
if (!$response->getJson() || !isset($response->getJson()->data)) {
|
||||
if (! $response->getJson() || ! isset($response->getJson()->data)) {
|
||||
throw new Exception($response->getJson()->error ?? 'Unknown error has occured');
|
||||
}
|
||||
|
||||
@@ -134,7 +132,7 @@ class Site extends Resource
|
||||
$this->setId($id);
|
||||
}
|
||||
|
||||
if (!$this->getId()) {
|
||||
if (! $this->getId()) {
|
||||
throw new RequiresId('No Site ID set');
|
||||
}
|
||||
|
||||
@@ -143,7 +141,7 @@ class Site extends Resource
|
||||
$response = $this->getPloi()->makeAPICall($this->getEndpoint());
|
||||
|
||||
// Wrap the logs if they're not already wrapped
|
||||
if (!is_array($response->getJson()->data)) {
|
||||
if (! is_array($response->getJson()->data)) {
|
||||
return [$response->getJson()->data];
|
||||
}
|
||||
|
||||
@@ -154,9 +152,7 @@ class Site extends Resource
|
||||
{
|
||||
// Set the options
|
||||
$options = [
|
||||
'body' => json_encode([
|
||||
'php_version' => $version,
|
||||
]),
|
||||
'php_version' => $version,
|
||||
];
|
||||
|
||||
// Build the endpoint
|
||||
|
||||
@@ -48,10 +48,8 @@ class SystemUser extends Resource
|
||||
|
||||
// Set the options
|
||||
$options = [
|
||||
'body' => json_encode([
|
||||
'name' => $name,
|
||||
'sudo' => $sudo
|
||||
]),
|
||||
'name' => $name,
|
||||
'sudo' => $sudo,
|
||||
];
|
||||
|
||||
// Build the endpoint
|
||||
|
||||
Reference in New Issue
Block a user