user()->sshKeys); } /** * Stores a new SSH key for the authenticated user's account. */ #[Endpoint('Create SSH key', 'Adds an SSH public key to the authenticated user account.')] #[ResponseFromResource(UserSSHKeyResource::class, UserSSHKey::class, description: 'SSH key created.', resourceKey: 'ssh_key')] public function store(StoreSSHKeyRequest $request, CreatesSshKeys $keys): UserSSHKeyResource { $model = $keys->create($request->user(), $request->string('name')->toString(), $request->getPublicKey(), $request->getKeyFingerprint()); return UserSSHKeyResource::make($model); } /** * Deletes an SSH key from the user's account. */ #[Endpoint('Delete SSH key', 'Deletes an SSH key from the authenticated user account by fingerprint. Missing keys are treated as already deleted.')] #[ScribeResponse(status: 204, description: 'SSH key deleted or already absent.')] public function delete(DeleteSSHKeyRequest $request, DeletesSshKeys $keys): JsonResponse { $key = $request->user()->sshKeys() ->where('fingerprint', $request->validated('fingerprint')) ->first(); if (($key) !== null) { $keys->delete($key); } return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT); } }