Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

Merge remote-tracking branch 'origin/next' into feature/vultr-cloud-provider

Andras Bacsaic58b4fd69cb9
diff --cc app/Livewire/Server/CloudProviderToken/Show.php
index 25aae7c659,e3232d3f36..fa66647766
--- a/app/Livewire/Server/CloudProviderToken/Show.php
+++ b/app/Livewire/Server/CloudProviderToken/Show.php
@@@ -75,7 -68,17 +75,17 @@@ class Show extends Componen
$this->server->cloudProviderToken()->associate($ownedToken);
$this->server->save();
+
+ auditLog('ui.server.cloud_token_assigned', [
+ 'team_id' => currentTeam()->id,
+ 'server_uuid' => $this->server->uuid,
+ 'server_name' => $this->server->name,
+ 'cloud_token_uuid' => $ownedToken->uuid,
+ 'cloud_token_name' => $ownedToken->name,
+ 'provider' => $ownedToken->provider,
+ ]);
+
- $this->dispatch('success', 'Hetzner token updated successfully.');
+ $this->dispatch('success', "{$this->providerName} token updated successfully.");
$this->dispatch('refreshServerShow');
} catch (\Exception $e) {
$this->server->refresh();
@@@ -146,19 -134,25 +156,29 @@@
return;
}
+ $endpoint = $token->provider === 'vultr'
+ ? 'https://api.vultr.com/v2/account'
+ : 'https://api.hetzner.cloud/v1/servers';
+
$response = Http::withHeaders([
'Authorization' => 'Bearer '.$token->token,
- ])->timeout(10)->get('https://api.hetzner.cloud/v1/servers');
+ ])->timeout(10)->get($endpoint);
if ($response->successful()) {
- $this->dispatch('success', 'Hetzner token is valid and working.');
+ $this->dispatch('success', "{$this->providerName} token is valid and working.");
} else {
- $this->dispatch('error', 'Hetzner token is invalid or has insufficient permissions.');
+ $this->dispatch('error', "{$this->providerName} token is invalid or has insufficient permissions.");
}
+
+ auditLog('ui.server.cloud_token_validated', [
+ 'team_id' => currentTeam()->id,
+ 'server_uuid' => $this->server->uuid,
+ 'server_name' => $this->server->name,
+ 'cloud_token_uuid' => $token->uuid,
+ 'cloud_token_name' => $token->name,
+ 'provider' => $token->provider,
+ 'valid' => $response->successful(),
+ ]);
} catch (\Throwable $e) {
return handleError($e, $this);
}
diff --cc app/Livewire/Server/Show.php
index 0cd560c98f,433f544aec..f85d628a0d
--- a/app/Livewire/Server/Show.php
+++ b/app/Livewire/Server/Show.php
@@@ -609,13 -537,20 +615,27 @@@ class Show extends Componen
->get();
}
+ public function loadVultrTokens(): void
+ {
+ $this->availableVultrTokens = CloudProviderToken::ownedByCurrentTeam()
+ ->where('provider', 'vultr')
+ ->get();
+ }
+
+ #[Computed]
+ public function limaStartCommand(): ?string
+ {
+ if (! isDev()) {
+ return null;
+ }
+
+ return match ($this->server->uuid) {
+ 'lima-ubuntu-2404' => 'limactl start --yes --name=coolify-lima-ubuntu-2404 docker/lima/ubuntu-2404.yaml',
+ 'lima-ubuntu-2604' => 'limactl start --yes --name=coolify-lima-ubuntu-2604 docker/lima/ubuntu-2604.yaml',
+ default => null,
+ };
+ }
+
public function searchHetznerServer(): void
{
$this->hetznerSearchError = null;
diff --cc app/Livewire/Server/ValidateAndInstall.php
index 5731c4fbe2,afcc918a65..b3b946c15e
--- a/app/Livewire/Server/ValidateAndInstall.php
+++ b/app/Livewire/Server/ValidateAndInstall.php
@@@ -86,15 -90,12 +90,28 @@@ class ValidateAndInstall extends Compon
public function validateConnection()
{
- $this->authorize('update', $this->server);
- if ($this->server->vultr_instance_id) {
- $status = $this->server->refreshVultrState();
- $this->server->refresh();
-
- if (in_array($status, ['stopped', 'suspended', 'deleted'], true)) {
- $this->error = $status === 'deleted'
- ? 'Vultr instance is deleted or no longer accessible. Relink this server before validating.'
- : 'Vultr instance is '.($status ?? 'not running').'. Power it on before validating.';
+ try {
+ $this->authorize('update', $this->server);
++ if ($this->server->vultr_instance_id) {
++ $status = $this->server->refreshVultrState();
++ $this->server->refresh();
++
++ if (in_array($status, ['stopped', 'suspended', 'deleted'], true)) {
++ $this->error = $status === 'deleted'
++ ? 'Vultr instance is deleted or no longer accessible. Relink this server before validating.'
++ : 'Vultr instance is '.($status ?? 'not running').'. Power it on before validating.';
++ $this->server->update([
++ 'validation_logs' => $this->error,
++ ]);
++
++ return;
++ }
++ }
++
+ ['uptime' => $this->uptime, 'error' => $error] = $this->server->validateConnection();
+ if (! $this->uptime) {
+ $sanitizedError = htmlspecialchars($error ?? '', ENT_QUOTES, 'UTF-8');
+ $this->error = 'Server is not reachable. Please validate your configuration and connection.<br>Check this <a target="_blank" class="text-black underline dark:text-white" href="https://coolify.io/docs/knowledge-base/server/openssh">documentation</a> for further help. <br><br><div class="text-error">Error: '.$sanitizedError.'</div>';
$this->server->update([
'validation_logs' => $this->error,
]);
diff --cc database/factories/CloudProviderTokenFactory.php
index 49bc2e498e,4da7a2d084..689c268268
--- a/database/factories/CloudProviderTokenFactory.php
+++ b/database/factories/CloudProviderTokenFactory.php
@@@ -11,11 -11,8 +11,13 @@@ use Illuminate\Database\Eloquent\Factor
*/
class CloudProviderTokenFactory extends Factory
{
+ protected $model = CloudProviderToken::class;
+
+ /**
+ * Define the model's default state.
+ *
+ * @return array<string, mixed>
+ */
public function definition(): array
{
return [
diff --cc tests/Feature/Api/CloudProviderTokenApiTest.php
index a26cd93117,42b2d09723..680586a9c0
--- a/tests/Feature/Api/CloudProviderTokenApiTest.php
+++ b/tests/Feature/Api/CloudProviderTokenApiTest.php
@@@ -10,16 -12,11 +12,17 @@@ use Illuminate\Support\Once
uses(RefreshDatabase::class);
beforeEach(function () {
+ config([
+ 'app.maintenance.driver' => 'file',
+ 'cache.default' => 'array',
+ 'session.driver' => 'array',
+ ]);
+
- InstanceSettings::unguarded(fn () => InstanceSettings::query()->create([
- 'id' => 0,
- 'is_api_enabled' => true,
- ]));
+ InstanceSettings::query()->whereKey(0)->delete();
+ $settings = new InstanceSettings(['is_api_enabled' => true]);
+ $settings->id = 0;
+ $settings->save();
+ Once::flush();
// Create a team with owner
$this->team = Team::factory()->create();
@@@ -446,22 -518,32 +548,51 @@@ describe('POST /api/v1/cloud-tokens/{uu
$response->assertJson(['valid' => true, 'message' => 'Token is valid.']);
});
+ test('validates a valid Vultr token', function () {
+ $token = CloudProviderToken::factory()->create([
+ 'team_id' => $this->team->id,
+ 'provider' => 'vultr',
+ ]);
+
+ Http::fake([
+ 'https://api.vultr.com/v2/account' => Http::response([], 200),
+ ]);
+
+ $response = $this->withHeaders([
+ 'Authorization' => 'Bearer '.$this->bearerToken,
+ 'Content-Type' => 'application/json',
+ ])->postJson("/api/v1/cloud-tokens/{$token->uuid}/validate");
+
+ $response->assertStatus(200);
+ $response->assertJson(['valid' => true, 'message' => 'Token is valid.']);
+ });
++
+ test('writes an audit log entry when validating a stored token', function () {
+ $token = CloudProviderToken::factory()->create([
+ 'team_id' => $this->team->id,
+ 'provider' => 'hetzner',
+ 'name' => 'Audit Token',
+ ]);
+
+ Http::fake([
+ 'https://api.hetzner.cloud/v1/servers' => Http::response([], 200),
+ ]);
+
+ $auditChannel = Mockery::mock();
+ $auditChannel->shouldReceive('info')
+ ->once()
+ ->with('api.cloud_token.validated', Mockery::on(function (array $context) use ($token) {
+ return $context['cloud_token_uuid'] === $token->uuid
+ && $context['provider'] === 'hetzner'
+ && $context['valid'] === true;
+ }));
+
+ Log::shouldReceive('channel')->with('audit')->andReturn($auditChannel);
+
+ $this->withHeaders([
+ 'Authorization' => 'Bearer '.$this->bearerToken,
+ 'Content-Type' => 'application/json',
+ ])->postJson("/api/v1/cloud-tokens/{$token->uuid}/validate")
+ ->assertOk();
+ });
});