Add dedicated show/edit pages for cloud provider tokens and cloud-init scripts, including descriptions and UUID routes. Generate private keys directly from the index and surface cloud provider API loading errors in server creation flows.
53 lines
1,021 B
PHP
53 lines
1,021 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
class CloudProviderToken extends BaseModel
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $fillable = [
|
|
'team_id',
|
|
'provider',
|
|
'token',
|
|
'name',
|
|
'description',
|
|
];
|
|
|
|
protected $hidden = [
|
|
'token',
|
|
];
|
|
|
|
protected $casts = [
|
|
'token' => 'encrypted',
|
|
];
|
|
|
|
public function team()
|
|
{
|
|
return $this->belongsTo(Team::class);
|
|
}
|
|
|
|
public function servers()
|
|
{
|
|
return $this->hasMany(Server::class);
|
|
}
|
|
|
|
public function hasServers(): bool
|
|
{
|
|
return $this->servers()->exists();
|
|
}
|
|
|
|
public static function ownedByCurrentTeam(array $select = ['*'])
|
|
{
|
|
$selectArray = collect($select)->concat(['id']);
|
|
|
|
return self::whereTeamId(currentTeam()->id)->select($selectArray->all());
|
|
}
|
|
|
|
public function scopeForProvider($query, string $provider)
|
|
{
|
|
return $query->where('provider', $provider);
|
|
}
|
|
}
|