-
-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace Allocations with Endpoints #395
base: main
Are you sure you want to change the base?
Conversation
# Conflicts: # app/Filament/Resources/ServerResource/Pages/CreateServer.php # app/Models/Node.php
# Conflicts: # app/Filament/Resources/EggResource/RelationManagers/ServersRelationManager.php # app/Filament/Resources/NodeResource/RelationManagers/AllocationsRelationManager.php # app/Filament/Resources/NodeResource/RelationManagers/NodesRelationManager.php # app/Filament/Resources/ServerResource/Pages/CreateServer.php # app/Filament/Resources/ServerResource/Pages/ListServers.php # app/Filament/Resources/ServerResource/RelationManagers/AllocationsRelationManager.php # app/Filament/Resources/UserResource/RelationManagers/ServersRelationManager.php # app/Models/Allocation.php # app/Models/ApiKey.php # app/Models/Server.php # app/Models/User.php
# Conflicts: # app/Filament/Resources/ServerResource/Pages/CreateServer.php # app/Filament/Resources/ServerResource/Pages/EditServer.php # app/Filament/Resources/ServerResource/RelationManagers/AllocationsRelationManager.php # app/Services/Allocations/AssignmentService.php # database/Seeders/eggs/minecraft/egg-bungeecord.json # database/Seeders/eggs/minecraft/egg-forge-minecraft.json # database/Seeders/eggs/minecraft/egg-paper.json # database/Seeders/eggs/minecraft/egg-sponge-sponge-vanilla.json # database/Seeders/eggs/minecraft/egg-vanilla-minecraft.json # database/Seeders/eggs/rust/egg-rust.json # database/Seeders/eggs/source-engine/egg-counter-strike-global-offensive.json # database/Seeders/eggs/source-engine/egg-custom-source-engine-game.json # database/Seeders/eggs/source-engine/egg-garrys-mod.json # database/Seeders/eggs/source-engine/egg-insurgency.json # database/Seeders/eggs/source-engine/egg-team-fortress2.json # database/Seeders/eggs/voice-servers/egg-mumble-server.json # database/Seeders/eggs/voice-servers/egg-teamspeak3-server.json
# Conflicts: # app/Filament/Resources/NodeResource/Pages/CreateNode.php # app/Filament/Resources/NodeResource/RelationManagers/AllocationsRelationManager.php # app/Filament/Resources/NodeResource/RelationManagers/NodesRelationManager.php # app/Filament/Resources/ServerResource/Pages/CreateServer.php # app/Filament/Resources/ServerResource/Pages/EditServer.php # app/Filament/Resources/ServerResource/Pages/ListServers.php # app/Filament/Resources/ServerResource/RelationManagers/AllocationsRelationManager.php # app/Filament/Resources/UserResource/RelationManagers/ServersRelationManager.php # app/Transformers/Api/Client/ServerTransformer.php # composer.lock # config/panel.php
# Conflicts: # app/Filament/Resources/NodeResource/RelationManagers/AllocationsRelationManager.php # app/Filament/Resources/ServerResource/Pages/CreateServer.php # app/Filament/Resources/ServerResource/Pages/EditServer.php # app/Filament/Resources/ServerResource/RelationManagers/AllocationsRelationManager.php # app/Filament/Resources/UserResource/Pages/EditProfile.php # app/Models/Node.php # app/Models/Objects/DeploymentObject.php # app/Services/Allocations/AssignmentService.php # app/Services/Servers/ServerCreationService.php # app/Services/Servers/TransferServerService.php # pint.json
Forms\Components\ToggleButtons::make('condition') | ||
->label('Status') | ||
->formatStateUsing(fn (Server $server) => $server->condition) | ||
->options(fn ($state) => collect(array_merge(ContainerStatus::cases(), ServerState::cases())) | ||
->filter(fn ($condition) => $condition->value === $state) | ||
->mapWithKeys(fn ($state) => [$state->value => str($state->value)->replace('_', ' ')->ucwords()]) | ||
) | ||
->colors(collect(array_merge(ContainerStatus::cases(), ServerState::cases()))->mapWithKeys( | ||
fn ($status) => [$status->value => $status->color()] | ||
)) | ||
->icons(collect(array_merge(ContainerStatus::cases(), ServerState::cases()))->mapWithKeys( | ||
fn ($status) => [$status->value => $status->icon()] | ||
)) | ||
->columnSpan([ | ||
'default' => 2, | ||
'sm' => 1, | ||
'md' => 1, | ||
'lg' => 1, | ||
]), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forms\Components\ToggleButtons::make('condition') | |
->label('Status') | |
->formatStateUsing(fn (Server $server) => $server->condition) | |
->options(fn ($state) => collect(array_merge(ContainerStatus::cases(), ServerState::cases())) | |
->filter(fn ($condition) => $condition->value === $state) | |
->mapWithKeys(fn ($state) => [$state->value => str($state->value)->replace('_', ' ')->ucwords()]) | |
) | |
->colors(collect(array_merge(ContainerStatus::cases(), ServerState::cases()))->mapWithKeys( | |
fn ($status) => [$status->value => $status->color()] | |
)) | |
->icons(collect(array_merge(ContainerStatus::cases(), ServerState::cases()))->mapWithKeys( | |
fn ($status) => [$status->value => $status->icon()] | |
)) | |
->columnSpan([ | |
'default' => 2, | |
'sm' => 1, | |
'md' => 1, | |
'lg' => 1, | |
]), |
->afterStateUpdated(self::ports(...)) | ||
->live(), | ||
|
||
Forms\Components\Repeater::make('portVariables') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
->afterStateUpdated(self::ports(...)) | ||
->live(), | ||
|
||
Forms\Components\Repeater::make('portVariables') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
->columns(4) | ||
->schema([ | ||
|
||
Forms\Components\TagsInput::make('ports') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
->required(), | ||
), | ||
|
||
Forms\Components\Select::make('ip') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if I want multiple IPs?
|
||
Wizard\Step::make('Allocation') | ||
->label('Allocation') | ||
->icon('tabler-transfer-in') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
->icon('tabler-transfer-in') | |
->icon('tabler-network') |
->columns(4) | ||
->schema([ | ||
|
||
Forms\Components\TagsInput::make('ports') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$this->port = (int) $port; | ||
} | ||
|
||
throw_unless(filter_var($this->ip, FILTER_VALIDATE_IP) !== false, new InvalidArgumentException("$this->ip is an invalid IP address")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will throw if you previously had allocations with 127.0.0.1
(will post error logs later)
$fail('The :attribute must be greater or equal to 0.'); | ||
// Require minimum valid port | ||
if ($value <= Endpoint::PORT_FLOOR) { | ||
$fail('The :attribute must be greater than 1024.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$fail('The :attribute must be greater than 1024.'); | |
$fail('The :attribute must be greater than ' . Endpoint::PORT_FLOOR . '.'); |
$fail('The :attribute must be less or equal to 65535.'); | ||
// Require maximum valid port | ||
if ($value > Endpoint::PORT_CEIL) { | ||
$fail('The :attribute must be less than 65535.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$fail('The :attribute must be less than 65535.'); | |
$fail('The :attribute must be less than ' . Endpoint::PORT_CEIL . '.'); |
@@ -75,6 +74,7 @@ public function transform(Server $server): array | |||
// This field is deprecated, please use "status". | |||
'is_installing' => !$server->isInstalled(), | |||
'is_transferring' => !is_null($server->transfer), | |||
'ports' => $user->can(Permission::ACTION_ALLOCATION_READ, $server) ? $server->ports : collect(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ports
should be removed if the user/ api key doesn't have permissions to read allocations/ endpoints.
Otherwise you can't distinguish if a server really has no ports or if the user just have missing permissions.
Resolves #68