Merge branch 'next' into dep-and-remove-unused-stuff

This commit is contained in:
🏔️ Peak
2024-11-12 14:39:01 +01:00
committed by GitHub
5 changed files with 167 additions and 44 deletions

View File

@@ -426,6 +426,7 @@ class ServersController extends Controller
'private_key_uuid' => ['type' => 'string', 'example' => 'og888os', 'description' => 'The UUID of the private key.'], 'private_key_uuid' => ['type' => 'string', 'example' => 'og888os', 'description' => 'The UUID of the private key.'],
'is_build_server' => ['type' => 'boolean', 'example' => false, 'description' => 'Is build server.'], 'is_build_server' => ['type' => 'boolean', 'example' => false, 'description' => 'Is build server.'],
'instant_validate' => ['type' => 'boolean', 'example' => false, 'description' => 'Instant validate.'], 'instant_validate' => ['type' => 'boolean', 'example' => false, 'description' => 'Instant validate.'],
'proxy_type' => ['type' => 'string', 'enum' => ['traefik', 'caddy', 'none'], 'example' => 'traefik', 'description' => 'The proxy type.'],
], ],
), ),
), ),
@@ -461,7 +462,7 @@ class ServersController extends Controller
)] )]
public function create_server(Request $request) public function create_server(Request $request)
{ {
$allowedFields = ['name', 'description', 'ip', 'port', 'user', 'private_key_uuid', 'is_build_server', 'instant_validate']; $allowedFields = ['name', 'description', 'ip', 'port', 'user', 'private_key_uuid', 'is_build_server', 'instant_validate', 'proxy_type'];
$teamId = getTeamIdFromToken(); $teamId = getTeamIdFromToken();
if (is_null($teamId)) { if (is_null($teamId)) {
@@ -481,6 +482,7 @@ class ServersController extends Controller
'user' => 'string|nullable', 'user' => 'string|nullable',
'is_build_server' => 'boolean|nullable', 'is_build_server' => 'boolean|nullable',
'instant_validate' => 'boolean|nullable', 'instant_validate' => 'boolean|nullable',
'proxy_type' => 'string|nullable',
]); ]);
$extraFields = array_diff(array_keys($request->all()), $allowedFields); $extraFields = array_diff(array_keys($request->all()), $allowedFields);
@@ -512,6 +514,14 @@ class ServersController extends Controller
if (is_null($request->instant_validate)) { if (is_null($request->instant_validate)) {
$request->offsetSet('instant_validate', false); $request->offsetSet('instant_validate', false);
} }
if ($request->proxy_type) {
$validProxyTypes = collect(ProxyTypes::cases())->map(function ($proxyType) {
return str($proxyType->value)->lower();
});
if (! $validProxyTypes->contains(str($request->proxy_type)->lower())) {
return response()->json(['message' => 'Invalid proxy type.'], 422);
}
}
$privateKey = PrivateKey::whereTeamId($teamId)->whereUuid($request->private_key_uuid)->first(); $privateKey = PrivateKey::whereTeamId($teamId)->whereUuid($request->private_key_uuid)->first();
if (! $privateKey) { if (! $privateKey) {
return response()->json(['message' => 'Private key not found.'], 404); return response()->json(['message' => 'Private key not found.'], 404);
@@ -521,6 +531,8 @@ class ServersController extends Controller
return response()->json(['message' => 'Server with this IP already exists.'], 400); return response()->json(['message' => 'Server with this IP already exists.'], 400);
} }
$proxyType = $request->proxy_type ? str($request->proxy_type)->upper() : ProxyTypes::TRAEFIK->value;
$server = ModelsServer::create([ $server = ModelsServer::create([
'name' => $request->name, 'name' => $request->name,
'description' => $request->description, 'description' => $request->description,
@@ -530,7 +542,7 @@ class ServersController extends Controller
'private_key_id' => $privateKey->id, 'private_key_id' => $privateKey->id,
'team_id' => $teamId, 'team_id' => $teamId,
'proxy' => [ 'proxy' => [
'type' => ProxyTypes::TRAEFIK->value, 'type' => $proxyType,
'status' => ProxyStatus::EXITED->value, 'status' => ProxyStatus::EXITED->value,
], ],
]); ]);
@@ -571,6 +583,7 @@ class ServersController extends Controller
'private_key_uuid' => ['type' => 'string', 'description' => 'The UUID of the private key.'], 'private_key_uuid' => ['type' => 'string', 'description' => 'The UUID of the private key.'],
'is_build_server' => ['type' => 'boolean', 'description' => 'Is build server.'], 'is_build_server' => ['type' => 'boolean', 'description' => 'Is build server.'],
'instant_validate' => ['type' => 'boolean', 'description' => 'Instant validate.'], 'instant_validate' => ['type' => 'boolean', 'description' => 'Instant validate.'],
'proxy_type' => ['type' => 'string', 'enum' => ['traefik', 'caddy', 'none'], 'description' => 'The proxy type.'],
], ],
), ),
), ),
@@ -604,7 +617,7 @@ class ServersController extends Controller
)] )]
public function update_server(Request $request) public function update_server(Request $request)
{ {
$allowedFields = ['name', 'description', 'ip', 'port', 'user', 'private_key_uuid', 'is_build_server', 'instant_validate']; $allowedFields = ['name', 'description', 'ip', 'port', 'user', 'private_key_uuid', 'is_build_server', 'instant_validate', 'proxy_type'];
$teamId = getTeamIdFromToken(); $teamId = getTeamIdFromToken();
if (is_null($teamId)) { if (is_null($teamId)) {
@@ -624,6 +637,7 @@ class ServersController extends Controller
'user' => 'string|nullable', 'user' => 'string|nullable',
'is_build_server' => 'boolean|nullable', 'is_build_server' => 'boolean|nullable',
'instant_validate' => 'boolean|nullable', 'instant_validate' => 'boolean|nullable',
'proxy_type' => 'string|nullable',
]); ]);
$extraFields = array_diff(array_keys($request->all()), $allowedFields); $extraFields = array_diff(array_keys($request->all()), $allowedFields);
@@ -644,6 +658,16 @@ class ServersController extends Controller
if (! $server) { if (! $server) {
return response()->json(['message' => 'Server not found.'], 404); return response()->json(['message' => 'Server not found.'], 404);
} }
if ($request->proxy_type) {
$validProxyTypes = collect(ProxyTypes::cases())->map(function ($proxyType) {
return str($proxyType->value)->lower();
});
if ($validProxyTypes->contains(str($request->proxy_type)->lower())) {
$server->changeProxy($request->proxy_type, async: true);
} else {
return response()->json(['message' => 'Invalid proxy type.'], 422);
}
}
$server->update($request->only(['name', 'description', 'ip', 'port', 'user'])); $server->update($request->only(['name', 'description', 'ip', 'port', 'user']));
if ($request->is_build_server) { if ($request->is_build_server) {
$server->settings()->update([ $server->settings()->update([
@@ -654,7 +678,9 @@ class ServersController extends Controller
ValidateServer::dispatch($server)->onQueue('high'); ValidateServer::dispatch($server)->onQueue('high');
} }
return response()->json(serializeApiResponse($server))->setStatusCode(201); return response()->json([
])->setStatusCode(201);
} }
#[OA\Delete( #[OA\Delete(

View File

@@ -4,7 +4,6 @@ namespace App\Livewire\Server;
use App\Actions\Proxy\CheckConfiguration; use App\Actions\Proxy\CheckConfiguration;
use App\Actions\Proxy\SaveConfiguration; use App\Actions\Proxy\SaveConfiguration;
use App\Actions\Proxy\StartProxy;
use App\Models\Server; use App\Models\Server;
use Livewire\Component; use Livewire\Component;
@@ -44,14 +43,13 @@ class Proxy extends Component
public function selectProxy($proxy_type) public function selectProxy($proxy_type)
{ {
$this->server->proxy->set('status', 'exited'); try {
$this->server->proxy->set('type', $proxy_type); $this->server->changeProxy($proxy_type, async: false);
$this->server->save();
$this->selectedProxy = $this->server->proxy->type; $this->selectedProxy = $this->server->proxy->type;
if ($this->server->proxySet()) {
StartProxy::run($this->server, false);
}
$this->dispatch('proxyStatusUpdated'); $this->dispatch('proxyStatusUpdated');
} catch (\Throwable $e) {
return handleError($e, $this);
}
} }
public function instantSave() public function instantSave()

View File

@@ -2,6 +2,7 @@
namespace App\Models; namespace App\Models;
use App\Actions\Proxy\StartProxy;
use App\Actions\Server\InstallDocker; use App\Actions\Server\InstallDocker;
use App\Actions\Server\StartSentinel; use App\Actions\Server\StartSentinel;
use App\Enums\ProxyTypes; use App\Enums\ProxyTypes;
@@ -26,22 +27,23 @@ use Symfony\Component\Yaml\Yaml;
description: 'Server model', description: 'Server model',
type: 'object', type: 'object',
properties: [ properties: [
'id' => ['type' => 'integer'], 'id' => ['type' => 'integer', 'description' => 'The server ID.'],
'uuid' => ['type' => 'string'], 'uuid' => ['type' => 'string', 'description' => 'The server UUID.'],
'name' => ['type' => 'string'], 'name' => ['type' => 'string', 'description' => 'The server name.'],
'description' => ['type' => 'string'], 'description' => ['type' => 'string', 'description' => 'The server description.'],
'ip' => ['type' => 'string'], 'ip' => ['type' => 'string', 'description' => 'The IP address.'],
'user' => ['type' => 'string'], 'user' => ['type' => 'string', 'description' => 'The user.'],
'port' => ['type' => 'integer'], 'port' => ['type' => 'integer', 'description' => 'The port number.'],
'proxy' => ['type' => 'object'], 'proxy' => ['type' => 'object', 'description' => 'The proxy configuration.'],
'high_disk_usage_notification_sent' => ['type' => 'boolean'], 'proxy_type' => ['type' => 'string', 'enum' => ['traefik', 'caddy', 'none'], 'description' => 'The proxy type.'],
'unreachable_notification_sent' => ['type' => 'boolean'], 'high_disk_usage_notification_sent' => ['type' => 'boolean', 'description' => 'The flag to indicate if the high disk usage notification has been sent.'],
'unreachable_count' => ['type' => 'integer'], 'unreachable_notification_sent' => ['type' => 'boolean', 'description' => 'The flag to indicate if the unreachable notification has been sent.'],
'validation_logs' => ['type' => 'string'], 'unreachable_count' => ['type' => 'integer', 'description' => 'The unreachable count for your server.'],
'log_drain_notification_sent' => ['type' => 'boolean'], 'validation_logs' => ['type' => 'string', 'description' => 'The validation logs.'],
'swarm_cluster' => ['type' => 'string'], 'log_drain_notification_sent' => ['type' => 'boolean', 'description' => 'The flag to indicate if the log drain notification has been sent.'],
'delete_unused_volumes' => ['type' => 'boolean'], 'swarm_cluster' => ['type' => 'string', 'description' => 'The swarm cluster configuration.'],
'delete_unused_networks' => ['type' => 'boolean'], 'delete_unused_volumes' => ['type' => 'boolean', 'description' => 'The flag to indicate if the unused volumes should be deleted.'],
'delete_unused_networks' => ['type' => 'boolean', 'description' => 'The flag to indicate if the unused networks should be deleted.'],
] ]
)] )]
@@ -1251,4 +1253,25 @@ $schema://$host {
{ {
return instant_remote_process(['docker restart '.$containerName], $this, false); return instant_remote_process(['docker restart '.$containerName], $this, false);
} }
public function changeProxy(string $proxyType, bool $async = true)
{
$validProxyTypes = collect(ProxyTypes::cases())->map(function ($proxyType) {
return str($proxyType->value)->lower();
});
if ($validProxyTypes->contains(str($proxyType)->lower())) {
$this->proxy->set('type', str($proxyType)->upper());
$this->proxy->set('status', 'exited');
$this->save();
if ($this->proxySet()) {
if ($async) {
StartProxy::dispatch($this);
} else {
StartProxy::run($this);
}
}
} else {
throw new \Exception('Invalid proxy type.');
}
}
} }

