mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-02 22:46:16 +00:00
refactoring (#116)
- refactoring architecture - fix incomplete ssh logs - code editor for scripts in the app - remove Jobs and SSHCommands
This commit is contained in:
@ -2,8 +2,8 @@
|
||||
|
||||
namespace App\StorageProviders;
|
||||
|
||||
use App\Contracts\StorageProvider as StorageProviderContract;
|
||||
use App\Models\StorageProvider;
|
||||
use App\StorageProviders\StorageProvider as StorageProviderContract;
|
||||
|
||||
abstract class AbstractStorageProvider implements StorageProviderContract
|
||||
{
|
||||
|
@ -2,12 +2,9 @@
|
||||
|
||||
namespace App\StorageProviders;
|
||||
|
||||
use App\Exceptions\BackupFileException;
|
||||
use App\Models\Server;
|
||||
use App\SSHCommands\Storage\DownloadFromDropboxCommand;
|
||||
use App\SSHCommands\Storage\UploadToDropboxCommand;
|
||||
use App\SSH\Storage\Storage;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Throwable;
|
||||
|
||||
class Dropbox extends AbstractStorageProvider
|
||||
{
|
||||
@ -37,44 +34,9 @@ public function connect(): bool
|
||||
return $res->successful();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function upload(Server $server, string $src, string $dest): array
|
||||
public function ssh(Server $server): Storage
|
||||
{
|
||||
$upload = $server->ssh()->exec(
|
||||
new UploadToDropboxCommand(
|
||||
$src,
|
||||
$dest,
|
||||
$this->storageProvider->credentials['token']
|
||||
),
|
||||
'upload-to-dropbox'
|
||||
);
|
||||
|
||||
$data = json_decode($upload, true);
|
||||
|
||||
if (isset($data['error'])) {
|
||||
throw new BackupFileException('Failed to upload to Dropbox '.$data['error_summary'] ?? '');
|
||||
}
|
||||
|
||||
return [
|
||||
'size' => $data['size'] ?? null,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function download(Server $server, string $src, string $dest): void
|
||||
{
|
||||
$server->ssh()->exec(
|
||||
new DownloadFromDropboxCommand(
|
||||
$src,
|
||||
$dest,
|
||||
$this->storageProvider->credentials['token']
|
||||
),
|
||||
'download-from-dropbox'
|
||||
);
|
||||
return new \App\SSH\Storage\Dropbox($server, $this->storageProvider);
|
||||
}
|
||||
|
||||
public function delete(array $paths): void
|
||||
|
@ -3,10 +3,8 @@
|
||||
namespace App\StorageProviders;
|
||||
|
||||
use App\Models\Server;
|
||||
use App\SSHCommands\Storage\DownloadFromFTPCommand;
|
||||
use App\SSHCommands\Storage\UploadToFTPCommand;
|
||||
use App\SSH\Storage\Storage;
|
||||
use FTP\Connection;
|
||||
use Throwable;
|
||||
|
||||
class FTP extends AbstractStorageProvider
|
||||
{
|
||||
@ -49,48 +47,9 @@ public function connect(): bool
|
||||
return $isConnected;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function upload(Server $server, string $src, string $dest): array
|
||||
public function ssh(Server $server): Storage
|
||||
{
|
||||
$server->ssh()->exec(
|
||||
new UploadToFTPCommand(
|
||||
$src,
|
||||
$this->storageProvider->credentials['path'].'/'.$dest,
|
||||
$this->storageProvider->credentials['host'],
|
||||
$this->storageProvider->credentials['port'],
|
||||
$this->storageProvider->credentials['username'],
|
||||
$this->storageProvider->credentials['password'],
|
||||
$this->storageProvider->credentials['ssl'],
|
||||
$this->storageProvider->credentials['passive'],
|
||||
),
|
||||
'upload-to-ftp'
|
||||
);
|
||||
|
||||
return [
|
||||
'size' => null,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function download(Server $server, string $src, string $dest): void
|
||||
{
|
||||
$server->ssh()->exec(
|
||||
new DownloadFromFTPCommand(
|
||||
$this->storageProvider->credentials['path'].'/'.$src,
|
||||
$dest,
|
||||
$this->storageProvider->credentials['host'],
|
||||
$this->storageProvider->credentials['port'],
|
||||
$this->storageProvider->credentials['username'],
|
||||
$this->storageProvider->credentials['password'],
|
||||
$this->storageProvider->credentials['ssl'],
|
||||
$this->storageProvider->credentials['passive'],
|
||||
),
|
||||
'download-from-ftp'
|
||||
);
|
||||
return new \App\SSH\Storage\FTP($server, $this->storageProvider);
|
||||
}
|
||||
|
||||
public function delete(array $paths): void
|
||||
|
19
app/StorageProviders/StorageProvider.php
Normal file
19
app/StorageProviders/StorageProvider.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\StorageProviders;
|
||||
|
||||
use App\Models\Server;
|
||||
use App\SSH\Storage\Storage;
|
||||
|
||||
interface StorageProvider
|
||||
{
|
||||
public function validationRules(): array;
|
||||
|
||||
public function credentialData(array $input): array;
|
||||
|
||||
public function connect(): bool;
|
||||
|
||||
public function ssh(Server $server): Storage;
|
||||
|
||||
public function delete(array $paths): void;
|
||||
}
|
Reference in New Issue
Block a user