Files
coolify/app/Traits/HasSecretManagerAutocomplete.php
Andras Bacsai 91d4467322 feat(secrets): resolve integrations across deployments and databases
Add secret manager integration links and API support, resolve referenced credentials in database startup commands, and improve environment variable handling and filtering.
2026-08-23 21:33:00 +02:00

59 lines
1.5 KiB
PHP

<?php
namespace App\Traits;
use App\Models\SecretManagerLink;
/**
* Exposes the resource's secret manager source to the env-var-input
* autocomplete: a boolean for the "vault" scope, and a lazy key-name fetch
* (called from the frontend only when the user types a vault reference).
* Secret values never reach the component state — key names only.
*/
trait HasSecretManagerAutocomplete
{
public function hasSecretManagerSource(): bool
{
return $this->secretManagerLinkForAutocomplete() !== null;
}
/**
* @return list<string>
*/
public function fetchSecretManagerKeys(): array
{
$this->skipRender();
$link = $this->secretManagerLinkForAutocomplete();
if (! $link) {
return [];
}
try {
$this->authorize('view', $link->resourceable);
$keys = array_keys($link->fetchSecrets());
sort($keys);
return $keys;
} catch (\Throwable) {
throw new \RuntimeException('Unable to fetch secret manager keys.');
}
}
private function secretManagerLinkForAutocomplete(): ?SecretManagerLink
{
$resource = $this->secretManagerResource();
if (! $resource || ! method_exists($resource, 'secretManagerLink')) {
return null;
}
if (! $resource->relationLoaded('secretManagerLink')) {
$resource->load('secretManagerLink.integrationToken');
}
return $resource->secretManagerLink;
}
}