View File

@@ -5234,6 +5234,16 @@
"type": "boolean", "type": "boolean",
"example": false, "example": false,
"description": "Instant validate." "description": "Instant validate."
},
"proxy_type": {
"type": "string",
"enum": [
"traefik",
"caddy",
"none"
],
"example": "traefik",
"description": "The proxy type."
} }
}, },
"type": "object" "type": "object"
@@ -5419,6 +5429,15 @@
"instant_validate": { "instant_validate": {
"type": "boolean", "type": "boolean",
"description": "Instant validate." "description": "Instant validate."
},
"proxy_type": {
"type": "string",
"enum": [
"traefik",
"caddy",
"none"
],
"description": "The proxy type."
} }
}, },
"type": "object" "type": "object"
@@ -7358,52 +7377,77 @@
"description": "Server model", "description": "Server model",
"properties": { "properties": {
"id": { "id": {
"type": "integer" "type": "integer",
"description": "The server ID."
}, },
"uuid": { "uuid": {
"type": "string" "type": "string",
"description": "The server UUID."
}, },
"name": { "name": {
"type": "string" "type": "string",
"description": "The server name."
}, },
"description": { "description": {
"type": "string" "type": "string",
"description": "The server description."
}, },
"ip": { "ip": {
"type": "string" "type": "string",
"description": "The IP address."
}, },
"user": { "user": {
"type": "string" "type": "string",
"description": "The user."
}, },
"port": { "port": {
"type": "integer" "type": "integer",
"description": "The port number."
}, },
"proxy": { "proxy": {
"type": "object" "type": "object",
"description": "The proxy configuration."
},
"proxy_type": {
"type": "string",
"enum": [
"traefik",
"caddy",
"none"
],
"description": "The proxy type."
}, },
"high_disk_usage_notification_sent": { "high_disk_usage_notification_sent": {
"type": "boolean" "type": "boolean",
"description": "The flag to indicate if the high disk usage notification has been sent."
}, },
"unreachable_notification_sent": { "unreachable_notification_sent": {
"type": "boolean" "type": "boolean",
"description": "The flag to indicate if the unreachable notification has been sent."
}, },
"unreachable_count": { "unreachable_count": {
"type": "integer" "type": "integer",
"description": "The unreachable count for your server."
}, },
"validation_logs": { "validation_logs": {
"type": "string" "type": "string",
"description": "The validation logs."
}, },
"log_drain_notification_sent": { "log_drain_notification_sent": {
"type": "boolean" "type": "boolean",
"description": "The flag to indicate if the log drain notification has been sent."
}, },
"swarm_cluster": { "swarm_cluster": {
"type": "string" "type": "string",
"description": "The swarm cluster configuration."
}, },
"delete_unused_volumes": { "delete_unused_volumes": {
"type": "boolean" "type": "boolean",
"description": "The flag to indicate if the unused volumes should be deleted."
}, },
"delete_unused_networks": { "delete_unused_networks": {
"type": "boolean" "type": "boolean",
"description": "The flag to indicate if the unused networks should be deleted."
} }
}, },
"type": "object" "type": "object"

