# UserSshKeyEvent events

> 4 FeatherPanel plugin events on UserSshKeyEvent (3 emitted by the core): the event names, the arguments each listener gets, where they fire and a PHP listener for each.

Source: https://featherpanel.com/docs/plugins/events/user-ssh-key/

Part of the [plugin events reference](https://featherpanel.com/docs/plugins/events/). Listeners get the payload values as positional arguments in the order shown, cannot cancel the action, and must catch their own exceptions. 1 of these events are declared but no code emits them yet; they are marked not emitted.

## Setup

Import `UserSshKeyEvent` in your entry class and register listeners in `processEvents()`:

```php
<?php

namespace App\Addons\myplugin;

use App\App;
use App\Plugins\AppPlugin;
use App\Plugins\PluginEvents;
use App\Plugins\Events\Events\UserSshKeyEvent;

class MyPlugin implements AppPlugin
{
    public static function processEvents(PluginEvents $event): void
    {
        $event->on(UserSshKeyEvent::onUserSshKeyCreated(), function (...$rest): void {
            App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:user:ssh_key:created');
        });
    }

    public static function pluginInstall(): void
    {
    }

    public static function pluginUninstall(): void
    {
    }
}
```

## `UserSshKeyEvent::onUserSshKeyCreated()`

- Name: `featherpanel:user:ssh_key:created`
- emitted at 2 sites
- 2 payload shapes
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/UserSshKeyEvent.php#L28)

Docblock: array ssh\_key data. (the emitter passes 2 values, see the table)

Same event name as `UserEvent::onUserSshKeyCreated()`. A listener on either method receives the emits of both.

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `ssh_key` | `$sshKey`not at every site | not declared |
| 2 | `created_by` | `$createdBy`not at every site | not declared |

| Arguments passed | Emitted from |
| --- | --- |
| `ssh_key`, `created_by` | 
`PterodactylImporterController::importSshKey`

 |
| `user_uuid`, `ssh_key` | 

`UserSshKeyController::createUserSshKey`

 |

When it fires (2 sites)

-   [`PterodactylImporterController::importSshKey`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/PterodactylImporterController.php#L1123)[`POST /api/admin/pterodactyl-importer/import-ssh-key`](https://featherpanel.com/docs/api/reference/admin/pterodactyl-importer/#post-admin-pterodactyl-importer-import-ssh-key)
-   [`UserSshKeyController::createUserSshKey`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/User/User/UserSshKeyController.php#L371)[`POST /api/user/ssh-keys`](https://featherpanel.com/docs/api/reference/user/ssh-keys/#post-user-ssh-keys)

```php
$event->on(UserSshKeyEvent::onUserSshKeyCreated(), function (...$rest): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:user:ssh_key:created');
});
```

## `UserSshKeyEvent::onUserSshKeyDeleted()`

- Name: `featherpanel:user:ssh_key:deleted`
- emitted at 2 sites
- 2 payload shapes
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/UserSshKeyEvent.php#L44)

Docblock: int ssh\_key id, array ssh\_key data.

Same event name as `UserEvent::onUserSshKeyDeleted()`. A listener on either method receives the emits of both.

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `user_uuid` | `$userUuid` | `int`from docblock |
| 2 | `ssh_key` | `$sshKey` | `array`from docblock |

| Arguments passed | Emitted from |
| --- | --- |
| `user_uuid`, `ssh_key` | 
`UserSshKeyController::deleteUserSshKey`

 |
| `user_uuid`, `ssh_key`, `action` | 

`UserSshKeyController::hardDeleteUserSshKey`

 |

When it fires (2 sites)

-   [`UserSshKeyController::deleteUserSshKey`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/User/User/UserSshKeyController.php#L569)[`DELETE /api/user/ssh-keys/{id}`](https://featherpanel.com/docs/api/reference/user/ssh-keys/#delete-user-ssh-keys-id)
-   [`UserSshKeyController::hardDeleteUserSshKey`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/User/User/UserSshKeyController.php#L756)[`DELETE /api/user/ssh-keys/{id}/hard-delete`](https://featherpanel.com/docs/api/reference/user/ssh-keys/#delete-user-ssh-keys-id-hard-delete)

```php
$event->on(UserSshKeyEvent::onUserSshKeyDeleted(), function ($userUuid, $sshKey, ...$rest): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:user:ssh_key:deleted ' . json_encode(['user_uuid' => $userUuid, 'ssh_key' => $sshKey]));
});
```

## `UserSshKeyEvent::onUserSshKeyError()`

- Name: `featherpanel:user:ssh_key:error`
- not emitted
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/UserSshKeyEvent.php#L53)

Docblock: string error message, array context.

```php
$event->on(UserSshKeyEvent::onUserSshKeyError(), function (...$args): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:user:ssh_key:error ' . json_encode($args));
});
```

No code emits this event yet, so the arguments are unknown. The listener accepts any.

## `UserSshKeyEvent::onUserSshKeyUpdated()`

- Name: `featherpanel:user:ssh_key:updated`
- emitted at 2 sites
- 2 payload shapes
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/UserSshKeyEvent.php#L36)

Docblock: int ssh\_key id, array updated data. (the emitter passes 3 values, see the table)

Same event name as `UserEvent::onUserSshKeyUpdated()`. A listener on either method receives the emits of both.

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `user_uuid` | `$userUuid` | not declared |
| 2 | `ssh_key` | `$sshKey` | not declared |
| 3 | `updated_data` | `$updatedData`not at every site | not declared |

| Arguments passed | Emitted from |
| --- | --- |
| `user_uuid`, `ssh_key`, `updated_data` | 
`UserSshKeyController::updateUserSshKey`

 |
| `user_uuid`, `ssh_key`, `action` | 

`UserSshKeyController::restoreUserSshKey`

 |

When it fires (2 sites)

-   [`UserSshKeyController::updateUserSshKey`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/User/User/UserSshKeyController.php#L487)[`PUT /api/user/ssh-keys/{id}`](https://featherpanel.com/docs/api/reference/user/ssh-keys/#put-user-ssh-keys-id)
-   [`UserSshKeyController::restoreUserSshKey`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/User/User/UserSshKeyController.php#L666)[`POST /api/user/ssh-keys/{id}/restore`](https://featherpanel.com/docs/api/reference/user/ssh-keys/#post-user-ssh-keys-id-restore)

```php
$event->on(UserSshKeyEvent::onUserSshKeyUpdated(), function ($userUuid, $sshKey, ...$rest): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:user:ssh_key:updated');
});
```
