2023-03-24 15:47:58 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
2023-09-11 10:15:45 +02:00
|
|
|
use phpseclib3\Crypt\PublicKeyLoader;
|
2023-06-07 15:08:35 +02:00
|
|
|
|
2023-03-24 15:47:58 +01:00
|
|
|
class PrivateKey extends BaseModel
|
|
|
|
{
|
2023-04-26 15:38:50 +02:00
|
|
|
protected $fillable = [
|
|
|
|
'name',
|
|
|
|
'description',
|
|
|
|
'private_key',
|
2023-06-19 10:58:00 +02:00
|
|
|
'is_git_related',
|
2023-04-26 15:38:50 +02:00
|
|
|
'team_id',
|
|
|
|
];
|
2023-08-08 11:51:36 +02:00
|
|
|
|
2023-06-16 12:05:52 +02:00
|
|
|
static public function ownedByCurrentTeam(array $select = ['*'])
|
2023-06-07 15:08:35 +02:00
|
|
|
{
|
2023-06-16 12:05:52 +02:00
|
|
|
$selectArray = collect($select)->concat(['id']);
|
2023-08-22 17:44:49 +02:00
|
|
|
return PrivateKey::whereTeamId(currentTeam()->id)->select($selectArray->all());
|
2023-06-07 15:08:35 +02:00
|
|
|
}
|
2023-08-08 11:51:36 +02:00
|
|
|
|
2023-09-11 10:15:45 +02:00
|
|
|
public function publicKey()
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
return PublicKeyLoader::load($this->private_key)->getPublicKey()->toString('OpenSSH',['comment' => '']);
|
2023-09-11 17:36:30 +02:00
|
|
|
} catch (\Throwable $e) {
|
2023-09-11 10:15:45 +02:00
|
|
|
return 'Error loading private key';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-08 11:51:36 +02:00
|
|
|
public function isEmpty()
|
|
|
|
{
|
|
|
|
if ($this->servers()->count() === 0 && $this->applications()->count() === 0 && $this->githubApps()->count() === 0 && $this->gitlabApps()->count() === 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function servers()
|
|
|
|
{
|
|
|
|
return $this->hasMany(Server::class);
|
|
|
|
}
|
|
|
|
|
2023-06-19 09:44:39 +02:00
|
|
|
public function applications()
|
|
|
|
{
|
|
|
|
return $this->hasMany(Application::class);
|
|
|
|
}
|
2023-08-08 11:51:36 +02:00
|
|
|
|
2023-06-19 09:44:39 +02:00
|
|
|
public function githubApps()
|
|
|
|
{
|
|
|
|
return $this->hasMany(GithubApp::class);
|
|
|
|
}
|
2023-08-08 11:51:36 +02:00
|
|
|
|
2023-06-19 09:44:39 +02:00
|
|
|
public function gitlabApps()
|
|
|
|
{
|
|
|
|
return $this->hasMany(GitlabApp::class);
|
|
|
|
}
|
2023-03-24 15:47:58 +01:00
|
|
|
}
|