creating networks wip
This commit is contained in:
12
app/Data/ServerProviders/Network.php
Normal file
12
app/Data/ServerProviders/Network.php
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Data\ServerProviders;
|
||||||
|
|
||||||
|
class Network
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
public string $id,
|
||||||
|
public string $name,
|
||||||
|
public string $ipRange,
|
||||||
|
) {}
|
||||||
|
}
|
||||||
@@ -5,9 +5,7 @@ namespace App\Events\Servers;
|
|||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
use Illuminate\Broadcasting\Channel;
|
use Illuminate\Broadcasting\Channel;
|
||||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||||
use Illuminate\Broadcasting\PresenceChannel;
|
|
||||||
use Illuminate\Broadcasting\PrivateChannel;
|
use Illuminate\Broadcasting\PrivateChannel;
|
||||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
|
||||||
use Illuminate\Foundation\Events\Dispatchable;
|
use Illuminate\Foundation\Events\Dispatchable;
|
||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
|
||||||
@@ -17,8 +15,7 @@ class ServerProvisioned
|
|||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
protected Server $server,
|
protected Server $server,
|
||||||
)
|
) {
|
||||||
{
|
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,10 +31,10 @@ class ProvisionCallback extends Controller
|
|||||||
|
|
||||||
if (! $isValidIp) {
|
if (! $isValidIp) {
|
||||||
logger('someone tried to callback from an invalid IP');
|
logger('someone tried to callback from an invalid IP');
|
||||||
logger(' server ip: ' . $server->ipv4);
|
logger(' server ip: '.$server->ipv4);
|
||||||
logger(' server ipv6: ' . $server->ipv6);
|
logger(' server ipv6: '.$server->ipv6);
|
||||||
logger(' callback ip: ' . $request->ip());
|
logger(' callback ip: '.$request->ip());
|
||||||
logger(' server id: ' . $server->id);
|
logger(' server id: '.$server->id);
|
||||||
|
|
||||||
return response('Unauthorized', 401);
|
return response('Unauthorized', 401);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use App\Actions\GenerateRandomSlug;
|
use App\Actions\GenerateRandomSlug;
|
||||||
use App\Actions\GetProviderService;
|
|
||||||
use App\Enums\ServerStatus;
|
use App\Enums\ServerStatus;
|
||||||
use App\Jobs\Servers\WaitForServerToConnect;
|
use App\Jobs\Servers\WaitForServerToConnect;
|
||||||
use App\Models\Organisation;
|
use App\Models\Organisation;
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Integrations\Requests\Hetzner\Servers;
|
||||||
|
|
||||||
|
use Saloon\Contracts\Body\HasBody;
|
||||||
|
use Saloon\Enums\Method;
|
||||||
|
use Saloon\Http\Request;
|
||||||
|
use Saloon\Traits\Body\HasJsonBody;
|
||||||
|
|
||||||
|
class CreateNetworkRequest extends Request implements HasBody
|
||||||
|
{
|
||||||
|
use HasJsonBody;
|
||||||
|
|
||||||
|
protected Method $method = Method::POST;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
protected ?string $name = null,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
protected function defaultBody(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'name' => $this->name,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function resolveEndpoint(): string
|
||||||
|
{
|
||||||
|
return '/networks';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Integrations\Requests\Hetzner\Servers;
|
||||||
|
|
||||||
|
use Saloon\Contracts\Body\HasBody;
|
||||||
|
use Saloon\Enums\Method;
|
||||||
|
use Saloon\Http\Request;
|
||||||
|
use Saloon\Traits\Body\HasJsonBody;
|
||||||
|
|
||||||
|
class GetNetworksRequest extends Request implements HasBody
|
||||||
|
{
|
||||||
|
use HasJsonBody;
|
||||||
|
|
||||||
|
protected Method $method = Method::GET;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
protected ?string $name = null,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
protected function defaultBody(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'name' => $this->name,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function resolveEndpoint(): string
|
||||||
|
{
|
||||||
|
return '/networks';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,11 +5,13 @@ namespace App\Services\ServerProviders;
|
|||||||
use App\Data\ServerProviders\CreatedServer;
|
use App\Data\ServerProviders\CreatedServer;
|
||||||
use App\Data\ServerProviders\Image;
|
use App\Data\ServerProviders\Image;
|
||||||
use App\Data\ServerProviders\Location;
|
use App\Data\ServerProviders\Location;
|
||||||
|
use App\Data\ServerProviders\Network;
|
||||||
use App\Data\ServerProviders\ServerType;
|
use App\Data\ServerProviders\ServerType;
|
||||||
use App\Http\Integrations\Connectors\HetznerConnector;
|
use App\Http\Integrations\Connectors\HetznerConnector;
|
||||||
use App\Http\Integrations\Requests\Hetzner\Images\GetImagesRequest;
|
use App\Http\Integrations\Requests\Hetzner\Images\GetImagesRequest;
|
||||||
use App\Http\Integrations\Requests\Hetzner\Locations\GetLocationsRequest;
|
use App\Http\Integrations\Requests\Hetzner\Locations\GetLocationsRequest;
|
||||||
use App\Http\Integrations\Requests\Hetzner\Servers\CreateServerRequest;
|
use App\Http\Integrations\Requests\Hetzner\Servers\CreateServerRequest;
|
||||||
|
use App\Http\Integrations\Requests\Hetzner\Servers\GetNetworksRequest;
|
||||||
use App\Http\Integrations\Requests\Hetzner\ServerTypes\GetServerTypesRequest;
|
use App\Http\Integrations\Requests\Hetzner\ServerTypes\GetServerTypesRequest;
|
||||||
use App\Models\Provider;
|
use App\Models\Provider;
|
||||||
use Exception;
|
use Exception;
|
||||||
@@ -107,4 +109,27 @@ class HetznerService extends ServerProviderService
|
|||||||
);
|
);
|
||||||
})->where('osVersion', '!=', 'unknown')->values();
|
})->where('osVersion', '!=', 'unknown')->values();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function findNetwork(string $name): ?Network
|
||||||
|
{
|
||||||
|
$response = $this->connector->send(new GetNetworksRequest(
|
||||||
|
name: $name,
|
||||||
|
));
|
||||||
|
|
||||||
|
if ($response->status() !== 200) {
|
||||||
|
throw new Exception('Failed to fetch networks from Hetzner');
|
||||||
|
}
|
||||||
|
|
||||||
|
$network = collect($response->json('networks'))->where('name', $name)->first();
|
||||||
|
|
||||||
|
if ($network) {
|
||||||
|
return new Network(
|
||||||
|
id: $network['id'],
|
||||||
|
name: $network['name'],
|
||||||
|
ipRange: $network['ip_range'],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
namespace App\Services\ServerProviders;
|
namespace App\Services\ServerProviders;
|
||||||
|
|
||||||
use App\Data\ServerProviders\CreatedServer;
|
use App\Data\ServerProviders\CreatedServer;
|
||||||
|
use App\Data\ServerProviders\Network;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Saloon\Http\Connector;
|
use Saloon\Http\Connector;
|
||||||
|
|
||||||
@@ -22,4 +23,6 @@ abstract class ServerProviderService
|
|||||||
abstract public function getLocations(): Collection;
|
abstract public function getLocations(): Collection;
|
||||||
|
|
||||||
abstract public function getImages(): Collection;
|
abstract public function getImages(): Collection;
|
||||||
|
|
||||||
|
abstract public function findNetwork(string $name): ?Network;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Actions\Servers\SyncWireguardRules;
|
|
||||||
use App\Enums\ServerStatus;
|
|
||||||
use App\Http\Controllers\ApplicationController;
|
use App\Http\Controllers\ApplicationController;
|
||||||
use App\Http\Controllers\EnvironmentController;
|
use App\Http\Controllers\EnvironmentController;
|
||||||
use App\Http\Controllers\OrganisationController;
|
use App\Http\Controllers\OrganisationController;
|
||||||
@@ -9,11 +7,7 @@ use App\Http\Controllers\ProvisionCallback;
|
|||||||
use App\Http\Controllers\ProvisionScript;
|
use App\Http\Controllers\ProvisionScript;
|
||||||
use App\Http\Controllers\ServerController;
|
use App\Http\Controllers\ServerController;
|
||||||
use App\Http\Controllers\ServiceController;
|
use App\Http\Controllers\ServiceController;
|
||||||
use App\Models\Server;
|
|
||||||
use App\Support\Ip;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
use Inertia\Inertia;
|
|
||||||
|
|
||||||
Route::inertia('/', 'Welcome')->name('home');
|
Route::inertia('/', 'Welcome')->name('home');
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Actions\GetProviderService;
|
|
||||||
use App\Data\ServerProviders\CreatedServer;
|
|
||||||
use App\Models\Organisation;
|
use App\Models\Organisation;
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Support\Str;
|
|
||||||
use Inertia\Testing\AssertableInertia;
|
use Inertia\Testing\AssertableInertia;
|
||||||
|
|
||||||
use function Pest\Laravel\actingAs;
|
use function Pest\Laravel\actingAs;
|
||||||
|
|||||||
Reference in New Issue
Block a user