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;
|
2024-06-10 20:43:34 +00:00
|
|
|
use Illuminate\View\Component;
|
2023-09-22 09:23:49 +00:00
|
|
|
|
|
|
|
class Links extends Component
|
|
|
|
{
|
|
|
|
public Collection $links;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-09-22 09:23:49 +00:00
|
|
|
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) {
|
2024-06-25 08:37:10 +00:00
|
|
|
$fqdns = collect(str($application->fqdn)->explode(','));
|
2023-11-13 10:09:21 +00:00
|
|
|
$fqdns->map(function ($fqdn) {
|
|
|
|
$this->links->push(getFqdnWithoutPort($fqdn));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if ($application->ports) {
|
2024-06-25 08:37:10 +00:00
|
|
|
$portsCollection = collect(str($application->ports)->explode(','));
|
2023-11-13 10:09:21 +00:00
|
|
|
$portsCollection->map(function ($port) {
|
2024-06-25 08:37:10 +00:00
|
|
|
if (str($port)->contains(':')) {
|
|
|
|
$hostPort = str($port)->before(':');
|
2023-11-13 10:09:21 +00:00
|
|
|
} else {
|
|
|
|
$hostPort = $port;
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
$this->links->push(base_url(withPort: false).":{$hostPort}");
|
2023-11-13 10:09:21 +00:00
|
|
|
});
|
|
|
|
}
|
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');
|
|
|
|
}
|
|
|
|
}
|