rector: arrrrr

This commit is contained in:
Andras Bacsai
2025-01-07 14:52:08 +01:00
parent c702ebff6d
commit 16c0cd10d8
349 changed files with 4204 additions and 3712 deletions

View File

@@ -3,10 +3,12 @@
namespace App\Models;
use DanHarrin\LivewireRateLimiting\WithRateLimiting;
use Exception;
use Illuminate\Support\Facades\Storage;
use Illuminate\Validation\ValidationException;
use OpenApi\Attributes as OA;
use phpseclib3\Crypt\PublicKeyLoader;
use Throwable;
#[OA\Schema(
description: 'Private Key model',
@@ -36,10 +38,6 @@ class PrivateKey extends BaseModel
'fingerprint',
];
protected $casts = [
'private_key' => 'encrypted',
];
protected static function booted()
{
static::saving(function ($key) {
@@ -82,7 +80,7 @@ class PrivateKey extends BaseModel
PublicKeyLoader::load($privateKey);
return true;
} catch (\Throwable $e) {
} catch (Throwable $e) {
return false;
}
}
@@ -111,8 +109,8 @@ class PrivateKey extends BaseModel
'private_key' => $keyPair['private'],
'public_key' => $keyPair['public'],
];
} catch (\Throwable $e) {
throw new \Exception("Failed to generate new {$type} key: ".$e->getMessage());
} catch (Throwable $e) {
throw new Exception("Failed to generate new {$type} key: ".$e->getMessage(), $e->getCode(), $e);
}
}
@@ -122,7 +120,7 @@ class PrivateKey extends BaseModel
$key = PublicKeyLoader::load($privateKey);
return $key->getPublicKey()->toString('OpenSSH', ['comment' => '']);
} catch (\Throwable $e) {
} catch (Throwable $e) {
return null;
}
}
@@ -187,10 +185,17 @@ class PrivateKey extends BaseModel
public function isInUse()
{
return $this->servers()->exists()
|| $this->applications()->exists()
|| $this->githubApps()->exists()
|| $this->gitlabApps()->exists();
if ($this->servers()->exists()) {
return true;
}
if ($this->applications()->exists()) {
return true;
}
if ($this->githubApps()->exists()) {
return true;
}
return (bool) $this->gitlabApps()->exists();
}
public function safeDelete()
@@ -211,22 +216,22 @@ class PrivateKey extends BaseModel
$publicKey = $key->getPublicKey();
return $publicKey->getFingerprint('sha256');
} catch (\Throwable $e) {
} catch (Throwable $e) {
return null;
}
}
private static function fingerprintExists($fingerprint, $excludeId = null)
{
$query = self::query()
$builder = self::query()
->where('fingerprint', $fingerprint)
->where('id', '!=', $excludeId);
if (currentTeam()) {
$query->where('team_id', currentTeam()->id);
$builder->where('team_id', currentTeam()->id);
}
return $query->exists();
return $builder->exists();
}
public static function cleanupUnusedKeys()
@@ -235,4 +240,11 @@ class PrivateKey extends BaseModel
$privateKey->safeDelete();
});
}
protected function casts(): array
{
return [
'private_key' => 'encrypted',
];
}
}