2023-09-22 09:23:49 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\View\Components\Services;
|
|
|
|
|
|
|
|
use App\Models\Service;
|
|
|
|
use Closure;
|
|
|
|
use Illuminate\Contracts\View\View;
|
|
|
|
use Illuminate\Support\Collection;
|
|
|
|
use Illuminate\View\Component;
|
2023-09-22 12:47:25 +00:00
|
|
|
use Illuminate\Support\Str;
|
2023-09-22 09:23:49 +00:00
|
|
|
|
|
|
|
class Links extends Component
|
|
|
|
{
|
|
|
|
public Collection $links;
|
|
|
|
public function __construct(public Service $service)
|
|
|
|
{
|
|
|
|
$this->links = collect([]);
|
|
|
|
$service->applications()->get()->map(function ($application) {
|
2023-11-13 10:09:21 +00:00
|
|
|
$type = $application->serviceType();
|
|
|
|
if ($type) {
|
2024-04-16 12:08:11 +00:00
|
|
|
$links = generateServiceSpecificFqdns($application);
|
|
|
|
$links = $links->map(function ($link) {
|
|
|
|
return getFqdnWithoutPort($link);
|
|
|
|
});
|
2023-11-13 10:09:21 +00:00
|
|
|
$this->links = $this->links->merge($links);
|
|
|
|
} else {
|
|
|
|
if ($application->fqdn) {
|
|
|
|
$fqdns = collect(Str::of($application->fqdn)->explode(','));
|
|
|
|
$fqdns->map(function ($fqdn) {
|
|
|
|
$this->links->push(getFqdnWithoutPort($fqdn));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if ($application->ports) {
|
|
|
|
$portsCollection = collect(Str::of($application->ports)->explode(','));
|
|
|
|
$portsCollection->map(function ($port) {
|
|
|
|
if (Str::of($port)->contains(':')) {
|
|
|
|
$hostPort = Str::of($port)->before(':');
|
|
|
|
} else {
|
|
|
|
$hostPort = $port;
|
|
|
|
}
|
|
|
|
$this->links->push(base_url(withPort: false) . ":{$hostPort}");
|
|
|
|
});
|
|
|
|
}
|
2023-09-22 12:47:25 +00:00
|
|
|
}
|
2023-09-22 09:23:49 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the view / contents that represent the component.
|
|
|
|
*/
|
|
|
|
public function render(): View|Closure|string
|
|
|
|
{
|
|
|
|
return view('components.services.links');
|
|
|
|
}
|
|
|
|
}
|