View File

@@ -3577,6 +3577,11 @@ paths:
type: boolean type: boolean
example: false example: false
description: 'Instant validate.' description: 'Instant validate.'
proxy_type:
type: string
enum: [traefik, caddy, none]
example: traefik
description: 'The proxy type.'
type: object type: object
responses: responses:
'201': '201':
@@ -3697,6 +3702,10 @@ paths:
instant_validate: instant_validate:
type: boolean type: boolean
description: 'Instant validate.' description: 'Instant validate.'
proxy_type:
type: string
enum: [traefik, caddy, none]
description: 'The proxy type.'
type: object type: object
responses: responses:
'201': '201':
@@ -4911,36 +4920,59 @@ components:
properties: properties:
id: id:
type: integer type: integer
description: 'The server ID.'
uuid: uuid:
type: string type: string
description: 'The server UUID.'
name: name:
type: string type: string
description: 'The server name.'
description: description:
type: string type: string
description: 'The server description.'
ip: ip:
type: string type: string
description: 'The IP address.'
user: user:
type: string type: string
description: 'The user.'
port: port:
type: integer type: integer
description: 'The port number.'
proxy: proxy:
type: object type: object
description: 'The proxy configuration.'
proxy_type:
type: string
enum:
- traefik
- caddy
- none
description: 'The proxy type.'
high_disk_usage_notification_sent: high_disk_usage_notification_sent:
type: boolean type: boolean
description: 'The flag to indicate if the high disk usage notification has been sent.'
unreachable_notification_sent: unreachable_notification_sent:
type: boolean type: boolean
description: 'The flag to indicate if the unreachable notification has been sent.'
unreachable_count: unreachable_count:
type: integer type: integer
description: 'The unreachable count for your server.'
validation_logs: validation_logs:
type: string type: string
description: 'The validation logs.'
log_drain_notification_sent: log_drain_notification_sent:
type: boolean type: boolean
description: 'The flag to indicate if the log drain notification has been sent.'
swarm_cluster: swarm_cluster:
type: string type: string
description: 'The swarm cluster configuration.'
delete_unused_volumes: delete_unused_volumes:
type: boolean type: boolean
description: 'The flag to indicate if the unused volumes should be deleted.'
delete_unused_networks: delete_unused_networks:
type: boolean type: boolean
description: 'The flag to indicate if the unused networks should be deleted.'
type: object type: object
ServerSetting: ServerSetting:
description: 'Server Settings model' description: 'Server Settings model'