From a4d0bf30693aafdc8445ea27475eb475f41effea Mon Sep 17 00:00:00 2001 From: Sergey Date: Wed, 19 Dec 2018 18:27:00 +0300 Subject: [PATCH] Add integration with B2 Cloud (#51) * Add integration with B2 Cloud * Use 1.3 --- DependencyInjection/BMBackupManagerExtension.php | 3 +++ DependencyInjection/Configuration.php | 5 ++++- README.md | 5 +++++ Resources/config/services.yml | 4 ++++ Tests/Unit/DependencyInjection/ConfigurationTest.php | 2 +- composer.json | 3 ++- 6 files changed, 19 insertions(+), 3 deletions(-) diff --git a/DependencyInjection/BMBackupManagerExtension.php b/DependencyInjection/BMBackupManagerExtension.php index 52b8f2f..6ff5c4c 100644 --- a/DependencyInjection/BMBackupManagerExtension.php +++ b/DependencyInjection/BMBackupManagerExtension.php @@ -6,6 +6,7 @@ use League\Flysystem\Adapter\Local; use League\Flysystem\AwsS3v3\AwsS3Adapter; use League\Flysystem\Dropbox\DropboxAdapter; +use Mhetreramesh\Flysystem\BackblazeAdapter; use Srmklive\Dropbox\Adapter\DropboxAdapter as Dropbox2Adapter; use League\Flysystem\Rackspace\RackspaceAdapter; use League\Flysystem\Sftp\SftpAdapter; @@ -34,6 +35,7 @@ public function load(array $configs, ContainerBuilder $container) $managerIdMap = [ 'Local' => 'backup_manager.filesystems.local_filesystem', 'AwsS3' => 'backup_manager.filesystems.awss3_filesystem', + 'B2' => 'backup_manager.filesystems.b2_filesystem', 'Rackspace' => 'backup_manager.filesystems.rackspace_filesystem', 'Dropbox' => 'backup_manager.filesystems.dropbox_filesystem', 'DropboxV2' => 'backup_manager.filesystems.dropbox_v2_filesystem', @@ -67,6 +69,7 @@ private function validateStorage(array $config) $requirements = [ 'Local' => ['package'=>'league/flysystem:^1.0', 'test'=>Local::class], 'AwsS3' => ['package'=>'league/flysystem-aws-s3-v3:^1.0', 'test'=>AwsS3Adapter::class], + 'B2' => ['package'=>'mhetreramesh/flysystem-backblaze:^1.0', 'test'=>BackblazeAdapter::class], 'Rackspace' => ['package'=>'league/flysystem-rackspace:^1.0', 'test'=>RackspaceAdapter::class], 'Dropbox' => ['package'=>'league/flysystem-dropbox:^1.0', 'test'=>DropboxAdapter::class], 'DropboxV2' => ['package'=>'srmklive/flysystem-dropbox-v2:^1.0', 'test'=>Dropbox2Adapter::class], diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index e7245ed..3d073b0 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -39,6 +39,9 @@ public function getConfigTreeBuilder() case 'AwsS3': $this->validateAuthenticationType(['key', 'secret', 'region', 'version', 'bucket', 'root'], $config, 'AwsS3'); break; + case 'B2': + $this->validateAuthenticationType(['key', 'accountId', 'bucket'], $config, 'B2'); + break; case 'Rackspace': $this->validateAuthenticationType(['username', 'password', 'container'], $config, 'Rackspace'); break; @@ -55,7 +58,7 @@ public function getConfigTreeBuilder() $this->validateAuthenticationType(['host', 'username', 'password', 'root', 'port', 'timeout', 'privateKey'], $config, 'Sftp'); break; default: - $validTypes = ['Local', 'AwsS3', 'Rackspace', 'Dropbox', 'DropboxV2', 'Ftp', 'Sftp']; + $validTypes = ['Local', 'AwsS3', 'B2', 'Rackspace', 'Dropbox', 'DropboxV2', 'Ftp', 'Sftp']; throw new InvalidConfigurationException(sprintf('Type must be one of "%s", got "%s"', implode(', ', $validTypes), $config['type'])); } } diff --git a/README.md b/README.md index d6e3523..046ed46 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,11 @@ bm_backup_manager: version: latest bucket: root: + b2: + type: B2 + key: + accountId: + bucket: rackspace: type: Rackspace username: diff --git a/Resources/config/services.yml b/Resources/config/services.yml index 647d02d..a8bd6f8 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -22,6 +22,10 @@ services: class: BackupManager\Filesystems\Awss3Filesystem public: false + backup_manager.filesystems.b2_filesystem: + class: BackupManager\Filesystems\BackblazeFilesystem + public: false + backup_manager.filesystems.dropbox_filesystem: class: BackupManager\Filesystems\DropboxFilesystem public: false diff --git a/Tests/Unit/DependencyInjection/ConfigurationTest.php b/Tests/Unit/DependencyInjection/ConfigurationTest.php index ee68e60..8954a21 100644 --- a/Tests/Unit/DependencyInjection/ConfigurationTest.php +++ b/Tests/Unit/DependencyInjection/ConfigurationTest.php @@ -176,7 +176,7 @@ public function testStorageTypes($type) public function validStorageTypes() { return [ - ['Local'],['AwsS3'], ['Rackspace'], ['Dropbox'], ['DropboxV2'], ['Ftp'], ['Sftp'], + ['Local'],['AwsS3'], ['B2'], ['Rackspace'], ['Dropbox'], ['DropboxV2'], ['Ftp'], ['Sftp'], ]; } } diff --git a/composer.json b/composer.json index 4659b92..fe3764a 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ ], "require": { "php": "^5.5 || ^7.0", - "backup-manager/backup-manager": "^1.2", + "backup-manager/backup-manager": "^1.3", "nyholm/dsn": "^0.1", "symfony/config": "^2.7 || ^3.1 || ^4.0", "symfony/console": "^2.7 || ^3.1 || ^4.0", @@ -30,6 +30,7 @@ }, "suggest": { "league/flysystem-aws-s3-v3": "To use AWS S3, version 3", + "mhetreramesh/flysystem-backblaze": "To use B2", "srmklive/flysystem-dropbox-v2": "To use Dropbox", "league/flysystem-rackspace": "To use Rackspace", "league/flysystem-sftp": "To use sftp"