mirror of
https://github.com/coollabsio/coolify.git
synced 2026-11-06 21:18:11 -04:00
v4.7 (#12478)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: peaklabs-dev <122374094+peaklabs-dev@users.noreply.github.com> Co-authored-by: Aditya Tripathi <aditya@climactic.co>
This commit is contained in:
co-authored by
Claude Opus 5.5
peaklabs-dev
Aditya Tripathi
parent
b7dc2e435b
commit
033f0c84da
@@ -7,6 +7,7 @@ use App\Models\PrivateKey;
|
||||
use App\Support\ValidationPatterns;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use OpenApi\Attributes as OA;
|
||||
|
||||
class SecurityController extends Controller
|
||||
@@ -208,21 +209,16 @@ class SecurityController extends Controller
|
||||
$request->offsetSet('description', 'Created by Coolify via API');
|
||||
}
|
||||
|
||||
// A key that is not PEM text can be sent base64 encoded. Other text is validated as it is.
|
||||
$isPrivateKeyString = str_starts_with($request->private_key, '-----BEGIN');
|
||||
if (! $isPrivateKeyString) {
|
||||
try {
|
||||
$base64PrivateKey = base64_decode($request->private_key);
|
||||
$request->offsetSet('private_key', $base64PrivateKey);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'message' => 'Invalid private key.',
|
||||
], 422);
|
||||
}
|
||||
$base64PrivateKey = $isPrivateKeyString ? false : base64_decode($request->private_key, true);
|
||||
if ($base64PrivateKey !== false) {
|
||||
$request->offsetSet('private_key', $base64PrivateKey);
|
||||
}
|
||||
$isPrivateKeyValid = PrivateKey::validatePrivateKey($request->private_key);
|
||||
if (! $isPrivateKeyValid) {
|
||||
$privateKeyError = PrivateKey::validationError($request->private_key);
|
||||
if ($privateKeyError) {
|
||||
return response()->json([
|
||||
'message' => 'Invalid private key.',
|
||||
'message' => $privateKeyError,
|
||||
], 422);
|
||||
}
|
||||
$fingerPrint = PrivateKey::generateFingerprint($request->private_key);
|
||||
@@ -352,7 +348,14 @@ class SecurityController extends Controller
|
||||
], 404);
|
||||
}
|
||||
$this->authorize('update', $foundKey);
|
||||
$foundKey->update($request->only($allowedFields));
|
||||
try {
|
||||
$foundKey->update($request->only($allowedFields));
|
||||
} catch (ValidationException $e) {
|
||||
return response()->json([
|
||||
'message' => $e->getMessage(),
|
||||
'errors' => $e->errors(),
|
||||
], 422);
|
||||
}
|
||||
|
||||
auditLog('api.private_key.updated', [
|
||||
'team_id' => $teamId,
|
||||
|
||||
Reference in New Issue
Block a user