tests pass!
This commit is contained in:
@@ -11,6 +11,7 @@ class CreatedServer
|
||||
public string $status,
|
||||
public string $ipv4,
|
||||
public string $ipv6,
|
||||
public string $privateIp,
|
||||
public string $networkId,
|
||||
) {}
|
||||
}
|
||||
|
||||
@@ -105,12 +105,14 @@ class ServerController extends Controller
|
||||
'external_id' => $createdServer->id,
|
||||
'ipv4' => $createdServer->ipv4,
|
||||
'ipv6' => $createdServer->ipv6,
|
||||
'private_ip' => $createdServer->privateIp,
|
||||
'provider_status' => $createdServer->status,
|
||||
'status' => ServerStatus::WAITING_FOR_PROVIDER,
|
||||
'region' => $request->location,
|
||||
'os' => $request->image,
|
||||
'plan' => $request->server_type,
|
||||
'user' => 'keystone',
|
||||
'external_network_id' => $network->id,
|
||||
]);
|
||||
|
||||
dispatch(new WaitForServerToConnect(
|
||||
|
||||
@@ -7,11 +7,6 @@ use Saloon\Http\Connector;
|
||||
|
||||
class HetznerConnector extends Connector
|
||||
{
|
||||
public function __construct(protected readonly Provider $provider)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function resolveBaseUrl(): string
|
||||
{
|
||||
return 'https://api.hetzner.cloud/v1';
|
||||
@@ -22,7 +17,6 @@ class HetznerConnector extends Connector
|
||||
return [
|
||||
'Content-Type' => 'application/json',
|
||||
'Accept' => 'application/json',
|
||||
'Authorization' => 'Bearer '.$this->provider->token,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ class Provider extends Model
|
||||
public function service(): ?ServerProviderService
|
||||
{
|
||||
return match ($this->type) {
|
||||
ProviderType::HETZNER => app(HetznerService::class, ['provider' => $this]),
|
||||
ProviderType::HETZNER => app(HetznerService::class)->forProvider($this),
|
||||
default => null,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -20,9 +20,17 @@ use Illuminate\Support\Collection;
|
||||
|
||||
class HetznerService extends ServerProviderService
|
||||
{
|
||||
public function __construct(Provider $provider)
|
||||
protected Provider $provider;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->connector = new HetznerConnector($provider);
|
||||
$this->connector = new HetznerConnector();
|
||||
}
|
||||
|
||||
public function forProvider(Provider $provider): static
|
||||
{
|
||||
$this->provider = $provider;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function createServer(
|
||||
@@ -54,6 +62,7 @@ class HetznerService extends ServerProviderService
|
||||
ipv4: $response->json('server.public_net.ipv4.ip'),
|
||||
ipv6: $response->json('server.public_net.ipv6.ip'),
|
||||
networkId: $networkId,
|
||||
privateIp: $response->json('server.private_net.0.ip'),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Services\ServerProviders;
|
||||
|
||||
use App\Data\ServerProviders\CreatedServer;
|
||||
use App\Data\ServerProviders\Network;
|
||||
use App\Models\Provider;
|
||||
use Illuminate\Support\Collection;
|
||||
use Saloon\Http\Connector;
|
||||
|
||||
@@ -19,6 +20,8 @@ abstract class ServerProviderService
|
||||
string $networkId,
|
||||
): CreatedServer;
|
||||
|
||||
abstract public function forProvider(Provider $provider): static;
|
||||
|
||||
abstract public function getServerTypes(): Collection;
|
||||
|
||||
abstract public function getLocations(): Collection;
|
||||
|
||||
Reference in New Issue
Block a user