2024-04-12 12:44:49 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Livewire\Project\Shared;
|
|
|
|
|
|
|
|
|
|
use App\Models\Application;
|
|
|
|
|
use App\Models\Service;
|
|
|
|
|
use App\Models\StandaloneClickhouse;
|
|
|
|
|
use App\Models\StandaloneDragonfly;
|
|
|
|
|
use App\Models\StandaloneKeydb;
|
|
|
|
|
use App\Models\StandaloneMariadb;
|
|
|
|
|
use App\Models\StandaloneMongodb;
|
|
|
|
|
use App\Models\StandaloneMysql;
|
|
|
|
|
use App\Models\StandalonePostgresql;
|
|
|
|
|
use App\Models\StandaloneRedis;
|
2026-05-13 10:04:17 +02:00
|
|
|
use Illuminate\Contracts\View\View;
|
2024-04-12 12:44:49 +02:00
|
|
|
use Livewire\Component;
|
|
|
|
|
|
|
|
|
|
class ConfigurationChecker extends Component
|
|
|
|
|
{
|
|
|
|
|
public bool $isConfigurationChanged = false;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2026-05-13 09:58:58 +02:00
|
|
|
public array $configurationDiff = [];
|
|
|
|
|
|
2024-04-12 12:44:49 +02:00
|
|
|
public Application|Service|StandaloneRedis|StandalonePostgresql|StandaloneMongodb|StandaloneMysql|StandaloneMariadb|StandaloneKeydb|StandaloneDragonfly|StandaloneClickhouse $resource;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2026-05-13 10:04:17 +02:00
|
|
|
public function getListeners(): array
|
2025-09-22 09:44:30 +02:00
|
|
|
{
|
|
|
|
|
$teamId = auth()->user()->currentTeam()->id;
|
|
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
"echo-private:team.{$teamId},ApplicationConfigurationChanged" => 'configurationChanged',
|
|
|
|
|
'configurationChanged' => 'configurationChanged',
|
|
|
|
|
];
|
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2026-05-13 10:04:17 +02:00
|
|
|
public function mount(): void
|
2024-04-12 12:44:49 +02:00
|
|
|
{
|
|
|
|
|
$this->configurationChanged();
|
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2026-05-13 10:04:17 +02:00
|
|
|
public function render(): View
|
2024-04-12 12:44:49 +02:00
|
|
|
{
|
|
|
|
|
return view('livewire.project.shared.configuration-checker');
|
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2026-05-13 10:04:17 +02:00
|
|
|
public function refreshConfigurationChanges(): void
|
2024-04-12 12:44:49 +02:00
|
|
|
{
|
2026-05-13 10:04:17 +02:00
|
|
|
$this->configurationChanged();
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-30 13:15:10 +05:30
|
|
|
/**
|
|
|
|
|
* Members must never see environment variable values, so redact every
|
|
|
|
|
* environment-section change before it is serialized to the browser.
|
|
|
|
|
*
|
|
|
|
|
* @param array<int, array<string, mixed>> $changes
|
|
|
|
|
* @return array<int, array<string, mixed>>
|
|
|
|
|
*/
|
|
|
|
|
private function redactEnvironmentChanges(array $changes, bool $redact): array
|
|
|
|
|
{
|
|
|
|
|
if (! $redact) {
|
|
|
|
|
return $changes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return collect($changes)
|
|
|
|
|
->map(function (array $change): array {
|
|
|
|
|
if (data_get($change, 'section') !== 'environment') {
|
|
|
|
|
return $change;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$change['old_display_value'] = data_get($change, 'old_display_value') === '-' ? '-' : '••••••••';
|
|
|
|
|
$change['new_display_value'] = data_get($change, 'new_display_value') === '-' ? '-' : '••••••••';
|
|
|
|
|
$change['old_full_value'] = null;
|
|
|
|
|
$change['new_full_value'] = null;
|
|
|
|
|
$change['expandable'] = false;
|
|
|
|
|
$change['display_summary'] = data_get($change, 'type') === 'changed' ? 'Changed' : null;
|
|
|
|
|
|
|
|
|
|
return $change;
|
|
|
|
|
})
|
|
|
|
|
->all();
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-13 10:04:17 +02:00
|
|
|
public function configurationChanged(): void
|
|
|
|
|
{
|
|
|
|
|
$this->resource->refresh();
|
|
|
|
|
|
2026-05-13 09:58:58 +02:00
|
|
|
if ($this->resource instanceof Application) {
|
|
|
|
|
$diff = $this->resource->pendingDeploymentConfigurationDiff();
|
2026-05-30 13:15:10 +05:30
|
|
|
// Fail closed: only owners/admins may see unlocked env values.
|
|
|
|
|
$redactEnvironment = ! (bool) auth()->user()?->isAdmin();
|
|
|
|
|
|
|
|
|
|
$array = $diff->toArray();
|
|
|
|
|
$array['changes'] = $this->redactEnvironmentChanges($array['changes'] ?? [], $redactEnvironment);
|
|
|
|
|
|
2026-05-13 09:58:58 +02:00
|
|
|
$this->isConfigurationChanged = $diff->isChanged();
|
2026-05-30 13:15:10 +05:30
|
|
|
$this->configurationDiff = $array;
|
2026-05-13 09:58:58 +02:00
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-12 12:44:49 +02:00
|
|
|
$this->isConfigurationChanged = $this->resource->isConfigurationChanged();
|
2026-05-13 09:58:58 +02:00
|
|
|
$this->configurationDiff = [];
|
2024-04-12 12:44:49 +02:00
|
|
|
}
|
|
|
|
|
}
|