Skip to content

Commit

Permalink
Discard ipAddresses cache if wings is offline + Switch to Select (#862)
Browse files Browse the repository at this point in the history
* Change TextInputColumn to SelectColumn

* Discard cache if wings is offline

* Return 0.0.0.0 instead of an empty array

* Adjustment & remove dns resolve
  • Loading branch information
RMartinOscar authored Jan 6, 2025
1 parent 77fd54f commit ae44584
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Filament\Tables;
use Filament\Tables\Actions\BulkActionGroup;
use Filament\Tables\Actions\DeleteBulkAction;
use Filament\Tables\Columns\SelectColumn;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Columns\TextInputColumn;
use Filament\Tables\Table;
Expand Down Expand Up @@ -69,7 +70,9 @@ public function table(Table $table): Table
TextInputColumn::make('ip_alias')
->searchable()
->label('Alias'),
TextInputColumn::make('ip')
SelectColumn::make('ip')
->options(fn (Allocation $allocation) => collect($this->getOwnerRecord()->ipAddresses())->merge([$allocation->ip])->mapWithKeys(fn (string $ip) => [$ip => $ip]))
->selectablePlaceholder(false)
->searchable()
->label('IP'),
])
Expand Down
13 changes: 5 additions & 8 deletions app/Models/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -374,24 +374,21 @@ public function ipAddresses(): array
{
return cache()->remember("nodes.$this->id.ips", now()->addHour(), function () {
$ips = collect();
if (is_ip($this->fqdn)) {
$ips = $ips->push($this->fqdn);
} elseif ($dnsRecords = gethostbynamel($this->fqdn)) {
$ips = $ips->concat($dnsRecords);
}

try {
$addresses = Http::daemon($this)->connectTimeout(1)->timeout(1)->get('/api/system/ips')->json();
$ips = $ips->concat(fluent($addresses)->get('ip_addresses'));
} catch (Exception) {
// pass
if (is_ip($this->fqdn)) {
$ips->push($this->fqdn);
}
}

$ips->push('0.0.0.0');

// Only IPV4
$ips = $ips->filter(fn (string $ip) => filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) !== false);

$ips->push('0.0.0.0');

return $ips->unique()->all();
});
}
Expand Down

0 comments on commit ae44584

Please sign in to comment.