-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 685b988
Showing
26 changed files
with
2,242 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
The MIT License (MIT) | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,207 @@ | ||
# VanguardBackup PHP SDK | ||
|
||
## Overview | ||
|
||
The VanguardBackup PHP SDK offers a fluent interface for interacting with the VanguardBackup API, enabling efficient management of your backup operations. | ||
|
||
## API Documentation | ||
|
||
While this SDK provides a convenient way to interact with the VanguardBackup API, you may sometimes need more detailed information about the specific parameters and responses for each endpoint. For comprehensive API documentation, including request/response schemas and example payloads, please refer to our official API documentation: | ||
|
||
[VanguardBackup API Documentation](https://docs.vanguardbackup.com/api/introduction) | ||
|
||
This resource will be invaluable when constructing requests or handling responses, especially for more complex operations not fully abstracted by the SDK. | ||
|
||
## Getting Started | ||
|
||
### Installation | ||
|
||
Add the VanguardBackup SDK to your project using Composer: | ||
|
||
```bash | ||
composer require vanguardbackup/vanguard-sdk | ||
``` | ||
|
||
### Initializing the SDK | ||
|
||
Create a new instance of the VanguardBackup client: | ||
|
||
```php | ||
$vanguard = new VanguardBackup\Vanguard\VanguardClient('YOUR_API_KEY'); | ||
``` | ||
|
||
For custom VanguardBackup installations, specify the API base URL: | ||
|
||
```php | ||
$vanguard = new VanguardBackup\Vanguard\VanguardClient('YOUR_API_KEY', 'https://your-vanguard-instance.com/api'); | ||
``` | ||
|
||
## Core Functionalities | ||
|
||
### User Authentication | ||
|
||
Retrieve the authenticated user's information: | ||
|
||
```php | ||
$user = $vanguard->user(); | ||
``` | ||
|
||
### Backup Task Management | ||
|
||
Backup tasks are central to VanguardBackup operations. Here's how to interact with them: | ||
|
||
```php | ||
// List all backup tasks | ||
$tasks = $vanguard->backupTasks(); | ||
|
||
// Get a specific backup task | ||
$task = $vanguard->backupTask($taskId); | ||
|
||
// Create a new backup task | ||
$newTask = $vanguard->createBackupTask([ | ||
'label' => 'Daily Database Backup', | ||
'source_type' => 'database', | ||
// ... other task parameters | ||
]); | ||
|
||
// Update an existing backup task | ||
$updatedTask = $vanguard->updateBackupTask($taskId, [ | ||
'frequency' => 'daily', | ||
// ... other parameters to update | ||
]); | ||
|
||
// Delete a backup task | ||
$vanguard->deleteBackupTask($taskId); | ||
|
||
// Get the status of a backup task | ||
$status = $vanguard->getBackupTaskStatus($taskId); | ||
|
||
// Retrieve the latest log for a backup task | ||
$log = $vanguard->getLatestBackupTaskLog($taskId); | ||
|
||
// Manually trigger a backup task | ||
$vanguard->runBackupTask($taskId); | ||
``` | ||
|
||
Individual `BackupTask` instances also provide methods for common operations: | ||
|
||
```php | ||
$task->update(['label' => 'Weekly Full Backup']); | ||
$task->delete(); | ||
$task->getStatus(); | ||
$task->getLatestLog(); | ||
$task->run(); | ||
``` | ||
|
||
### Remote Server Management | ||
|
||
Manage the servers from which you're backing up data: | ||
|
||
```php | ||
// List all remote servers | ||
$servers = $vanguard->remoteServers(); | ||
|
||
// Get a specific remote server | ||
$server = $vanguard->remoteServer($serverId); | ||
|
||
// Add a new remote server | ||
$newServer = $vanguard->createRemoteServer([ | ||
'label' => 'Production DB Server', | ||
'ip_address' => '192.168.1.100', | ||
// ... other server details | ||
]); | ||
|
||
// Update a remote server | ||
$updatedServer = $vanguard->updateRemoteServer($serverId, [ | ||
'label' => 'Updated Production DB Server', | ||
]); | ||
|
||
// Remove a remote server | ||
$vanguard->deleteRemoteServer($serverId); | ||
``` | ||
|
||
### Backup Destination Management | ||
|
||
Control where your backups are stored: | ||
|
||
```php | ||
// List all backup destinations | ||
$destinations = $vanguard->backupDestinations(); | ||
|
||
// Get a specific backup destination | ||
$destination = $vanguard->backupDestination($destinationId); | ||
|
||
// Create a new backup destination | ||
$newDestination = $vanguard->createBackupDestination([ | ||
'type' => 's3', | ||
'bucket' => 'my-backups', | ||
// ... other destination details | ||
]); | ||
|
||
// Update a backup destination | ||
$updatedDestination = $vanguard->updateBackupDestination($destinationId, [ | ||
'bucket' => 'new-backup-bucket', | ||
]); | ||
|
||
// Remove a backup destination | ||
$vanguard->deleteBackupDestination($destinationId); | ||
``` | ||
|
||
### Tag Management | ||
|
||
Organize your backup resources with tags: | ||
|
||
```php | ||
// List all tags | ||
$tags = $vanguard->tags(); | ||
|
||
// Get a specific tag | ||
$tag = $vanguard->tag($tagId); | ||
|
||
// Create a new tag | ||
$newTag = $vanguard->createTag(['label' => 'Production']); | ||
|
||
// Update a tag | ||
$updatedTag = $vanguard->updateTag($tagId, ['label' => 'Staging']); | ||
|
||
// Delete a tag | ||
$vanguard->deleteTag($tagId); | ||
``` | ||
|
||
### Notification Stream Management | ||
|
||
Configure how you receive alerts about your backups: | ||
|
||
```php | ||
// List all notification streams | ||
$streams = $vanguard->notificationStreams(); | ||
|
||
// Get a specific notification stream | ||
$stream = $vanguard->notificationStream($streamId); | ||
|
||
// Create a new notification stream | ||
$newStream = $vanguard->createNotificationStream([ | ||
'type' => 'slack', | ||
'webhook_url' => 'https://hooks.slack.com/services/...', | ||
]); | ||
|
||
// Update a notification stream | ||
$updatedStream = $vanguard->updateNotificationStream($streamId, [ | ||
'events' => ['backup_failed', 'backup_successful'], | ||
]); | ||
|
||
// Delete a notification stream | ||
$vanguard->deleteNotificationStream($streamId); | ||
``` | ||
|
||
## Security | ||
|
||
For reporting security vulnerabilities, please refer to our [security policy](https://github.com/vanguardbackup/vanguard/security/policy). | ||
|
||
## License | ||
|
||
The VanguardBackup PHP SDK is open-source software, released under the [MIT licence](LICENSE.md). | ||
|
||
## Acknowledgments | ||
|
||
We'd like to express our gratitude to the Laravel Forge PHP SDK, which served as an inspiration for the structure and design of this SDK. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
{ | ||
"name": "vanguardbackup/vanguard-php-sdk", | ||
"description": "The official VanguardBackup PHP SDK.", | ||
"keywords": ["vanguard", "backup", "sdk", "php"], | ||
"license": "MIT", | ||
"support": { | ||
"issues": "https://github.com/vanguardbackup/vanguard-php-sdk/issues", | ||
"source": "https://github.com/vanguardbackup/vanguard-php-sdk" | ||
}, | ||
"authors": [ | ||
{ | ||
"name": "Lewis Larsen", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
"php": "^7.2|^8.0", | ||
"ext-json": "*", | ||
"guzzlehttp/guzzle": "^6.3.1|^7.0" | ||
}, | ||
"require-dev": { | ||
"roave/security-advisories": "dev-latest" | ||
, | ||
"illuminate/support": "^7.0|^8.0|^9.0|^10.0|^11.0", | ||
"mockery/mockery": "^1.3.1", | ||
"phpstan/phpstan": "^1.10", | ||
"phpunit/phpunit": "^8.4|^9.0|^10.4" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"VanguardBackup\\Vanguard\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"VanguardBackup\\Vanguard\\Tests\\": "tests/" | ||
} | ||
}, | ||
"extra": { | ||
"branch-alias": { | ||
"dev-master": "1.x-dev" | ||
}, | ||
"laravel": { | ||
"providers": [ | ||
"VanguardBackup\\Vanguard\\VanguardServiceProvider" | ||
] | ||
} | ||
}, | ||
"config": { | ||
"sort-packages": true | ||
}, | ||
"minimum-stability": "dev", | ||
"prefer-stable": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
parameters: | ||
paths: | ||
- src | ||
|
||
level: 0 | ||
|
||
ignoreErrors: | ||
- "#\\(void\\) is used.#" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit backupGlobals="false" | ||
backupStaticAttributes="false" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
convertDeprecationsToExceptions="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false" | ||
> | ||
<testsuites> | ||
<testsuite name="Vanguard Test Suite"> | ||
<directory suffix="Test.php">./tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
namespace VanguardBackup\Vanguard\Actions; | ||
|
||
use VanguardBackup\Vanguard\Resources\BackupDestination; | ||
|
||
trait ManagesBackupDestinations | ||
{ | ||
/** | ||
* Get the collection of backup destinations. | ||
* | ||
* @return BackupDestination[] | ||
*/ | ||
public function backupDestinations() | ||
{ | ||
return $this->transformCollection( | ||
$this->get('backup-destinations')['data'], BackupDestination::class | ||
); | ||
} | ||
|
||
/** | ||
* Get a backup destination instance. | ||
* | ||
* @param string $destinationId | ||
* @return BackupDestination | ||
*/ | ||
public function backupDestination(string $destinationId): BackupDestination | ||
{ | ||
return new BackupDestination($this->get("backup-destinations/{$destinationId}")['data'], $this); | ||
} | ||
|
||
/** | ||
* Create a new backup destination. | ||
* | ||
* @param array $data | ||
* @return BackupDestination | ||
*/ | ||
public function createBackupDestination(array $data): BackupDestination | ||
{ | ||
return new BackupDestination($this->post('backup-destinations', $data)['data'], $this); | ||
} | ||
|
||
/** | ||
* Update the given backup destination. | ||
* | ||
* @param string $destinationId | ||
* @param array $data | ||
* @return BackupDestination | ||
*/ | ||
public function updateBackupDestination(string $destinationId, array $data): BackupDestination | ||
{ | ||
return new BackupDestination($this->put("backup-destinations/{$destinationId}", $data)['data'], $this); | ||
} | ||
|
||
/** | ||
* Delete the given backup destination. | ||
* | ||
* @param string $destinationId | ||
* @return void | ||
*/ | ||
public function deleteBackupDestination(string $destinationId): void | ||
{ | ||
$this->delete("backup-destinations/{$destinationId}"); | ||
} | ||
} |
Oops, something went wrong.