Skip to content

Commit

Permalink
added endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
lewislarsen committed Mar 1, 2025
1 parent e3bf211 commit aa847a6
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 0 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,21 @@ $updatedStream = $vanguard->updateNotificationStream($streamId, [
$vanguard->deleteNotificationStream($streamId);
```

### SSH Key Management

Retrieve the Vanguard instance SSH public key:

```php
// Get the instance SSH public key
$sshKey = $vanguard->getInstanceSshKey();

// Access the public key as a string
echo $sshKey->publicKey;

// Or cast the object to a string to get the public key
echo (string) $sshKey;
```

## Security

For reporting security vulnerabilities, please refer to our [security policy](https://github.com/vanguardbackup/vanguard/security/policy).
Expand Down
20 changes: 20 additions & 0 deletions src/Actions/ManagesSshKeys.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace VanguardBackup\Vanguard\Actions;

use VanguardBackup\Vanguard\Resources\SshKey;

trait ManagesSshKeys
{
/**
* Get the Vanguard instance SSH public key.
*
* This key can be used for SSH authentication when connecting to remote servers.
*/
public function getInstanceSshKey(): SshKey
{
return new SshKey($this->get('ssh-key'), $this);
}
}
2 changes: 2 additions & 0 deletions src/Facades/Vanguard.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@

use Illuminate\Support\Facades\Facade;
use VanguardBackup\Vanguard\Resources\ScheduledBackupTask;
use VanguardBackup\Vanguard\Resources\SshKey;
use VanguardBackup\Vanguard\VanguardManager;

/**
* @method static \VanguardBackup\Vanguard\VanguardClient setApiKey(string $apiKey, \GuzzleHttp\Client|null $httpClient = null)
* @method static \VanguardBackup\Vanguard\VanguardClient setBaseUrl(string $url)
* @method static string getBaseUrl()
* @method static \VanguardBackup\Vanguard\Resources\User user()
* @method static SshKey getInstanceSshKey()
* @method static \VanguardBackup\Vanguard\Resources\Tag[] tags()
* @method static \VanguardBackup\Vanguard\Resources\Tag tag(string $tagId)
* @method static \VanguardBackup\Vanguard\Resources\Tag createTag(array $data)
Expand Down
31 changes: 31 additions & 0 deletions src/Resources/SshKey.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace VanguardBackup\Vanguard\Resources;

class SshKey extends Resource
{
/**
* The SSH public key.
*/
public string $publicKey;

/**
* Create a new resource instance.
*/
public function __construct(array $attributes, $vanguard = null)
{
parent::__construct($attributes, $vanguard);

$this->publicKey = $attributes['public_key'];
}

/**
* Get the string representation of the SSH key.
*/
public function __toString(): string
{
return $this->publicKey;
}
}
1 change: 1 addition & 0 deletions src/VanguardClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class VanguardClient
Actions\ManagesBackupTasks,
Actions\ManagesNotificationStreams,
Actions\ManagesRemoteServers,
Actions\ManagesSshKeys,
Actions\ManagesTags,
MakesHttpRequests,
ManagesBackupTaskLogs;
Expand Down

0 comments on commit aa847a6

Please sign in to comment.